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

Pre Emulator Launch Script #247

Merged
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ jobs:
disable-animations: true
working-directory: ./test-fixture/
channel: canary
pre-emulator-launch-script: |
echo "Running pre emulator launch script. Printing the working directory now:"
pwd
script: |
echo $GITHUB_REPOSITORY
adb devices
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,12 @@ jobs:
| `disable-linux-hw-accel` | Optional | `true` | Whether to disable hardware acceleration on Linux machines - `true` or `false`. Note that this is true by default as Github-hosted Linux runners do not support hardware acceleration. |
| `enable-hw-keyboard` | Optional | `false` | Whether to enable hardware keyboard - `true` or `false`. |
| `emulator-build` | Optional | N/A | Build number of a specific version of the emulator binary to use e.g. `6061023` for emulator v29.3.0.0. |
| `working-directory` | Optional | `./` | A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository. |
| `working-directory` | Optional | `./` | A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository. Will be used for `script` & `pre-emulator-launch-script`. |
| `ndk` | Optional | N/A | Version of NDK to install - e.g. `21.0.6113669` |
| `cmake` | Optional | N/A | Version of CMake to install - e.g. `3.10.2.4988404` |
| `channel` | Optional | stable | Channel to download the SDK components from - `stable`, `beta`, `dev`, `canary` |
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` |
| `pre-emulator-launch-script` | Optional | N/A | Custom script to run which will run before launch the emulator - e.g. `./adjust-emulator-configs.sh` |
nilsreichardt marked this conversation as resolved.
Show resolved Hide resolved

Default `emulator-options`: `-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim`.

Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ inputs:
script:
description: 'custom script to run - e.g. `./gradlew connectedCheck`'
required: true
pre-emulator-launch-script:
description: 'custom script to run which will run before launch the emulator - e.g. `./adjust-emulator-configs.sh`'
runs:
using: 'node12'
main: 'lib/main.js'
24 changes: 24 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,33 @@ function run() {
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
console.log(`${script}`);
}));
// custom pre emulator launch script
const preEmulatorLaunchScriptInput = core.getInput('pre-emulator-launch-script');
const preEmulatorLaunchScripts = !preEmulatorLaunchScriptInput ? undefined : script_parser_1.parseScript(preEmulatorLaunchScriptInput);
console.log(`Pre emulator launch script:`);
preEmulatorLaunchScripts === null || preEmulatorLaunchScripts === void 0 ? void 0 : preEmulatorLaunchScripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
console.log(`${script}`);
}));
console.log(`::endgroup::`);
// install SDK
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);
// execute pre emulator launch script if set
if (preEmulatorLaunchScripts !== undefined) {
console.log(`::group::Run pre emulator launch script`);
try {
for (const preEmulatorLaunchScript of preEmulatorLaunchScripts) {
// use array form to avoid various quote escaping problems
// caused by exec(`sh -c "${preEmulatorLaunchScript}"`)
yield exec.exec('sh', ['-c', preEmulatorLaunchScript], {
cwd: workingDirectory
});
}
}
catch (error) {
core.setFailed(error.message);
}
console.log(`::endgroup::`);
}
// launch an emulator
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, ramSize, heapSize, sdcardPathOrSize, diskSize, avdName, forceAvdCreation, emulatorOptions, disableAnimations, disableSpellchecker, disableLinuxHardwareAcceleration, enableHardwareKeyboard);
// execute the custom script
Expand Down
25 changes: 25 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,36 @@ async function run() {
scripts.forEach(async (script: string) => {
console.log(`${script}`);
});

// custom pre emulator launch script
const preEmulatorLaunchScriptInput = core.getInput('pre-emulator-launch-script');
const preEmulatorLaunchScripts = !preEmulatorLaunchScriptInput ? undefined : parseScript(preEmulatorLaunchScriptInput);
console.log(`Pre emulator launch script:`);
preEmulatorLaunchScripts?.forEach(async (script: string) => {
console.log(`${script}`);
});
console.log(`::endgroup::`);

// install SDK
await installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndkVersion, cmakeVersion);

// execute pre emulator launch script if set
if (preEmulatorLaunchScripts !== undefined) {
console.log(`::group::Run pre emulator launch script`);
try {
for (const preEmulatorLaunchScript of preEmulatorLaunchScripts) {
// use array form to avoid various quote escaping problems
// caused by exec(`sh -c "${preEmulatorLaunchScript}"`)
await exec.exec('sh', ['-c', preEmulatorLaunchScript], {
cwd: workingDirectory
});
}
} catch (error) {
core.setFailed(error.message);
}
console.log(`::endgroup::`);
}

// launch an emulator
await launchEmulator(
apiLevel,
Expand Down