Add input validations with tests.

This commit is contained in:
Yang Chen
2019-11-06 18:59:27 +11:00
parent d6aab89c3b
commit 137c96a972
9 changed files with 168 additions and 54 deletions
+14 -22
View File
@@ -17,6 +17,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(require("@actions/core"));
const sdk_installer_1 = require("./sdk-installer");
const input_validator_1 = require("./input-validator");
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
@@ -24,31 +25,22 @@ function run() {
if (process.platform !== 'darwin') {
throw new Error('This action is expected to be run within a macOS virtual machine to enable hardware acceleration.');
}
// TODO test inputs
// TODO test real inputs in test.yml
// api-level is required
// TODO use InputOptions {true}
const apiLevel = core.getInput('api-level');
// TODO check apiLevel is number and within valid range
console.log(`API level - ${apiLevel}`);
// target is optional with default
// API level of the platform and system image
const apiLevel = core.getInput('api-level', { required: true });
input_validator_1.checkApiLevel(apiLevel);
console.log(`API level: ${apiLevel}`);
// target of the system image
const target = core.getInput('target');
if (target !== 'default' && target !== 'google_apis') {
throw new Error(`Target ${target} is unknown. Please use either 'default' or 'google_apis'.`);
}
console.log(`target - ${target}`);
// abi is optional with default
input_validator_1.checkTarget(target);
console.log(`target: ${target}`);
// CPU / ABI of the system image
const abi = core.getInput('abi');
if (abi !== 'x86' && abi !== 'x86_64') {
throw new Error(`abi ${abi} is unknown (ARM-based emulators are not supported). Please use either 'x86' or 'x86_64'.`);
}
console.log(`cpu/abi - ${abi}`);
// headless is optional with default
input_validator_1.checkAbi(abi);
console.log(`cpu/abi: ${abi}`);
// headless mode
const headless = core.getInput('headless');
if (headless !== 'true' && headless !== 'false') {
throw new Error(`Input 'headless' should be either 'true' or 'false'.`);
}
console.log(`headless mode - ${headless}`);
input_validator_1.checkHeadless(headless);
console.log(`headless mode: ${headless}`);
// install SDK
yield sdk_installer_1.installAndroidSdk(Number(apiLevel), target, abi);
// TODO start emulator