Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emulator-boot-timeout parameter #326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions action-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ inputs:
type: string
force-avd-creation:
type: boolean
emulator-boot-timeout:
type: integer
emulator-options:
type: string
disable-animations:
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
9 changes: 4 additions & 5 deletions lib/emulator-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down Expand Up @@ -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.');
Expand Down Expand Up @@ -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 = '';
Expand Down
5 changes: 4 additions & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions src/emulator-manager.ts
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -18,6 +16,7 @@ export async function launchEmulator(
diskSize: string,
avdName: string,
forceAvdCreation: boolean,
emulatorBootTimeout: number,
emulatorOptions: string,
disableAnimations: boolean,
disableSpellChecker: boolean,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -114,11 +113,11 @@ export async function killEmulator(): Promise<void> {
/**
* Wait for emulator to boot.
*/
async function waitForDevice(): Promise<void> {
async function waitForDevice(emulatorBootTimeout: number): Promise<void> {
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 = '';
Expand Down
5 changes: 5 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down Expand Up @@ -205,6 +209,7 @@ async function run() {
diskSize,
avdName,
forceAvdCreation,
emulatorBootTimeout,
emulatorOptions,
disableAnimations,
disableSpellchecker,
Expand Down