mirror of
https://gitea.com/actions/setup-android.git
synced 2025-12-23 15:39:52 +00:00
Compare commits
40 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7506bcd002 | ||
|
|
0bdb2caf82 | ||
|
|
6989f50c81 | ||
|
|
9ab2660a79 | ||
|
|
cc38275357 | ||
|
|
999dabf39c | ||
|
|
6bde8445cd | ||
|
|
1edf194eee | ||
|
|
8c02e1fcfa | ||
|
|
87280a34d4 | ||
|
|
e3e9dc9b68 | ||
|
|
fb95bc1561 | ||
|
|
0df682b3d9 | ||
|
|
0e84f1d6a4 | ||
|
|
9e5b3ce36b | ||
|
|
ebc0cbe4ab | ||
|
|
27f88822ed | ||
|
|
a9018e09bb | ||
|
|
6bb81b1f40 | ||
|
|
7b2dad077d | ||
|
|
6ef7c7f726 | ||
|
|
df284ad095 | ||
|
|
bb3313467a | ||
|
|
8c6fc62420 | ||
|
|
bd524df5da | ||
|
|
e5fc925f91 | ||
|
|
aceb0eac9b | ||
|
|
903dd50e8f | ||
|
|
ec68242df7 | ||
|
|
658d02355a | ||
|
|
72fdd2e74f | ||
|
|
e8ff59719d | ||
|
|
f373a0666c | ||
|
|
e5615156f4 | ||
|
|
943107c4e9 | ||
|
|
9ee0d8a034 | ||
|
|
d7b9d01c78 | ||
|
|
b5b08e0aee | ||
|
|
61b92998bb | ||
|
|
3496691692 |
30
.github/workflows/build-test.yml
vendored
30
.github/workflows/build-test.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Setup node 12
|
||||
uses: actions/setup-node@v2.1.1
|
||||
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.1
|
||||
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.1
|
||||
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.1
|
||||
uses: actions/setup-node@v2.1.4
|
||||
with:
|
||||
node-version: '12'
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ steps:
|
||||
java-version: 1.8
|
||||
|
||||
- name: Setup Android SDK
|
||||
uses: android-actions/setup-android@v1
|
||||
uses: android-actions/setup-android@v2
|
||||
|
||||
- name: Build SampleApplication
|
||||
run: ./gradlew --no-daemon build
|
||||
|
||||
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
5650
package-lock.json
generated
5650
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@@ -25,23 +25,26 @@
|
||||
"author": "daveol",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^1.0.2",
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/tool-cache": "^1.6.0"
|
||||
"@actions/cache": "^1.0.6",
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/tool-cache": "^1.6.1",
|
||||
"fs-extra": "^9.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.10",
|
||||
"@types/node": "^14.6.0",
|
||||
"@typescript-eslint/parser": "^3.9.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.7.0",
|
||||
"eslint": "^7.20.0",
|
||||
"eslint-plugin-github": "^4.1.1",
|
||||
"eslint-plugin-jest": "^23.20.0",
|
||||
"jest": "^24.9.0",
|
||||
"jest-circus": "^26.4.0",
|
||||
"js-yaml": "^3.13.1",
|
||||
"prettier": "^2.0.5",
|
||||
"ts-jest": "^24.2.0",
|
||||
"typescript": "^3.9.7"
|
||||
"eslint-plugin-jest": "^24.1.5",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"js-yaml": "^3.14.1",
|
||||
"prettier": "^2.2.1",
|
||||
"ts-jest": "^26.5.1",
|
||||
"typescript": "^4.1.5"
|
||||
}
|
||||
}
|
||||
|
||||
188
src/main.ts
188
src/main.ts
@@ -3,9 +3,12 @@ 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 COMMANDLINE_TOOLS_VERSION = '6609375'
|
||||
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`
|
||||
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`
|
||||
@@ -13,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')
|
||||
|
||||
Reference in New Issue
Block a user