Skip to content

Commit 3f52989

Browse files
committed
Merge branch 'master' into release/v2
* master: Prepare for release 2.2.0. Stop pinning emulator build in workflow. Add support for pinning specific emulator build. Explicitly set GPU mode to swiftshader_indirect. Fix script execution order. Run test fixture in workflow.
2 parents da41ec9 + 86385e0 commit 3f52989

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+817
-31
lines changed

.github/workflows/workflow.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ jobs:
2727
npm run lint
2828
npm test
2929
30+
- name: Prepare test fixture
31+
run: cp -a ./test-fixture/* ./
32+
3033
- name: run action
3134
uses: ./
3235
with:
3336
api-level: ${{ matrix.api-level }}
3437
target: google_apis
35-
arch: x86_64
38+
arch: x86
3639
profile: Nexus 6
37-
emulator-options: -no-window -no-snapshot -noaudio -no-boot-anim -camera-back none
40+
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
3841
disable-animations: true
3942
script: |
40-
adb reconnect
41-
adb devices -l
43+
./gradlew help
44+
./gradlew connectedDebugAndroidTest

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
## v2.2.0
4+
5+
* Fixed an issue where emulator is killed prematurely.
6+
* Added `-gpu swiftshader_indirect` to default `launch-options`.
7+
* Added support for pinning a specific `emulator-build` - e.g. `6061023` for emulator **v29.3.0.0**.
8+
39
## v2.1.0
410

511
* Added support for multi-line script.

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ jobs:
7777
| `target` | Optional | `default` | Target of the system image - `default` or `google_apis`. |
7878
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. |
7979
| `profile` | Optional | N/A | Hardware profile used for creating the AVD - e.g. `Nexus 6`. For a list of all profiles available, run `$ANDROID_HOME/tools/bin/avdmanager list` and refer to the results under "Available Android Virtual Devices". |
80-
| `emulator-options` | Optional | See below | Command-line options used when launching the emulator (replacing all default options) - e.g. `-no-snapshot -camera-back emulated`. |
80+
| `emulator-options` | Optional | See below | Command-line options used when launching the emulator (replacing all default options) - e.g. `-no-window -no-snapshot -camera-back emulated`. |
8181
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
82+
| `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. |
8283
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` |
8384

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

__tests__/input-validator.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,26 @@ describe('disable-animations validator tests', () => {
9797
expect(func2).not.toThrow();
9898
});
9999
});
100+
101+
describe('emulator-build validator tests', () => {
102+
it('Throws if emulator-build is not a number', () => {
103+
const func = () => {
104+
validator.checkEmulatorBuild('abc123');
105+
};
106+
expect(func).toThrowError(`Unexpected emulator build: 'abc123'.`);
107+
});
108+
109+
it('Throws if emulator-build is not an integer', () => {
110+
const func = () => {
111+
validator.checkEmulatorBuild('123.123');
112+
};
113+
expect(func).toThrowError(`Unexpected emulator build: '123.123'.`);
114+
});
115+
116+
it('Validates successfully with valid emulator-build', () => {
117+
const func = () => {
118+
validator.checkEmulatorBuild('6061023');
119+
};
120+
expect(func).not.toThrow();
121+
});
122+
});

action.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ inputs:
1717
profile:
1818
description: 'Hardware profile used for creating the AVD - e.g. `Nexus 6`.'
1919
emulator-options:
20-
description: 'command-line options used when launching the emulator - e.g. `-no-snapshot -camera-back emulated`.'
21-
default: '-no-window -no-snapshot -noaudio -no-boot-anim'
20+
description: 'command-line options used when launching the emulator - e.g. `-no-window -no-snapshot -camera-back emulated`.'
21+
default: '-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim'
2222
disable-animations:
2323
description: 'whether to disable animations - true or false'
2424
default: 'true'
25+
emulator-build:
26+
description: 'build number of a specific version of the emulator binary to use e.g. `6061023` for emulator v29.3.0.0.'
2527
script:
2628
description: 'custom script to run - e.g. `./gradlew connectedCheck`'
2729
required: true

lib/input-validator.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,9 @@ function checkDisableAnimations(disableAnimations) {
3030
}
3131
}
3232
exports.checkDisableAnimations = checkDisableAnimations;
33+
function checkEmulatorBuild(emulatorBuild) {
34+
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
35+
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
36+
}
37+
}
38+
exports.checkEmulatorBuild = checkEmulatorBuild;

lib/main.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,38 @@ function run() {
5252
input_validator_1.checkDisableAnimations(disableAnimationsInput);
5353
const disableAnimations = disableAnimationsInput === 'true';
5454
console.log(`disable animations: ${disableAnimations}`);
55+
// emulator build
56+
const emulatorBuildInput = core.getInput('emulator-build');
57+
if (emulatorBuildInput) {
58+
input_validator_1.checkEmulatorBuild(emulatorBuildInput);
59+
console.log(`using emulator build: ${emulatorBuildInput}`);
60+
}
61+
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;
5562
// custom script to run
5663
const scriptInput = core.getInput('script', { required: true });
5764
const scripts = script_parser_1.parseScript(scriptInput);
5865
console.log(`Script:`);
5966
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
6067
console.log(`${script}`);
6168
}));
69+
// install SDK
70+
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild);
6271
try {
63-
// install SDK
64-
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch);
6572
// launch an emulator
6673
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
6774
}
6875
catch (error) {
6976
core.setFailed(error.message);
7077
}
7178
// execute the custom script
72-
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
73-
try {
79+
try {
80+
for (const script of scripts) {
7481
yield exec.exec(`${script}`);
7582
}
76-
catch (error) {
77-
core.setFailed(error.message);
78-
}
79-
}));
83+
}
84+
catch (error) {
85+
core.setFailed(error.message);
86+
}
8087
// finally kill the emulator
8188
yield emulator_manager_1.killEmulator();
8289
}

lib/sdk-installer.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,22 @@ const BUILD_TOOLS_VERSION = '29.0.2';
2121
* Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
2222
* and the system image for the chosen API level, CPU arch, and target.
2323
*/
24-
function installAndroidSdk(apiLevel, target, arch) {
24+
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
2525
return __awaiter(this, void 0, void 0, function* () {
2626
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
27-
console.log('Installing latest build tools, platform tools, platform, and emulator.');
28-
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' emulator > /dev/null"`);
27+
console.log('Installing latest build tools, platform tools, and platform.');
28+
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
29+
if (emulatorBuild) {
30+
console.log(`Installing emulator build ${emulatorBuild}.`);
31+
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
32+
yield exec.exec(`rm -rf ${process.env.ANDROID_HOME}/emulator`);
33+
yield exec.exec(`unzip -q emulator.zip -d ${process.env.ANDROID_HOME}`);
34+
yield exec.exec(`rm -f emulator.zip`);
35+
}
36+
else {
37+
console.log('Installing latest emulator.');
38+
yield exec.exec(`sh -c \\"${sdkmangerPath} --install emulator > /dev/null"`);
39+
}
2940
console.log('Installing system images.');
3041
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
3142
});

src/input-validator.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ export function checkDisableAnimations(disableAnimations: string): void {
2828
throw new Error(`Input for input.disable-animations should be either 'true' or 'false'.`);
2929
}
3030
}
31+
32+
export function checkEmulatorBuild(emulatorBuild: string): void {
33+
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
34+
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
35+
}
36+
}

src/main.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as core from '@actions/core';
22
import { installAndroidSdk } from './sdk-installer';
3-
import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations } from './input-validator';
3+
import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmulatorBuild } from './input-validator';
44
import { launchEmulator, killEmulator } from './emulator-manager';
55
import * as exec from '@actions/exec';
66
import { parseScript } from './script-parser';
@@ -42,6 +42,14 @@ async function run() {
4242
const disableAnimations = disableAnimationsInput === 'true';
4343
console.log(`disable animations: ${disableAnimations}`);
4444

45+
// emulator build
46+
const emulatorBuildInput = core.getInput('emulator-build');
47+
if (emulatorBuildInput) {
48+
checkEmulatorBuild(emulatorBuildInput);
49+
console.log(`using emulator build: ${emulatorBuildInput}`);
50+
}
51+
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;
52+
4553
// custom script to run
4654
const scriptInput = core.getInput('script', { required: true });
4755
const scripts = parseScript(scriptInput);
@@ -50,24 +58,24 @@ async function run() {
5058
console.log(`${script}`);
5159
});
5260

53-
try {
54-
// install SDK
55-
await installAndroidSdk(apiLevel, target, arch);
61+
// install SDK
62+
await installAndroidSdk(apiLevel, target, arch, emulatorBuild);
5663

64+
try {
5765
// launch an emulator
5866
await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
5967
} catch (error) {
6068
core.setFailed(error.message);
6169
}
6270

6371
// execute the custom script
64-
scripts.forEach(async (script: string) => {
65-
try {
72+
try {
73+
for (const script of scripts) {
6674
await exec.exec(`${script}`);
67-
} catch (error) {
68-
core.setFailed(error.message);
6975
}
70-
});
76+
} catch (error) {
77+
core.setFailed(error.message);
78+
}
7179

7280
// finally kill the emulator
7381
await killEmulator();

0 commit comments

Comments
 (0)