also cache repository info

This commit is contained in:
Dave Olsthoorn 2020-07-25 19:24:48 +02:00
parent e7b65d73cb
commit c9080c4243
5 changed files with 46 additions and 38 deletions

2
dist/main/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/post/index.js vendored

File diff suppressed because one or more lines are too long

View file

@ -14,7 +14,9 @@ import {
ANDROID_GLOB, ANDROID_GLOB,
ANDROID_KEY, ANDROID_KEY,
COMMANDLINE_TOOLS_VERSION, COMMANDLINE_TOOLS_VERSION,
ANDROID_SDK_ROOT ANDROID_SDK_ROOT,
ANDROID_REPOSITORIES_CACHE,
ANDROID_REPOSITORIES_CFG
} from './constants' } from './constants'
async function hashFiles(globs: string[]): Promise<string | undefined> { async function hashFiles(globs: string[]): Promise<string | undefined> {
@ -144,7 +146,7 @@ export async function preAndroidCache(): Promise<void> {
core.saveState(ANDROID_KEY, androidKey) core.saveState(ANDROID_KEY, androidKey)
const androidCache = await cache.restoreCache( const androidCache = await cache.restoreCache(
[GRADLE_CACHE_DIR], [ANDROID_SDK_ROOT, ANDROID_REPOSITORIES_CACHE, ANDROID_REPOSITORIES_CFG],
androidKey, androidKey,
androidRestoreKeys androidRestoreKeys
) )
@ -166,7 +168,10 @@ export async function postAndroidCache(): Promise<void> {
return return
} }
await cache.saveCache([ANDROID_SDK_ROOT], androidKey) await cache.saveCache(
[ANDROID_SDK_ROOT, ANDROID_REPOSITORIES_CACHE, ANDROID_REPOSITORIES_CFG],
androidKey
)
return return
} }

View file

@ -31,6 +31,16 @@ export const ANDROID_SDK_ROOT = path.join(HOME, 'android')
export const ANDROID_GLOB = GRADLE_CACHE_GLOB export const ANDROID_GLOB = GRADLE_CACHE_GLOB
export const ANDROID_KEY = 'ANDROID_KEY' 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_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_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` export const COMMANDLINE_TOOLS_MAC_URL = `https://dl.google.com/android/repository/commandlinetools-mac-${COMMANDLINE_TOOLS_VERSION}_latest.zip`

View file

@ -7,60 +7,53 @@ import {
ANDROID_SDK_ROOT, ANDROID_SDK_ROOT,
COMMANDLINE_TOOLS_LIN_URL, COMMANDLINE_TOOLS_LIN_URL,
COMMANDLINE_TOOLS_MAC_URL, COMMANDLINE_TOOLS_MAC_URL,
COMMANDLINE_TOOLS_WIN_URL COMMANDLINE_TOOLS_WIN_URL,
ANDROID_REPOSITORIES_CFG,
ANDROID_REPOSITORIES_DIR
} from './constants' } from './constants'
export async function install(): Promise<void> { export async function install(): Promise<void> {
const licenseDir = path.join(ANDROID_SDK_ROOT, 'licenses') const licenseDir = path.join(ANDROID_SDK_ROOT, 'licenses')
// If the licences exist, the rest does too // 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}`) core.debug(`Skipping install, licenseDir found: ${licenseDir}`)
return 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') { if (process.platform === 'linux') {
const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_LIN_URL) const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_LIN_URL)
const cmdlineTools = await tc.extractZip(cmdlineToolsZip) const cmdlineTools = await tc.extractZip(cmdlineToolsZip)
const sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager') 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
}
)
} else if (process.platform === 'darwin') { } else if (process.platform === 'darwin') {
const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_MAC_URL) const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_MAC_URL)
const cmdlineTools = await tc.extractZip(cmdlineToolsZip) const cmdlineTools = await tc.extractZip(cmdlineToolsZip)
const sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager') sdkManager = path.join(cmdlineTools, 'tools', 'bin', 'sdkmanager')
exec.exec(
sdkManager,
['--include_obsolete', `--sdk_root=${ANDROID_SDK_ROOT}`, 'tools'],
{
input: acceptBuffer
}
)
} else if (process.platform === 'win32') { } else if (process.platform === 'win32') {
const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_WIN_URL) const cmdlineToolsZip = await tc.downloadTool(COMMANDLINE_TOOLS_WIN_URL)
const cmdlineTools = await tc.extractZip(cmdlineToolsZip) 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( exec.exec(
sdkManager, sdkManager,
['--include_obsolete', `--sdk_root=${ANDROID_SDK_ROOT}`, 'tools'], ['--include_obsolete', `--sdk_root=${ANDROID_SDK_ROOT}`, 'tools'],
{ {input: acceptBuffer}
input: acceptBuffer
}
) )
} else {
core.error(`Unsupported platform: ${process.platform}`)
}
} }