From 08e0eb2a04c88d0662bd84b7dd063ddac861124c Mon Sep 17 00:00:00 2001 From: Dmitry Koplyarov Date: Thu, 2 Mar 2023 00:26:20 +0000 Subject: [PATCH 1/2] Add emulator-boot-timeout parameter --- action.yml | 3 +++ lib/emulator-manager.js | 9 ++++----- lib/main.js | 5 ++++- src/emulator-manager.ts | 9 ++++----- src/main.ts | 5 +++++ 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/action.yml b/action.yml index 13ba8e368..194f99db9 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,9 @@ inputs: force-avd-creation: description: 'whether to force create the AVD by overwriting an existing AVD with the same name as `avd-name` - `true` or `false`' default: 'true' + emulator-boot-timeout: + description: 'Emulator boot timeout in seconds. If it takes longer to boot, the action would fail' + default: '600' emulator-options: description: 'command-line options used when launching the emulator - e.g. `-no-window -no-snapshot -camera-back emulated`' default: '-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim' diff --git a/lib/emulator-manager.js b/lib/emulator-manager.js index 428542ded..97b4a435b 100644 --- a/lib/emulator-manager.js +++ b/lib/emulator-manager.js @@ -35,11 +35,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.killEmulator = exports.launchEmulator = void 0; const exec = __importStar(require("@actions/exec")); const fs = __importStar(require("fs")); -const EMULATOR_BOOT_TIMEOUT_SECONDS = 600; /** * Creates and launches a new AVD instance with the specified configurations. */ -function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) { +function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) { return __awaiter(this, void 0, void 0, function* () { try { console.log(`::group::Launch Emulator`); @@ -83,7 +82,7 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSiz }, }); // wait for emulator to complete booting - yield waitForDevice(); + yield waitForDevice(emulatorBootTimeout); yield exec.exec(`adb shell input keyevent 82`); if (disableAnimations) { console.log('Disabling animations.'); @@ -125,12 +124,12 @@ exports.killEmulator = killEmulator; /** * Wait for emulator to boot. */ -function waitForDevice() { +function waitForDevice(emulatorBootTimeout) { return __awaiter(this, void 0, void 0, function* () { let booted = false; let attempts = 0; const retryInterval = 2; // retry every 2 seconds - const maxAttempts = EMULATOR_BOOT_TIMEOUT_SECONDS / 2; + const maxAttempts = emulatorBootTimeout / 2; while (!booted) { try { let result = ''; diff --git a/lib/main.js b/lib/main.js index 99ce8da9d..1bbc7d012 100644 --- a/lib/main.js +++ b/lib/main.js @@ -99,6 +99,9 @@ function run() { (0, input_validator_1.checkForceAvdCreation)(forceAvdCreationInput); const forceAvdCreation = forceAvdCreationInput === 'true'; console.log(`force avd creation: ${forceAvdCreation}`); + // Emulator boot timeout seconds + const emulatorBootTimeout = parseInt(core.getInput('emulator-boot-timeout'), 10); + console.log(`Emulator boot timeout: ${emulatorBootTimeout}`); // emulator options const emulatorOptions = core.getInput('emulator-options').trim(); console.log(`emulator options: ${emulatorOptions}`); @@ -190,7 +193,7 @@ function run() { console.log(`::endgroup::`); } // launch an emulator - yield (0, emulator_manager_1.launchEmulator)(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard); + yield (0, emulator_manager_1.launchEmulator)(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard); // execute the custom script try { // move to custom working directory if set diff --git a/src/emulator-manager.ts b/src/emulator-manager.ts index b596249a7..4f6910472 100644 --- a/src/emulator-manager.ts +++ b/src/emulator-manager.ts @@ -1,8 +1,6 @@ import * as exec from '@actions/exec'; import * as fs from 'fs'; -const EMULATOR_BOOT_TIMEOUT_SECONDS = 600; - /** * Creates and launches a new AVD instance with the specified configurations. */ @@ -18,6 +16,7 @@ export async function launchEmulator( diskSize: string, avdName: string, forceAvdCreation: boolean, + emulatorBootTimeout: number, emulatorOptions: string, disableAnimations: boolean, disableSpellChecker: boolean, @@ -77,7 +76,7 @@ export async function launchEmulator( }); // wait for emulator to complete booting - await waitForDevice(); + await waitForDevice(emulatorBootTimeout); await exec.exec(`adb shell input keyevent 82`); if (disableAnimations) { @@ -114,11 +113,11 @@ export async function killEmulator(): Promise { /** * Wait for emulator to boot. */ -async function waitForDevice(): Promise { +async function waitForDevice(emulatorBootTimeout: number): Promise { let booted = false; let attempts = 0; const retryInterval = 2; // retry every 2 seconds - const maxAttempts = EMULATOR_BOOT_TIMEOUT_SECONDS / 2; + const maxAttempts = emulatorBootTimeout / 2; while (!booted) { try { let result = ''; diff --git a/src/main.ts b/src/main.ts index 4cb0424c2..0f21a2031 100644 --- a/src/main.ts +++ b/src/main.ts @@ -89,6 +89,10 @@ async function run() { const forceAvdCreation = forceAvdCreationInput === 'true'; console.log(`force avd creation: ${forceAvdCreation}`); + // Emulator boot timeout seconds + const emulatorBootTimeout = parseInt(core.getInput('emulator-boot-timeout'), 10); + console.log(`Emulator boot timeout: ${emulatorBootTimeout}`); + // emulator options const emulatorOptions = core.getInput('emulator-options').trim(); console.log(`emulator options: ${emulatorOptions}`); @@ -205,6 +209,7 @@ async function run() { diskSize, avdName, forceAvdCreation, + emulatorBootTimeout, emulatorOptions, disableAnimations, disableSpellchecker, From 0f21778b539bbec3d4cfc92fca0ab25727c1c42d Mon Sep 17 00:00:00 2001 From: Dmitry Koplyarov Date: Fri, 3 Mar 2023 00:05:54 +0000 Subject: [PATCH 2/2] Update action-types.yml --- action-types.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/action-types.yml b/action-types.yml index 1c1d4617c..49cbb7368 100644 --- a/action-types.yml +++ b/action-types.yml @@ -35,6 +35,8 @@ inputs: type: string force-avd-creation: type: boolean + emulator-boot-timeout: + type: integer emulator-options: type: string disable-animations: