mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-08-31 17:49:33 +00:00
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import * as core from '@actions/core';
|
|
import { installAndroidSdk } from './sdk-installer';
|
|
import { checkApiLevel, checkTarget, checkArch, checkHeadless, checkDisableAnimations } from './input-validator';
|
|
import { launchEmulator, killEmulator } from './emulator-manager';
|
|
import * as exec from '@actions/exec';
|
|
|
|
async function run() {
|
|
try {
|
|
// only support running on macOS
|
|
if (process.platform !== 'darwin') {
|
|
throw new Error('This action is expected to be run within a macOS virtual machine to enable hardware acceleration.');
|
|
}
|
|
|
|
// API level of the platform and system image
|
|
const apiLevelInput = core.getInput('api-level', { required: true });
|
|
checkApiLevel(apiLevelInput);
|
|
const apiLevel = Number(apiLevelInput);
|
|
console.log(`API level: ${apiLevel}`);
|
|
|
|
// target of the system image
|
|
const target = core.getInput('target');
|
|
checkTarget(target);
|
|
console.log(`target: ${target}`);
|
|
|
|
// CPU architecture of the system image
|
|
const arch = core.getInput('arch');
|
|
checkArch(arch);
|
|
console.log(`CPI architecture: ${arch}`);
|
|
|
|
// Hardware profile used for creating the AVD
|
|
const profile = core.getInput('profile');
|
|
console.log(`Hardware profile: ${profile}`);
|
|
|
|
// headless mode
|
|
const headlessInput = core.getInput('headless');
|
|
checkHeadless(headlessInput);
|
|
const headless = headlessInput === 'true';
|
|
console.log(`headless mode: ${headless}`);
|
|
|
|
// disable animations
|
|
const disableAnimationsInput = core.getInput('disable-animations');
|
|
checkDisableAnimations(disableAnimationsInput);
|
|
const disableAnimations = disableAnimationsInput === 'true';
|
|
console.log(`disable animations: ${disableAnimations}`);
|
|
|
|
// custom scrpt to run
|
|
const scriptInput = core.getInput('script', { required: true });
|
|
const commands = scriptInput.split(/\r?\n/);
|
|
|
|
// install SDK
|
|
await installAndroidSdk(apiLevel, target, arch);
|
|
|
|
// launch an emulator
|
|
await launchEmulator(apiLevel, target, arch, profile, headless, disableAnimations);
|
|
|
|
// execute the custom script
|
|
commands.forEach(async command => {
|
|
await exec.exec(`${command}`);
|
|
});
|
|
|
|
// finally kill the emulator
|
|
await killEmulator();
|
|
} catch (error) {
|
|
// kill the emulator so the action can exit
|
|
await killEmulator();
|
|
core.setFailed(error.message);
|
|
}
|
|
}
|
|
|
|
run();
|