mirror of
https://github.com/android-actions/setup-android
synced 2024-11-22 05:29:34 -08:00
also cache repository info
This commit is contained in:
parent
e7b65d73cb
commit
c9080c4243
5 changed files with 46 additions and 38 deletions
2
dist/main/index.js
vendored
2
dist/main/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/post/index.js
vendored
2
dist/post/index.js
vendored
File diff suppressed because one or more lines are too long
11
src/cache.ts
11
src/cache.ts
|
@ -14,7 +14,9 @@ import {
|
|||
ANDROID_GLOB,
|
||||
ANDROID_KEY,
|
||||
COMMANDLINE_TOOLS_VERSION,
|
||||
ANDROID_SDK_ROOT
|
||||
ANDROID_SDK_ROOT,
|
||||
ANDROID_REPOSITORIES_CACHE,
|
||||
ANDROID_REPOSITORIES_CFG
|
||||
} from './constants'
|
||||
|
||||
async function hashFiles(globs: string[]): Promise<string | undefined> {
|
||||
|
@ -144,7 +146,7 @@ export async function preAndroidCache(): Promise<void> {
|
|||
core.saveState(ANDROID_KEY, androidKey)
|
||||
|
||||
const androidCache = await cache.restoreCache(
|
||||
[GRADLE_CACHE_DIR],
|
||||
[ANDROID_SDK_ROOT, ANDROID_REPOSITORIES_CACHE, ANDROID_REPOSITORIES_CFG],
|
||||
androidKey,
|
||||
androidRestoreKeys
|
||||
)
|
||||
|
@ -166,7 +168,10 @@ export async function postAndroidCache(): Promise<void> {
|
|||
return
|
||||
}
|
||||
|
||||
await cache.saveCache([ANDROID_SDK_ROOT], androidKey)
|
||||
await cache.saveCache(
|
||||
[ANDROID_SDK_ROOT, ANDROID_REPOSITORIES_CACHE, ANDROID_REPOSITORIES_CFG],
|
||||
androidKey
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -31,6 +31,16 @@ export const ANDROID_SDK_ROOT = path.join(HOME, 'android')
|
|||
export const ANDROID_GLOB = GRADLE_CACHE_GLOB
|
||||
export const ANDROID_KEY = 'ANDROID_KEY'
|
||||
|
||||
export const ANDROID_REPOSITORIES_DIR = path.join(HOME, '.android')
|
||||
export const ANDROID_REPOSITORIES_CFG = path.join(
|
||||
ANDROID_REPOSITORIES_DIR,
|
||||
'repositories.cfg'
|
||||
)
|
||||
export const ANDROID_REPOSITORIES_CACHE = path.join(
|
||||
ANDROID_REPOSITORIES_DIR,
|
||||
'cache'
|
||||
)
|
||||
|
||||
export const COMMANDLINE_TOOLS_VERSION = '6609375'
|
||||
export const COMMANDLINE_TOOLS_WIN_URL = `https://dl.google.com/android/repository/commandlinetools-win-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
export const COMMANDLINE_TOOLS_MAC_URL = `https://dl.google.com/android/repository/commandlinetools-mac-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
|
|
|
@ -7,60 +7,53 @@ import {
|
|||
ANDROID_SDK_ROOT,
|
||||
COMMANDLINE_TOOLS_LIN_URL,
|
||||
COMMANDLINE_TOOLS_MAC_URL,
|
||||
COMMANDLINE_TOOLS_WIN_URL
|
||||
COMMANDLINE_TOOLS_WIN_URL,
|
||||
ANDROID_REPOSITORIES_CFG,
|
||||
ANDROID_REPOSITORIES_DIR
|
||||
} from './constants'
|
||||
|
||||
export async function install(): Promise<void> {
|
||||
const licenseDir = path.join(ANDROID_SDK_ROOT, 'licenses')
|
||||
|
||||
// If the licences exist, the rest does too
|
||||
if (fs.existsSync(licenseDir)) {
|
||||
if (fs.existsSync(licenseDir) && fs.existsSync(ANDROID_REPOSITORIES_CFG)) {
|
||||
core.debug(`Skipping install, licenseDir found: ${licenseDir}`)
|
||||
return
|
||||
}
|
||||
|
||||
const acceptBuffer = Buffer.from('y\ny\ny\ny\ny\n\ny', 'utf8')
|
||||
// create ~/.android/repositories.cfg
|
||||
fs.mkdirSync(ANDROID_REPOSITORIES_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)
|
||||
const sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager')
|
||||
|
||||
console.log(fs.readdirSync(cmdlineTools))
|
||||
console.log(fs.existsSync(sdkManager))
|
||||
|
||||
exec.exec(
|
||||
sdkManager,
|
||||
['--include_obsolete', `--sdk_root=${ANDROID_SDK_ROOT}`, 'tools'],
|
||||
{
|
||||
input: acceptBuffer
|
||||
}
|
||||
)
|
||||
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)
|
||||
const sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager')
|
||||
|
||||
exec.exec(
|
||||
sdkManager,
|
||||
['--include_obsolete', `--sdk_root=${ANDROID_SDK_ROOT}`, 'tools'],
|
||||
{
|
||||
input: acceptBuffer
|
||||
}
|
||||
)
|
||||
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)
|
||||
const sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager.bat')
|
||||
sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager.bat')
|
||||
} else {
|
||||
core.error(`Unsupported platform: ${process.platform}`)
|
||||
}
|
||||
|
||||
exec.exec(sdkManager, ['--licenses'], {input: acceptBuffer})
|
||||
|
||||
exec.exec(
|
||||
sdkManager,
|
||||
['--include_obsolete', `--sdk_root=${ANDROID_SDK_ROOT}`, 'tools'],
|
||||
{
|
||||
input: acceptBuffer
|
||||
}
|
||||
{input: acceptBuffer}
|
||||
)
|
||||
} else {
|
||||
core.error(`Unsupported platform: ${process.platform}`)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue