mirror of
https://gitea.com/actions/setup-android.git
synced 2025-12-12 19:36:59 +00:00
Changeup: consilidate code, drop cache, change download
This changes up way too much: - Moving most (all) of the code to main.ts instead of the numerous files - Dropping the caching functionality, since it should be optional - now we will only download the android sdk tools if they are not already present, including if ANDROID_SDK_ROOT is already set
This commit is contained in:
78
src/main.ts
78
src/main.ts
@@ -1,14 +1,71 @@
|
||||
import * as core from '@actions/core'
|
||||
import * as tc from '@actions/tool-cache'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as path from 'path'
|
||||
import {ANDROID_SDK_ROOT, ANNOTATION_MATCHERS} from './constants'
|
||||
import {preGradleCache, preAndroidCache, preGradleWrapper} from './cache'
|
||||
import {install} from './install'
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
|
||||
const COMMANDLINE_TOOLS_VERSION = '6609375'
|
||||
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 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')
|
||||
|
||||
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')
|
||||
|
||||
// If the licences exist, the rest does too
|
||||
if (fs.existsSync(licenseDir) && fs.existsSync(ANDROID_REPOSITORIES_CFG)) {
|
||||
core.debug(`Skipping install, licenseDir found: ${licenseDir}`)
|
||||
return ANDROID_SDK_ROOT
|
||||
}
|
||||
|
||||
// create ~/.android/repositories.cfg
|
||||
fs.mkdirSync(ANDROID_HOME_SDK_DIR, {recursive: true})
|
||||
fs.closeSync(fs.openSync(ANDROID_REPOSITORIES_CFG, 'w'))
|
||||
|
||||
const acceptBuffer = Buffer.from(Array(10).fill('y').join('\n'), 'utf8')
|
||||
let sdkManager = ''
|
||||
|
||||
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}`)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
// process all caching but wait for them to all complete
|
||||
await Promise.all([preGradleWrapper(), preGradleCache(), preAndroidCache()])
|
||||
|
||||
await install()
|
||||
const ANDROID_SDK_ROOT = await install()
|
||||
|
||||
core.exportVariable('ANDROID_HOME', ANDROID_SDK_ROOT)
|
||||
core.exportVariable('ANDROID_SDK_ROOT', ANDROID_SDK_ROOT)
|
||||
@@ -17,11 +74,8 @@ async function run(): Promise<void> {
|
||||
core.addPath(path.join(ANDROID_SDK_ROOT, 'platform-tools'))
|
||||
|
||||
core.debug('add matchers')
|
||||
const matchersPath = path.join(__dirname, '..', '..', '.github')
|
||||
for (const matcher of ANNOTATION_MATCHERS) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`##[add-matcher]${path.join(matchersPath, matcher)}`)
|
||||
}
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`##[add-matcher]${path.join(__dirname, '..', 'matchers.json')}`)
|
||||
}
|
||||
|
||||
run()
|
||||
|
||||
Reference in New Issue
Block a user