Skip to content

Commit 743ec40

Browse files
authored
Add emulator-boot-timeout parameter (#326)
* Add emulator-boot-timeout parameter * Update action-types.yml
1 parent bad4154 commit 743ec40

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

action-types.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ inputs:
3535
type: string
3636
force-avd-creation:
3737
type: boolean
38+
emulator-boot-timeout:
39+
type: integer
3840
emulator-options:
3941
type: string
4042
disable-animations:

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ inputs:
3333
force-avd-creation:
3434
description: 'whether to force create the AVD by overwriting an existing AVD with the same name as `avd-name` - `true` or `false`'
3535
default: 'true'
36+
emulator-boot-timeout:
37+
description: 'Emulator boot timeout in seconds. If it takes longer to boot, the action would fail'
38+
default: '600'
3639
emulator-options:
3740
description: 'command-line options used when launching the emulator - e.g. `-no-window -no-snapshot -camera-back emulated`'
3841
default: '-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim'

lib/emulator-manager.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3535
exports.killEmulator = exports.launchEmulator = void 0;
3636
const exec = __importStar(require("@actions/exec"));
3737
const fs = __importStar(require("fs"));
38-
const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
3938
/**
4039
* Creates and launches a new AVD instance with the specified configurations.
4140
*/
42-
function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) {
41+
function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, emulatorOptions, disableAnimations, disableSpellChecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard) {
4342
return __awaiter(this, void 0, void 0, function* () {
4443
try {
4544
console.log(`::group::Launch Emulator`);
@@ -83,7 +82,7 @@ function launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSiz
8382
},
8483
});
8584
// wait for emulator to complete booting
86-
yield waitForDevice();
85+
yield waitForDevice(emulatorBootTimeout);
8786
yield exec.exec(`adb shell input keyevent 82`);
8887
if (disableAnimations) {
8988
console.log('Disabling animations.');
@@ -125,12 +124,12 @@ exports.killEmulator = killEmulator;
125124
/**
126125
* Wait for emulator to boot.
127126
*/
128-
function waitForDevice() {
127+
function waitForDevice(emulatorBootTimeout) {
129128
return __awaiter(this, void 0, void 0, function* () {
130129
let booted = false;
131130
let attempts = 0;
132131
const retryInterval = 2; // retry every 2 seconds
133-
const maxAttempts = EMULATOR_BOOT_TIMEOUT_SECONDS / 2;
132+
const maxAttempts = emulatorBootTimeout / 2;
134133
while (!booted) {
135134
try {
136135
let result = '';

lib/main.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ function run() {
9999
(0, input_validator_1.checkForceAvdCreation)(forceAvdCreationInput);
100100
const forceAvdCreation = forceAvdCreationInput === 'true';
101101
console.log(`force avd creation: ${forceAvdCreation}`);
102+
// Emulator boot timeout seconds
103+
const emulatorBootTimeout = parseInt(core.getInput('emulator-boot-timeout'), 10);
104+
console.log(`Emulator boot timeout: ${emulatorBootTimeout}`);
102105
// emulator options
103106
const emulatorOptions = core.getInput('emulator-options').trim();
104107
console.log(`emulator options: ${emulatorOptions}`);
@@ -190,7 +193,7 @@ function run() {
190193
console.log(`::endgroup::`);
191194
}
192195
// launch an emulator
193-
yield (0, emulator_manager_1.launchEmulator)(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard);
196+
yield (0, emulator_manager_1.launchEmulator)(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorBootTimeout, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard);
194197
// execute the custom script
195198
try {
196199
// move to custom working directory if set

src/emulator-manager.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import * as exec from '@actions/exec';
22
import * as fs from 'fs';
33

4-
const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
5-
64
/**
75
* Creates and launches a new AVD instance with the specified configurations.
86
*/
@@ -18,6 +16,7 @@ export async function launchEmulator(
1816
diskSize: string,
1917
avdName: string,
2018
forceAvdCreation: boolean,
19+
emulatorBootTimeout: number,
2120
emulatorOptions: string,
2221
disableAnimations: boolean,
2322
disableSpellChecker: boolean,
@@ -77,7 +76,7 @@ export async function launchEmulator(
7776
});
7877

7978
// wait for emulator to complete booting
80-
await waitForDevice();
79+
await waitForDevice(emulatorBootTimeout);
8180
await exec.exec(`adb shell input keyevent 82`);
8281

8382
if (disableAnimations) {
@@ -114,11 +113,11 @@ export async function killEmulator(): Promise<void> {
114113
/**
115114
* Wait for emulator to boot.
116115
*/
117-
async function waitForDevice(): Promise<void> {
116+
async function waitForDevice(emulatorBootTimeout: number): Promise<void> {
118117
let booted = false;
119118
let attempts = 0;
120119
const retryInterval = 2; // retry every 2 seconds
121-
const maxAttempts = EMULATOR_BOOT_TIMEOUT_SECONDS / 2;
120+
const maxAttempts = emulatorBootTimeout / 2;
122121
while (!booted) {
123122
try {
124123
let result = '';

src/main.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ async function run() {
8989
const forceAvdCreation = forceAvdCreationInput === 'true';
9090
console.log(`force avd creation: ${forceAvdCreation}`);
9191

92+
// Emulator boot timeout seconds
93+
const emulatorBootTimeout = parseInt(core.getInput('emulator-boot-timeout'), 10);
94+
console.log(`Emulator boot timeout: ${emulatorBootTimeout}`);
95+
9296
// emulator options
9397
const emulatorOptions = core.getInput('emulator-options').trim();
9498
console.log(`emulator options: ${emulatorOptions}`);
@@ -205,6 +209,7 @@ async function run() {
205209
diskSize,
206210
avdName,
207211
forceAvdCreation,
212+
emulatorBootTimeout,
208213
emulatorOptions,
209214
disableAnimations,
210215
disableSpellchecker,

0 commit comments

Comments
 (0)