Skip to content

Commit fb4b335

Browse files
committed
fix: allow google_apis_ps16k and google_apis_playstore_ps16k as valid targets
Fixes #403
1 parent e5aa8c7 commit fb4b335

File tree

6 files changed

+41
-8
lines changed

6 files changed

+41
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
|-|-|-|-|
207207
| `api-level` | Required | N/A | API level of the platform and system image - e.g. `23`, `33`, `35-ext15`, `Baklava`. **Minimum API level supported is 15**. |
208208
| `system-image-api-level` | Optional | same as `api-level` | API level of the system image - e.g. `34-ext10`, `35-ext15`. |
209-
| `target` | Optional | `default` | Target of the system image - `default`, `google_apis`, `playstore`, `android-wear`, `android-wear-cn`, `android-tv`, `google-tv`, `aosp_atd`, `google_atd`, `android-automotive`, `android-automotive-playstore` or `android-desktop`. Note that `aosp_atd` and `google_atd` currently require the following: `api-level: 30`, `arch: x86` or `arch: arm64-v8` and `channel: canary`. |
209+
| `target` | Optional | `default` | Target of the system image - `default`, `google_apis`, `google_apis_ps16k`, `playstore`, `playstore_ps16k`, `android-wear`, `android-wear-cn`, `android-tv`, `google-tv`, `aosp_atd`, `google_atd`, `android-automotive`, `android-automotive-playstore` or `android-desktop`. Note that the ATD and PS16K emulators currently require `arch: x86` or `arch: arm64-v8`, ATDs require `api-level` 30 or higher, PS16k require `api-level` 35 or higher. |
210210
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86`, `x86_64` or `arm64-v8a`. Note that `x86_64` image is only available for API 21+. `arm64-v8a` images require Android 4.2+ and are limited to fewer API levels (e.g. 30). |
211211
| `profile` | Optional | N/A | Hardware profile used for creating the AVD - e.g. `Nexus 6`. For a list of all profiles available, run `avdmanager list device`. |
212212
| `cores` | Optional | 2 | Number of cores to use for the emulator (`hw.cpu.ncore` in config.ini). |

__tests__/input-validator.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ describe('target validator tests', () => {
99
expect(func).toThrowError(`Value for input.target 'some-target' is unknown. Supported options: ${validator.VALID_TARGETS}`);
1010
});
1111

12+
it('Validates successfully with playstore target shorthands', () => {
13+
const func1 = () => {
14+
validator.checkTarget('playstore');
15+
};
16+
expect(func1).not.toThrow();
17+
const func2 = () => {
18+
validator.checkTarget('playstore_ps16k');
19+
};
20+
expect(func2).not.toThrow();
21+
});
22+
});
23+
1224
describe('arch validator tests', () => {
1325
it('Throws if arch is unknown', () => {
1426
const func = () => {

lib/input-validator.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
"use strict";
22
Object.defineProperty(exports, "__esModule", { value: true });
3-
exports.checkDiskSize = exports.checkEmulatorBuild = exports.checkEnableHardwareKeyboard = exports.checkDisableLinuxHardwareAcceleration = exports.checkDisableSpellchecker = exports.checkDisableAnimations = exports.checkPort = exports.checkForceAvdCreation = exports.checkChannel = exports.checkArch = exports.checkTarget = exports.MAX_PORT = exports.MIN_PORT = exports.VALID_CHANNELS = exports.VALID_ARCHS = exports.VALID_TARGETS = exports.MIN_API_LEVEL = void 0;
3+
exports.checkDiskSize = exports.checkEmulatorBuild = exports.checkEnableHardwareKeyboard = exports.checkDisableLinuxHardwareAcceleration = exports.checkDisableSpellchecker = exports.checkDisableAnimations = exports.checkPort = exports.checkForceAvdCreation = exports.checkChannel = exports.checkArch = exports.checkTarget = exports.playstoreTargetSubstitution = exports.MAX_PORT = exports.MIN_PORT = exports.VALID_CHANNELS = exports.VALID_ARCHS = exports.VALID_TARGETS = exports.MIN_API_LEVEL = void 0;
44
exports.MIN_API_LEVEL = 15;
55
exports.VALID_TARGETS = [
66
'default',
77
'google_apis',
8+
'google_apis_ps16k',
89
'aosp_atd',
910
'google_atd',
1011
'google_apis_playstore',
12+
'google_apis_playstore_ps16k',
1113
'android-wear',
1214
'android-wear-cn',
1315
'android-tv',
@@ -20,8 +22,18 @@ exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a'];
2022
exports.VALID_CHANNELS = ['stable', 'beta', 'dev', 'canary'];
2123
exports.MIN_PORT = 5554;
2224
exports.MAX_PORT = 5584;
25+
function playstoreTargetSubstitution(target) {
26+
// "playstore" is an allowed shorthand for "google_apis_playstore" images
27+
// this is idempotent - return same even if run multiple times on same target
28+
if (target === 'playstore')
29+
return 'google_apis_playstore';
30+
if (target === 'playstore_ps16k')
31+
return 'google_apis_playstore_ps16k';
32+
return target;
33+
}
34+
exports.playstoreTargetSubstitution = playstoreTargetSubstitution;
2335
function checkTarget(target) {
24-
if (!exports.VALID_TARGETS.includes(target)) {
36+
if (!exports.VALID_TARGETS.includes(playstoreTargetSubstitution(target))) {
2537
throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${exports.VALID_TARGETS}.`);
2638
}
2739
}

lib/main.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ function run() {
7070
}
7171
console.log(`System image API level: ${systemImageApiLevel}`);
7272
// target of the system image
73-
const targetInput = core.getInput('target');
74-
const target = targetInput == 'playstore' ? 'google_apis_playstore' : targetInput;
73+
const target = (0, input_validator_1.playstoreTargetSubstitution)(core.getInput('target'));
7574
(0, input_validator_1.checkTarget)(target);
7675
console.log(`target: ${target}`);
7776
// CPU architecture of the system image

src/input-validator.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ export const MIN_API_LEVEL = 15;
22
export const VALID_TARGETS: Array<string> = [
33
'default',
44
'google_apis',
5+
'google_apis_ps16k',
56
'aosp_atd',
67
'google_atd',
78
'google_apis_playstore',
9+
'google_apis_playstore_ps16k',
810
'android-wear',
911
'android-wear-cn',
1012
'android-tv',
@@ -18,8 +20,16 @@ export const VALID_CHANNELS: Array<string> = ['stable', 'beta', 'dev', 'canary']
1820
export const MIN_PORT = 5554;
1921
export const MAX_PORT = 5584;
2022

23+
export function playstoreTargetSubstitution(target: string): string {
24+
// "playstore" is an allowed shorthand for "google_apis_playstore" images
25+
// this is idempotent - return same even if run multiple times on same target
26+
if (target === 'playstore') return 'google_apis_playstore';
27+
if (target === 'playstore_ps16k') return 'google_apis_playstore_ps16k';
28+
return target;
29+
}
30+
2131
export function checkTarget(target: string): void {
22-
if (!VALID_TARGETS.includes(target)) {
32+
if (!VALID_TARGETS.includes(playstoreTargetSubstitution(target))) {
2333
throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${VALID_TARGETS}.`);
2434
}
2535
}

src/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
checkEnableHardwareKeyboard,
1313
checkDiskSize,
1414
checkPort,
15+
playstoreTargetSubstitution,
1516
MIN_PORT,
1617
} from './input-validator';
1718
import { createAvd, launchEmulator, killEmulator } from './emulator-manager';
@@ -52,8 +53,7 @@ async function run() {
5253
console.log(`System image API level: ${systemImageApiLevel}`);
5354

5455
// target of the system image
55-
const targetInput = core.getInput('target');
56-
const target = targetInput == 'playstore' ? 'google_apis_playstore' : targetInput;
56+
const target = playstoreTargetSubstitution(core.getInput('target'));
5757
checkTarget(target);
5858
console.log(`target: ${target}`);
5959

0 commit comments

Comments
 (0)