Support multi-line script.

This commit is contained in:
Yang Chen
2019-12-13 18:17:53 +11:00
committed by ychescale9
parent ae2123e35c
commit 9739504a54
8 changed files with 114 additions and 19 deletions
+2 -3
View File
@@ -49,7 +49,7 @@ export async function killEmulator(): Promise<void> {
try {
await exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
} catch (error) {
console.log('No emulator running on port 5554');
console.log(error.message);
}
}
@@ -57,7 +57,6 @@ export async function killEmulator(): Promise<void> {
* Wait for emulator to boot.
*/
async function waitForDevice(): Promise<void> {
const adbPath = `${process.env.ANDROID_HOME}/platform-tools/adb`;
let booted = false;
let attempts = 0;
const retryInterval = 2; // retry every 2 seconds
@@ -65,7 +64,7 @@ async function waitForDevice(): Promise<void> {
while (!booted) {
try {
let result = '';
await exec.exec(`${adbPath} shell getprop sys.boot_completed`, [], {
await exec.exec(`${ADB_PATH} shell getprop sys.boot_completed`, [], {
listeners: {
stdout: (data: Buffer) => {
result += data.toString();
+18 -6
View File
@@ -3,6 +3,7 @@ import { installAndroidSdk } from './sdk-installer';
import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations } from './input-validator';
import { launchEmulator, killEmulator } from './emulator-manager';
import * as exec from '@actions/exec';
import { parseScript } from './script-parser';
async function run() {
try {
@@ -25,7 +26,7 @@ async function run() {
// CPU architecture of the system image
const arch = core.getInput('arch');
checkArch(arch);
console.log(`CPI architecture: ${arch}`);
console.log(`CPU architecture: ${arch}`);
// Hardware profile used for creating the AVD
const profile = core.getInput('profile');
@@ -41,8 +42,13 @@ async function run() {
const disableAnimations = disableAnimationsInput === 'true';
console.log(`disable animations: ${disableAnimations}`);
// custom scrpt to run
const script = core.getInput('script', { required: true });
// custom script to run
const scriptInput = core.getInput('script', { required: true });
const scripts = parseScript(scriptInput);
console.log(`Script:`);
scripts.forEach(async (script: string) => {
console.log(`${script}`);
});
try {
// install SDK
@@ -50,13 +56,19 @@ async function run() {
// launch an emulator
await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
// execute the custom script
await exec.exec(`${script}`);
} catch (error) {
core.setFailed(error.message);
}
// execute the custom script
scripts.forEach(async (script: string) => {
try {
await exec.exec(`${script}`);
} catch (error) {
core.setFailed(error.message);
}
});
// finally kill the emulator
await killEmulator();
} catch (error) {
+18
View File
@@ -0,0 +1,18 @@
/**
* Convert a (potentially multi-line) script to an array of single-line script(s).
*/
export function parseScript(rawScript: string): Array<string> {
const scripts: Array<string> = rawScript
.trim()
.split(/\r\n|\n|\r/)
.map((value: string) => value.trim())
.filter((value: string) => {
return !value.startsWith('#') && value.length > 0;
});
if (scripts.length == 0) {
throw new Error(`No valid script found.`);
}
return scripts;
}