30 Commits

Author SHA1 Message Date
Laura
7506bcd002 [Issue #108] Overwrite CLI Tools (#115)
* Trying this

* Revert "Trying this"

This reverts commit 46eab8f218.

* Put exists check around tools move

* Remove directory before copying over it

* Reverted indent

* Revert additional two spaces
2021-03-03 00:02:20 +02:00
Vilius Sutkus '89
0bdb2caf82 [issue #108] Remove zip extraction leftovers 2021-03-02 03:05:42 +02:00
Vilius Sutkus '89
6989f50c81 Rebuild dist/index.js 2021-02-20 23:06:23 +01:00
Vilius Sutkus '89
9ab2660a79 Add @types/fs-extra dev dependency 2021-02-20 23:06:23 +01:00
Vilius Sutkus '89
cc38275357 Un-whitespace ANDROID_SDK_ROOT
sdkmanager doesn't like spaces in it's path.
Move the whole SDK to a place without spaces.
2021-02-20 23:03:41 +01:00
Vilius Sutkus '89
999dabf39c Use fs-extra.moveSync instead of fs.renameSync to move cmdline-tools
fs.renameSync can't rename across drives.
2021-02-20 23:03:41 +01:00
Vilius Sutkus '89
6bde8445cd Call sdkmanager, not .bat on windows too, it just works 2021-02-20 23:03:41 +01:00
Vilius Sutkus '89
1edf194eee Actually try to install sdkmanager after each commit 2021-02-20 23:03:41 +01:00
Vilius Sutkus '89
8c02e1fcfa Update run.yml to run sdkmanager after each update 2021-02-20 23:03:41 +01:00
Vilius Sutkus '89
87280a34d4 Check if sdkManager is actually available
GitHub Actions have Android-SDK preinstalled, but there's no sdkmanager.
Missing sdkmanager means no additional packages can be easily installed by dowsntream users.
2021-02-20 23:03:41 +01:00
Dave Olsthoorn
e3e9dc9b68 update dependencies 2021-02-20 22:53:11 +01:00
dependabot[bot]
fb95bc1561 Bump @types/jest from 26.0.19 to 26.0.20
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 26.0.19 to 26.0.20.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-01 12:16:20 +01:00
dependabot[bot]
0df682b3d9 Bump @types/node from 14.14.17 to 14.14.22
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.17 to 14.14.22.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>
2021-02-01 12:06:09 +01:00
Dave Olsthoorn
0e84f1d6a4 update dependencies 2020-12-31 20:04:54 +01:00
Dave Olsthoorn
9e5b3ce36b Merge branch 'main' of github.com:android-actions/setup-android into main 2020-12-21 09:19:32 +01:00
dependabot[bot]
ebc0cbe4ab Bump actions/setup-node from v2.1.2 to v2.1.4
Bumps [actions/setup-node](https://github.com/actions/setup-node) from v2.1.2 to v2.1.4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2.1.2...c46424eee26de4078d34105d3de3cc4992202b1e)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-21 09:16:42 +01:00
Max Romanyuta
27f88822ed Fix lint problems 2020-12-21 09:16:42 +01:00
Max Romanyuta
a9018e09bb Remove unnecessary changes 2020-12-21 09:16:42 +01:00
Max Romanyuta
6bb81b1f40 Fix path to sdkmanager for all platforms 2020-12-21 09:16:42 +01:00
Max Romanyuta
7b2dad077d Fix path to sdkmanager
In the commandlinetools-${OS}-${TOOLS_VERSION}_latest.zip file, the name of the zipped folder has been changed.
2020-12-21 09:16:42 +01:00
dependabot[bot]
6ef7c7f726 Bump @actions/cache from 1.0.3 to 1.0.5
Bumps [@actions/cache](https://github.com/actions/toolkit/tree/HEAD/packages/cache) from 1.0.3 to 1.0.5.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/cache/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/cache)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-21 09:16:42 +01:00
dependabot[bot]
df284ad095 Bump eslint from 7.12.1 to 7.16.0
Bumps [eslint](https://github.com/eslint/eslint) from 7.12.1 to 7.16.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.12.1...v7.16.0)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-21 09:16:42 +01:00
dependabot[bot]
bb3313467a Bump eslint-plugin-jest from 23.20.0 to 24.1.3
Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 23.20.0 to 24.1.3.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v23.20.0...v24.1.3)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-21 09:16:42 +01:00
Dave Olsthoorn
8c6fc62420 Bump @types/node from 14.14.6 to 14.14.14
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.14.6 to 14.14.14.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-21 09:16:27 +01:00
dependabot[bot]
bd524df5da Bump actions/setup-node from v2.1.2 to v2.1.4
Bumps [actions/setup-node](https://github.com/actions/setup-node) from v2.1.2 to v2.1.4.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](https://github.com/actions/setup-node/compare/v2.1.2...c46424eee26de4078d34105d3de3cc4992202b1e)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-21 09:04:56 +01:00
Max Romanyuta
e5fc925f91 Fix lint problems 2020-12-21 09:04:23 +01:00
Max Romanyuta
aceb0eac9b Remove unnecessary changes 2020-12-21 09:04:23 +01:00
Max Romanyuta
903dd50e8f Fix path to sdkmanager for all platforms 2020-12-21 09:04:23 +01:00
Max Romanyuta
ec68242df7 Fix path to sdkmanager
In the commandlinetools-${OS}-${TOOLS_VERSION}_latest.zip file, the name of the zipped folder has been changed.
2020-12-21 09:04:23 +01:00
dependabot[bot]
658d02355a Bump @typescript-eslint/parser from 4.6.1 to 4.10.0
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 4.6.1 to 4.10.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.10.0/packages/parser)

Signed-off-by: dependabot[bot] <support@github.com>
2020-12-21 05:51:33 +00:00
5 changed files with 2841 additions and 2008 deletions

View File

@@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v2.1.2
uses: actions/setup-node@v2.1.4
with:
node-version: '12'
@@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v2.1.2
uses: actions/setup-node@v2.1.4
with:
node-version: '12'
@@ -46,7 +46,7 @@ jobs:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v2.1.2
uses: actions/setup-node@v2.1.4
with:
node-version: '12'
@@ -54,13 +54,35 @@ jobs:
- run: npm test
runSdkManager:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-16.04, ubuntu-18.04, ubuntu-20.04, macos-10.15, windows-2016, windows-2019 ]
steps:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v2.1.4
with:
node-version: '12'
- run: npm ci
- run: npm run build
- run: node dist/index.js
- run: sdkmanager --list
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup node 12
uses: actions/setup-node@v2.1.2
uses: actions/setup-node@v2.1.4
with:
node-version: '12'

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

4605
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -25,23 +25,26 @@
"author": "daveol",
"license": "ISC",
"dependencies": {
"@actions/cache": "^1.0.3",
"@actions/cache": "^1.0.6",
"@actions/core": "^1.2.6",
"@actions/tool-cache": "^1.6.0"
"@actions/tool-cache": "^1.6.1",
"fs-extra": "^9.1.0"
},
"devDependencies": {
"@types/jest": "^26.0.15",
"@types/node": "^14.14.6",
"@typescript-eslint/parser": "^4.6.1",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.31",
"@typescript-eslint/eslint-plugin": "^4.15.1",
"@typescript-eslint/parser": "^4.15.1",
"@types/fs-extra": "^9.0.6",
"@zeit/ncc": "^0.22.3",
"eslint": "^7.12.1",
"eslint": "^7.20.0",
"eslint-plugin-github": "^4.1.1",
"eslint-plugin-jest": "^23.20.0",
"jest": "^24.9.0",
"eslint-plugin-jest": "^24.1.5",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"js-yaml": "^3.13.1",
"prettier": "^2.1.2",
"ts-jest": "^24.2.0",
"typescript": "^4.0.5"
"js-yaml": "^3.14.1",
"prettier": "^2.2.1",
"ts-jest": "^26.5.1",
"typescript": "^4.1.5"
}
}

View File

@@ -3,8 +3,10 @@ import * as tc from '@actions/tool-cache'
import * as exec from '@actions/exec'
import * as path from 'path'
import * as fs from 'fs'
import * as fse from 'fs-extra'
import * as os from 'os'
const CMDLINE_TOOLS_VERSION = '3.0'
const COMMANDLINE_TOOLS_VERSION = '6858069'
const COMMANDLINE_TOOLS_WIN_URL = `https://dl.google.com/android/repository/commandlinetools-win-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
@@ -14,64 +16,163 @@ const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/comm
const HOME = os.homedir()
const ANDROID_HOME_DIR = path.join(HOME, '.android')
const ANDROID_HOME_SDK_DIR = path.join(ANDROID_HOME_DIR, 'sdk')
const ANDROID_REPOSITORIES_CFG = path.join(ANDROID_HOME_DIR, 'repositories.cfg')
let ANDROID_SDK_ROOT = process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR
async function install(): Promise<string> {
const ANDROID_SDK_ROOT =
process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR
const licenseDir = path.join(ANDROID_SDK_ROOT, 'licenses')
function getSdkManagerPath(cmdToolsVersion: string): string {
return path.join(
ANDROID_SDK_ROOT,
'cmdline-tools',
cmdToolsVersion,
'bin',
'sdkmanager'
)
}
// If the licences exist, the rest does too
if (fs.existsSync(licenseDir)) {
core.debug(`Skipping install, licenseDir found: ${licenseDir}`)
return ANDROID_SDK_ROOT
function findPreinstalledSdkManager(): {
isFound: boolean
isCorrectVersion: boolean
exePath: string
} {
const result = {isFound: false, isCorrectVersion: false, exePath: ''}
// First try to find the version defined in CMDLINE_TOOLS_VERSION
result.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
result.isFound = fs.existsSync(result.exePath)
if (result.isFound) {
result.isCorrectVersion = true
return result
}
// create ~/.android/repositories.cfg
fs.mkdirSync(ANDROID_HOME_SDK_DIR, {recursive: true})
fs.closeSync(fs.openSync(ANDROID_REPOSITORIES_CFG, 'w'))
// cmdline-tools could have a 'latest' version, but if it was installed 2 years ago
// it may not be 'latest' as of today
result.exePath = getSdkManagerPath('latest')
result.isFound = fs.existsSync(result.exePath)
if (result.isFound) {
return result
}
result.exePath = ''
// Find whatever version is available in ANDROID_SDK_ROOT
const cmdlineToolsDir = path.join(ANDROID_SDK_ROOT, 'cmdline-tools')
const foundVersions: string[] = fs.existsSync(cmdlineToolsDir)
? fs.readdirSync(cmdlineToolsDir)
: []
const foundVersionsFiltered: string[] = foundVersions.filter(
obj => '.' !== obj && '..' !== obj
)
// Sort by desc, to get 2.0 first, before 1.0
const foundVersionsSorted: string[] = foundVersionsFiltered.sort(
(a: string, b: string) => (a > b ? -1 : 1)
)
for (const version of foundVersionsSorted) {
result.exePath = getSdkManagerPath(version)
result.isFound = fs.existsSync(result.exePath)
if (result.isFound) {
return result
}
}
result.exePath = ''
return result
}
async function callSdkManager(sdkManager: string, arg: string): Promise<void> {
const acceptBuffer = Buffer.from(Array(10).fill('y').join('\n'), 'utf8')
let sdkManager = ''
await exec.exec(sdkManager, [arg], {
input: acceptBuffer
})
}
if (process.platform === 'linux') {
const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_LIN_URL)
const cmdlineTools = await tc.extractZip(cmdlineToolsZip)
sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager')
} else if (process.platform === 'darwin') {
const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_MAC_URL)
const cmdlineTools = await tc.extractZip(cmdlineToolsZip)
sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager')
} else if (process.platform === 'win32') {
const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_WIN_URL)
const cmdlineTools = await tc.extractZip(cmdlineToolsZip)
sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager.bat')
} else {
core.error(`Unsupported platform: ${process.platform}`)
async function installSdkManager(): Promise<string> {
fs.mkdirSync(ANDROID_SDK_ROOT, {recursive: true})
// touch $ANDROID_SDK_ROOT/repositories.cfg
fs.closeSync(
fs.openSync(path.join(ANDROID_SDK_ROOT, 'repositories.cfg'), 'w')
)
const sdkManager = findPreinstalledSdkManager()
if (!sdkManager.isFound) {
let cmdlineToolsURL
if (process.platform === 'linux') {
cmdlineToolsURL = COMMANDLINE_TOOLS_LIN_URL
} else if (process.platform === 'darwin') {
cmdlineToolsURL = COMMANDLINE_TOOLS_MAC_URL
} else if (process.platform === 'win32') {
cmdlineToolsURL = COMMANDLINE_TOOLS_WIN_URL
} else {
core.error(`Unsupported platform: ${process.platform}`)
return ''
}
const cmdlineToolsZip = await tc.downloadTool(cmdlineToolsURL)
const cmdlineToolsExtractedLocation = await tc.extractZip(cmdlineToolsZip)
// Move cmdline-tools to where it would be if it was installed through sdkmanager
// Will allow calling sdkmanager without --sdk_root='..' argument
const desiredLocation = path.join(
ANDROID_SDK_ROOT,
'cmdline-tools',
CMDLINE_TOOLS_VERSION
)
fs.mkdirSync(path.dirname(desiredLocation), {recursive: true})
// @TODO: use io.mv instead of fs-extra once following issue is resolved:
// https://github.com/actions/toolkit/issues/706
if (fs.existsSync(desiredLocation)) fse.removeSync(desiredLocation)
fse.moveSync(
path.join(cmdlineToolsExtractedLocation, 'cmdline-tools'),
desiredLocation
)
fse.removeSync(cmdlineToolsExtractedLocation)
sdkManager.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
sdkManager.isCorrectVersion = true
}
await exec.exec(
sdkManager,
['--licenses', `--sdk_root=${ANDROID_SDK_ROOT}`],
{input: acceptBuffer}
)
await exec.exec(
sdkManager,
['--include_obsolete', `--sdk_root=${ANDROID_SDK_ROOT}`, 'tools'],
{input: acceptBuffer}
)
return ANDROID_SDK_ROOT
if (!sdkManager.isCorrectVersion) {
await callSdkManager(
sdkManager.exePath,
`cmdline-tools;${CMDLINE_TOOLS_VERSION}`
)
sdkManager.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
}
return sdkManager.exePath
}
async function run(): Promise<void> {
const ANDROID_SDK_ROOT = await install()
if ('win16' === process.env['ImageOS']) {
if (-1 !== ANDROID_SDK_ROOT.indexOf(' ')) {
// On Windows2016, Android SDK is installed to Program Files,
// and it doesn't really work..
// C:\windows\system32\cmd.exe /D /S /C ""C:\Program Files (x86)\Android\android-sdk\cmdline-tools\3.0\bin\sdkmanager.bat" --licenses"
// Error: Could not find or load main class Files
const newSDKLocation = ANDROID_SDK_ROOT.replace(/\s/gi, '-')
core.debug(`moving ${ANDROID_SDK_ROOT} to ${newSDKLocation}`)
fs.mkdirSync(path.dirname(newSDKLocation), {recursive: true})
// intentionally using fs.renameSync,
// because it doesn't move across drives
fs.renameSync(ANDROID_SDK_ROOT, newSDKLocation)
ANDROID_SDK_ROOT = newSDKLocation
}
}
const sdkManager = await installSdkManager()
core.debug(`sdkmanager installed to: ${sdkManager}`)
await callSdkManager(sdkManager, '--licenses')
await callSdkManager(sdkManager, 'tools')
await callSdkManager(sdkManager, 'platform-tools')
core.setOutput('ANDROID_COMMANDLINE_TOOLS_VERSION', COMMANDLINE_TOOLS_VERSION)
core.exportVariable('ANDROID_HOME', ANDROID_SDK_ROOT)
core.exportVariable('ANDROID_SDK_ROOT', ANDROID_SDK_ROOT)
core.addPath(path.join(ANDROID_SDK_ROOT, 'tools', 'bin'))
core.addPath(path.dirname(sdkManager))
core.addPath(path.join(ANDROID_SDK_ROOT, 'platform-tools'))
core.debug('add matchers')