mirror of
https://github.com/android-actions/setup-android
synced 2024-11-22 05:29:34 -08:00
[Issue #192] Accept cmdline-tools-version input parameter
This commit is contained in:
parent
9584f05408
commit
8023252681
7 changed files with 181 additions and 3125 deletions
2
.github/workflows/build-test.yml
vendored
2
.github/workflows/build-test.yml
vendored
|
@ -82,6 +82,8 @@ jobs:
|
|||
- run: npm run build
|
||||
|
||||
- run: node dist/index.js
|
||||
env:
|
||||
INPUT_CMDLINE-TOOLS-VERSION: '10406996'
|
||||
|
||||
- run: sdkmanager --list
|
||||
|
||||
|
|
25
README.md
25
README.md
|
@ -38,6 +38,31 @@ steps:
|
|||
run: ./gradlew --no-daemon build
|
||||
```
|
||||
|
||||
## SDK Version selection
|
||||
|
||||
Command line tools are versioned using two variables - short and long.
|
||||
Long one is the build number, used in the zip URL, short one is the human friendly version name.
|
||||
|
||||
By default, setup-android installs version 10406996 (short version 11.0).
|
||||
|
||||
To install a different version, call setup-android with desired long version as the input parameter `cmdline-tools-version`:
|
||||
```yaml
|
||||
- name: Setup Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
cmdline-tools-version: 8512546
|
||||
```
|
||||
|
||||
#### Version table
|
||||
| Short version | Long version |
|
||||
| --- | --- |
|
||||
| 11.0 | 10406996 |
|
||||
| 10.0 | 9862592 |
|
||||
| 9.0 | 9477386 |
|
||||
| 8.0 | 9123335 |
|
||||
| 7.0 | 8512546 |
|
||||
|
||||
Current cmdline tools version can be found at https://developer.android.com/studio#command-line-tools-only
|
||||
|
||||
# Thanks
|
||||
Based on the project [android-problem-matchers-action](https://github.com/jonasb/android-problem-matchers-action) from [@jonasb](https://github.com/jonasb)
|
||||
|
|
|
@ -2,6 +2,12 @@ name: 'Setup Android SDK Tools'
|
|||
author: 'Android-Actions'
|
||||
description: 'Setup the Android SDK Tools and add them to the path'
|
||||
|
||||
inputs:
|
||||
cmdline-tools-version:
|
||||
description: 'cmdline-tools-version. See https://developer.android.com/studio#command-line-tools-only'
|
||||
required: false
|
||||
default: '10406996'
|
||||
|
||||
runs:
|
||||
using: node20
|
||||
main: 'dist/index.js'
|
||||
|
|
2967
dist/index.js
vendored
2967
dist/index.js
vendored
File diff suppressed because it is too large
Load diff
104
package-lock.json
generated
104
package-lock.json
generated
|
@ -11,11 +11,9 @@
|
|||
"dependencies": {
|
||||
"@actions/cache": "^3.2.2",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"fs-extra": "^11.1.1"
|
||||
"@actions/tool-cache": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^11.0.2",
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/node": "^20.6.5",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
||||
|
@ -1612,16 +1610,6 @@
|
|||
"@babel/types": "^7.20.7"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/fs-extra": {
|
||||
"version": "11.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.2.tgz",
|
||||
"integrity": "sha512-c0hrgAOVYr21EX8J0jBMXGLMgJqVf/v6yxi0dLaJboW9aQPh16Id+z6w2Tx1hm+piJOLv8xPfVKZCLfjPw/IMQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/jsonfile": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/graceful-fs": {
|
||||
"version": "4.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.7.tgz",
|
||||
|
@ -1677,15 +1665,6 @@
|
|||
"integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/jsonfile": {
|
||||
"version": "6.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsonfile/-/jsonfile-6.1.2.tgz",
|
||||
"integrity": "sha512-8t92P+oeW4d/CRQfJaSqEwXujrhH4OEeHRjGU3v1Q8mUS8GPF3yiX26sw4svv6faL2HfBtGTe2xWIoVgN3dy9w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.6.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.5.tgz",
|
||||
|
@ -4037,19 +4016,6 @@
|
|||
"node": ">= 0.12"
|
||||
}
|
||||
},
|
||||
"node_modules/fs-extra": {
|
||||
"version": "11.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
|
||||
"integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
|
||||
"dependencies": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14.14"
|
||||
}
|
||||
},
|
||||
"node_modules/fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
|
@ -4270,7 +4236,8 @@
|
|||
"node_modules/graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/graphemer": {
|
||||
"version": "1.4.0",
|
||||
|
@ -5550,17 +5517,6 @@
|
|||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"dependencies": {
|
||||
"universalify": "^2.0.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"graceful-fs": "^4.1.6"
|
||||
}
|
||||
},
|
||||
"node_modules/jsx-ast-utils": {
|
||||
"version": "3.3.5",
|
||||
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz",
|
||||
|
@ -7218,14 +7174,6 @@
|
|||
"url": "https://github.com/sponsors/ljharb"
|
||||
}
|
||||
},
|
||||
"node_modules/universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
|
||||
"engines": {
|
||||
"node": ">= 10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/untildify": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz",
|
||||
|
@ -8736,16 +8684,6 @@
|
|||
"@babel/types": "^7.20.7"
|
||||
}
|
||||
},
|
||||
"@types/fs-extra": {
|
||||
"version": "11.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-11.0.2.tgz",
|
||||
"integrity": "sha512-c0hrgAOVYr21EX8J0jBMXGLMgJqVf/v6yxi0dLaJboW9aQPh16Id+z6w2Tx1hm+piJOLv8xPfVKZCLfjPw/IMQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/jsonfile": "*",
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/graceful-fs": {
|
||||
"version": "4.1.7",
|
||||
"resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.7.tgz",
|
||||
|
@ -8801,15 +8739,6 @@
|
|||
"integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==",
|
||||
"dev": true
|
||||
},
|
||||
"@types/jsonfile": {
|
||||
"version": "6.1.2",
|
||||
"resolved": "https://registry.npmjs.org/@types/jsonfile/-/jsonfile-6.1.2.tgz",
|
||||
"integrity": "sha512-8t92P+oeW4d/CRQfJaSqEwXujrhH4OEeHRjGU3v1Q8mUS8GPF3yiX26sw4svv6faL2HfBtGTe2xWIoVgN3dy9w==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "20.6.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.6.5.tgz",
|
||||
|
@ -10477,16 +10406,6 @@
|
|||
"mime-types": "^2.1.12"
|
||||
}
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "11.1.1",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
|
||||
"integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.2.0",
|
||||
"jsonfile": "^6.0.1",
|
||||
"universalify": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
|
@ -10637,7 +10556,8 @@
|
|||
"graceful-fs": {
|
||||
"version": "4.2.11",
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
|
||||
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
|
||||
"dev": true
|
||||
},
|
||||
"graphemer": {
|
||||
"version": "1.4.0",
|
||||
|
@ -11566,15 +11486,6 @@
|
|||
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
||||
"dev": true
|
||||
},
|
||||
"jsonfile": {
|
||||
"version": "6.1.0",
|
||||
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
||||
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.6",
|
||||
"universalify": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"jsx-ast-utils": {
|
||||
"version": "3.3.5",
|
||||
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-3.3.5.tgz",
|
||||
|
@ -12761,11 +12672,6 @@
|
|||
"which-boxed-primitive": "^1.0.2"
|
||||
}
|
||||
},
|
||||
"universalify": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
||||
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ=="
|
||||
},
|
||||
"untildify": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/untildify/-/untildify-4.0.0.tgz",
|
||||
|
|
|
@ -27,11 +27,9 @@
|
|||
"dependencies": {
|
||||
"@actions/cache": "^3.2.2",
|
||||
"@actions/core": "^1.10.1",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"fs-extra": "^11.1.1"
|
||||
"@actions/tool-cache": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^11.0.2",
|
||||
"@types/jest": "^29.5.5",
|
||||
"@types/node": "^20.6.5",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.2",
|
||||
|
|
198
src/main.ts
198
src/main.ts
|
@ -3,92 +3,41 @@ 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 = '11.0'
|
||||
const COMMANDLINE_TOOLS_VERSION = '10406996'
|
||||
function getVersionShort(versionLong: string): string {
|
||||
switch (versionLong) {
|
||||
case '10406996':
|
||||
return '11.0'
|
||||
case '9862592':
|
||||
return '10.0'
|
||||
case '9477386':
|
||||
return '9.0'
|
||||
case '9123335':
|
||||
return '8.0'
|
||||
case '8512546':
|
||||
return '7.0'
|
||||
default:
|
||||
return versionLong
|
||||
}
|
||||
}
|
||||
|
||||
const COMMANDLINE_TOOLS_WIN_URL = `https://dl.google.com/android/repository/commandlinetools-win-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_MAC_URL = `https://dl.google.com/android/repository/commandlinetools-mac-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/commandlinetools-linux-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
const VERSION_LONG = core.getInput('cmdline-tools-version', {
|
||||
trimWhitespace: true
|
||||
})
|
||||
if (VERSION_LONG.includes('/') || VERSION_LONG.includes('\\')) {
|
||||
core.setFailed('Malformed cmdline-tools-version!')
|
||||
throw new Error('Malformed cmdline-tools-version!')
|
||||
}
|
||||
const VERSION_SHORT = getVersionShort(VERSION_LONG)
|
||||
|
||||
const HOME = os.homedir()
|
||||
const ANDROID_HOME_DIR = path.join(HOME, '.android')
|
||||
const ANDROID_HOME_SDK_DIR = path.join(ANDROID_HOME_DIR, 'sdk')
|
||||
const COMMANDLINE_TOOLS_WIN_URL = `https://dl.google.com/android/repository/commandlinetools-win-${VERSION_LONG}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_MAC_URL = `https://dl.google.com/android/repository/commandlinetools-mac-${VERSION_LONG}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/commandlinetools-linux-${VERSION_LONG}_latest.zip`
|
||||
|
||||
const ANDROID_HOME_SDK_DIR = path.join(os.homedir(), '.android', 'sdk')
|
||||
let ANDROID_SDK_ROOT = process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR
|
||||
|
||||
function getSdkManagerPath(cmdToolsVersion: string): string {
|
||||
return path.join(
|
||||
ANDROID_SDK_ROOT,
|
||||
'cmdline-tools',
|
||||
cmdToolsVersion,
|
||||
'bin',
|
||||
'sdkmanager'
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
// 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) {
|
||||
const propertiesFile = path.join(
|
||||
ANDROID_SDK_ROOT,
|
||||
'cmdline-tools',
|
||||
'latest',
|
||||
'source.properties'
|
||||
)
|
||||
if (fs.existsSync(propertiesFile)) {
|
||||
result.isCorrectVersion = fs
|
||||
.readFileSync(propertiesFile, 'utf8')
|
||||
.includes(`Pkg.Revision=${CMDLINE_TOOLS_VERSION}`)
|
||||
}
|
||||
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')
|
||||
await exec.exec(sdkManager, [arg], {
|
||||
|
@ -97,15 +46,33 @@ async function callSdkManager(sdkManager: string, arg: string): Promise<void> {
|
|||
}
|
||||
|
||||
async function installSdkManager(): Promise<string> {
|
||||
fs.mkdirSync(ANDROID_SDK_ROOT, {recursive: true})
|
||||
const cmdlineTools = path.join(ANDROID_SDK_ROOT, 'cmdline-tools', VERSION_SHORT)
|
||||
let sdkManagerExe = path.join(cmdlineTools, 'bin', 'sdkmanager')
|
||||
|
||||
// touch $ANDROID_SDK_ROOT/repositories.cfg
|
||||
fs.closeSync(
|
||||
fs.openSync(path.join(ANDROID_SDK_ROOT, 'repositories.cfg'), 'w')
|
||||
)
|
||||
if (!fs.existsSync(sdkManagerExe)) {
|
||||
const latestCmdlineTools = path.join(ANDROID_SDK_ROOT, 'cmdline-tools', 'latest')
|
||||
const sourcePropertiesFile = path.join(latestCmdlineTools, 'source.properties')
|
||||
const latestSdkManagerExe = path.join(latestCmdlineTools, 'bin', 'sdkmanager')
|
||||
if (
|
||||
fs.existsSync(latestCmdlineTools) &&
|
||||
fs.existsSync(sourcePropertiesFile) &&
|
||||
fs.existsSync(latestSdkManagerExe)
|
||||
) {
|
||||
const sourceProperties = fs.readFileSync(sourcePropertiesFile)
|
||||
core.info(
|
||||
`Found preinstalled sdkmanager in ${latestCmdlineTools} with following source.properties:`
|
||||
)
|
||||
core.info(sourceProperties.toString())
|
||||
if (sourceProperties.includes(`Pkg.Revision=${VERSION_SHORT}`)) {
|
||||
core.info(`Preinstalled sdkmanager has the correct version`)
|
||||
sdkManagerExe = latestSdkManagerExe
|
||||
} else {
|
||||
core.info(`Wrong version in preinstalled sdkmanager`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const sdkManager = findPreinstalledSdkManager()
|
||||
if (!sdkManager.isFound) {
|
||||
if (!fs.existsSync(sdkManagerExe)) {
|
||||
let cmdlineToolsURL
|
||||
if (process.platform === 'linux') {
|
||||
cmdlineToolsURL = COMMANDLINE_TOOLS_LIN_URL
|
||||
|
@ -117,43 +84,25 @@ async function installSdkManager(): Promise<string> {
|
|||
core.error(`Unsupported platform: ${process.platform}`)
|
||||
return ''
|
||||
}
|
||||
|
||||
core.info(`Downloading commandline tools from ${cmdlineToolsURL}`)
|
||||
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
|
||||
)
|
||||
|
||||
// Create parent directory
|
||||
fs.mkdirSync(path.dirname(desiredLocation), {recursive: true})
|
||||
const extractTo = path.join(ANDROID_SDK_ROOT, 'cmdline-tools')
|
||||
await tc.extractZip(cmdlineToolsZip, extractTo)
|
||||
|
||||
// Make sure we don't have leftover target directory (happens sometimes...)
|
||||
if (fs.existsSync(desiredLocation)) fse.removeSync(desiredLocation)
|
||||
|
||||
// @TODO: use io.mv instead of fs-extra.moveSync once following issue is resolved:
|
||||
// https://github.com/actions/toolkit/issues/706
|
||||
fse.moveSync(
|
||||
path.join(cmdlineToolsExtractedLocation, 'cmdline-tools'),
|
||||
desiredLocation
|
||||
)
|
||||
fse.removeSync(cmdlineToolsExtractedLocation)
|
||||
|
||||
sdkManager.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
|
||||
sdkManager.isCorrectVersion = true
|
||||
if (fs.existsSync(cmdlineTools)) {
|
||||
core.info(`Removing leftovers from ${cmdlineTools}`)
|
||||
fs.rmSync(cmdlineTools, {recursive: true})
|
||||
}
|
||||
fs.renameSync(path.join(extractTo, 'cmdline-tools'), cmdlineTools)
|
||||
}
|
||||
|
||||
if (!sdkManager.isCorrectVersion) {
|
||||
await callSdkManager(
|
||||
sdkManager.exePath,
|
||||
`cmdline-tools;${CMDLINE_TOOLS_VERSION}`
|
||||
)
|
||||
sdkManager.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
|
||||
}
|
||||
return sdkManager.exePath
|
||||
// touch $ANDROID_SDK_ROOT/repositories.cfg
|
||||
fs.closeSync(fs.openSync(path.join(ANDROID_SDK_ROOT, 'repositories.cfg'), 'w'))
|
||||
core.debug(`sdkmanager available at: ${sdkManagerExe}`)
|
||||
return sdkManagerExe
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
|
@ -175,17 +124,16 @@ async function run(): Promise<void> {
|
|||
}
|
||||
}
|
||||
|
||||
const sdkManager = await installSdkManager()
|
||||
core.debug(`sdkmanager installed to: ${sdkManager}`)
|
||||
await callSdkManager(sdkManager, '--licenses')
|
||||
await callSdkManager(sdkManager, 'tools')
|
||||
await callSdkManager(sdkManager, 'platform-tools')
|
||||
const sdkManagerExe = await installSdkManager()
|
||||
await callSdkManager(sdkManagerExe, '--licenses')
|
||||
await callSdkManager(sdkManagerExe, 'tools')
|
||||
await callSdkManager(sdkManagerExe, 'platform-tools')
|
||||
|
||||
core.setOutput('ANDROID_COMMANDLINE_TOOLS_VERSION', COMMANDLINE_TOOLS_VERSION)
|
||||
core.setOutput('ANDROID_COMMANDLINE_TOOLS_VERSION', VERSION_LONG)
|
||||
core.exportVariable('ANDROID_HOME', ANDROID_SDK_ROOT)
|
||||
core.exportVariable('ANDROID_SDK_ROOT', ANDROID_SDK_ROOT)
|
||||
|
||||
core.addPath(path.dirname(sdkManager))
|
||||
core.addPath(path.dirname(sdkManagerExe))
|
||||
core.addPath(path.join(ANDROID_SDK_ROOT, 'platform-tools'))
|
||||
|
||||
core.debug('add matchers')
|
||||
|
|
Loading…
Reference in a new issue