Skip to content

Commit

Permalink
Merge branch 'master' into release/v1
Browse files Browse the repository at this point in the history
* master:
  Switch to sh.
  Update README.md
  Fix typos in docs.
  • Loading branch information
ychescale9 committed Nov 24, 2019
2 parents 483b89e + b34584f commit 6097e0a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ A GitHub Action for installing, configuring and running Android Emulators on mac

The old ARM-based emulators were slow and are no longer supported by Google. The modern Intel Atom (x86 and x86_64) emulators require hardware acceleration (HAXM on Mac & Windows, QEMU on Linux) from the host to run fast. This presents a challenge on CI as to be able to run hardware accelerated emulators within a docker container, **KVM** must be supported by the host VM which isn't the case for cloud-based CI providers due to infrastructural limits.

The **masOS** VM provided by **GitHub Actions** has **HAXM** installed so we are able to create a new AVD instance, launch an emulator with hardware acceleration, and run our Android instrumented tests directly on the VM.
The **masOS** VM provided by **GitHub Actions** has **HAXM** installed so we are able to create a new AVD instance, launch an emulator with hardware acceleration, and run our Android
tests directly on the VM.

This Action automates the process by doing the following:
This action automates the process by doing the following:

- Install / update the required **Android SDK** components including `build-tools`, `platform-tools`, `platform` (for the required API level), `emulator` and `system-images` (for the required API level).
- Create a new instance of **AVD** with the required [configurations](#configurations).
- Launch a new Emulator with the required [configurations](#configurations).
- Create a new instance of **AVD** with the provided [configurations](#configurations).
- Launch a new Emulator with the provided [configurations](#configurations).
- Wait until the Emulator is booted and ready for use.
- Run a custom script provided by the user of the action - e.g. `./gradlew connectedCheck`.
- Kill the Emulator and the finish the action.
- Run a custom script provided by user once the Emulator is up and running - e.g. `./gradlew connectedCheck`.
- Kill the Emulator and finish the action.

## Usage

Note that this action must be run on a **macOS** VM, e.g. `macOS-latest` or `macOS-10.14`.

A workflow that uses **android-emulator-runner** to run your instrumented on **API 29**:
A workflow that uses **android-emulator-runner** to run your instrumented tests on **API 29**:

```
jobs:
Expand Down
4 changes: 2 additions & 2 deletions lib/emulator-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ function launchEmulator(apiLevel, target, arch, profile, headless, disableAnimat
}
else {
console.log(`Creating AVD without custom profile.`);
yield exec.exec(`bash -c \\"echo no | ${AVD_MANAGER_PATH} create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
yield exec.exec(`sh -c \\"echo no | ${AVD_MANAGER_PATH} create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
}
// start emulator
console.log('Starting emulator.');
const noWindow = headless ? '-no-window' : '';
yield exec.exec(`bash -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${noWindow} -no-snapshot -noaudio -no-boot-anim &"`);
yield exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${noWindow} -no-snapshot -noaudio -no-boot-anim &"`);
// wait for emulator to complete booting
yield waitForDevice();
yield exec.exec(`${ADB_PATH} shell input keyevent 82`);
Expand Down
4 changes: 2 additions & 2 deletions lib/sdk-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ function installAndroidSdk(apiLevel, target, arch) {
return __awaiter(this, void 0, void 0, function* () {
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
console.log('Installing latest build tools, platform tools, platform, and emulator.');
yield exec.exec(`bash -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' emulator > /dev/null"`);
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' emulator > /dev/null"`);
console.log('Installing system images.');
yield exec.exec(`bash -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
});
}
exports.installAndroidSdk = installAndroidSdk;
4 changes: 2 additions & 2 deletions src/emulator-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export async function launchEmulator(apiLevel: number, target: string, arch: str
await exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
} else {
console.log(`Creating AVD without custom profile.`);
await exec.exec(`bash -c \\"echo no | ${AVD_MANAGER_PATH} create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
await exec.exec(`sh -c \\"echo no | ${AVD_MANAGER_PATH} create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'"`);
}

// start emulator
console.log('Starting emulator.');
const noWindow = headless ? '-no-window' : '';
await exec.exec(`bash -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${noWindow} -no-snapshot -noaudio -no-boot-anim &"`);
await exec.exec(`sh -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${noWindow} -no-snapshot -noaudio -no-boot-anim &"`);

// wait for emulator to complete booting
await waitForDevice();
Expand Down
4 changes: 2 additions & 2 deletions src/sdk-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const BUILD_TOOLS_VERSION = '29.0.2';
export async function installAndroidSdk(apiLevel: number, target: string, arch: string): Promise<void> {
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
console.log('Installing latest build tools, platform tools, platform, and emulator.');
await exec.exec(`bash -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' emulator > /dev/null"`);
await exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' emulator > /dev/null"`);
console.log('Installing system images.');
await exec.exec(`bash -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
await exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
}

0 comments on commit 6097e0a

Please sign in to comment.