Skip to content

Commit 66283c0

Browse files
fix: allow google_apis_ps16k as a valid target (#440)
* test: remove target validator test these appear to have too much maintenance burden as they only ever add more over time * fix: allow google_apis_ps16k and google_apis_playstore_ps16k as valid targets Fixes #403 Co-authored-by: Yang <reactivecircus@gmail.com> * fix: remove target validation entirely, any valid sdkmanager target will work no longer requires code changes here to access new targets --------- Co-authored-by: Yang <reactivecircus@gmail.com>
1 parent f2bf410 commit 66283c0

File tree

7 files changed

+21
-118
lines changed

7 files changed

+21
-118
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 - e.g. `default`, `google_apis`, `google_apis_ps16k`, `google_apis_playstore`, `google_apis_playstore_ps16k`, `android-wear`, `android-wear-cn`, `android-tv`, `google-tv`, `aosp_atd`, `google_atd`, `android-automotive`, `android-automotive-playstore, `android-desktop`. Please run `sdkmanager --list` to see the available targets. |
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: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,6 @@
11
import * as validator from '../src/input-validator';
22
import { MAX_PORT, MIN_PORT } from '../src/input-validator';
33

4-
describe('target validator tests', () => {
5-
it('Throws if target is unknown', () => {
6-
const func = () => {
7-
validator.checkTarget('some-target');
8-
};
9-
expect(func).toThrowError(`Value for input.target 'some-target' is unknown. Supported options: ${validator.VALID_TARGETS}`);
10-
});
11-
12-
it('Validates successfully with valid target', () => {
13-
const func1 = () => {
14-
validator.checkTarget('default');
15-
};
16-
expect(func1).not.toThrow();
17-
18-
const func2 = () => {
19-
validator.checkTarget('google_apis');
20-
};
21-
expect(func2).not.toThrow();
22-
23-
const func3 = () => {
24-
validator.checkTarget('aosp_atd');
25-
};
26-
expect(func3).not.toThrow();
27-
28-
const func4 = () => {
29-
validator.checkTarget('google_atd');
30-
};
31-
expect(func4).not.toThrow();
32-
33-
const func5 = () => {
34-
validator.checkTarget('google_apis_playstore');
35-
};
36-
expect(func5).not.toThrow();
37-
38-
const func6 = () => {
39-
validator.checkTarget('android-wear');
40-
};
41-
expect(func6).not.toThrow();
42-
43-
const func7 = () => {
44-
validator.checkTarget('android-wear-cn');
45-
};
46-
expect(func7).not.toThrow();
47-
48-
const func8 = () => {
49-
validator.checkTarget('android-tv');
50-
};
51-
expect(func8).not.toThrow();
52-
53-
const func9 = () => {
54-
validator.checkTarget('google-tv');
55-
};
56-
expect(func9).not.toThrow();
57-
58-
const func10 = () => {
59-
validator.checkTarget('android-automotive');
60-
};
61-
expect(func10).not.toThrow();
62-
63-
const func11 = () => {
64-
validator.checkTarget('android-automotive-playstore');
65-
};
66-
expect(func11).not.toThrow();
67-
68-
const func12 = () => {
69-
validator.checkTarget('android-desktop');
70-
};
71-
expect(func12).not.toThrow();
72-
});
73-
});
74-
754
describe('arch validator tests', () => {
765
it('Throws if arch is unknown', () => {
776
const func = () => {

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ inputs:
1212
description: 'API level of the system image - e.g. 34-ext10, 35-ext15. If not set the `api-level` input will be used.'
1313
required: false
1414
target:
15-
description: 'target of the system image - default, google_apis, google_apis_playstore, aosp_atd, google_atd, android-wear, android-wear-cn, android-tv, google-tv, android-automotive, android-automotive-playstore or android-desktop'
15+
description: 'target of the system image - e.g. default, google_apis, google_apis_ps16k, google_apis_playstore, google_apis_playstore_16k, aosp_atd, google_atd, android-wear, android-wear-cn, android-tv, google-tv, android-automotive, android-automotive-playstore or android-desktop'
1616
default: 'default'
1717
arch:
1818
description: 'CPU architecture of the system image - x86, x86_64 or arm64-v8a'

lib/input-validator.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
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.playstoreTargetSubstitution = exports.MAX_PORT = exports.MIN_PORT = exports.VALID_CHANNELS = exports.VALID_ARCHS = exports.MIN_API_LEVEL = void 0;
44
exports.MIN_API_LEVEL = 15;
5-
exports.VALID_TARGETS = [
6-
'default',
7-
'google_apis',
8-
'aosp_atd',
9-
'google_atd',
10-
'google_apis_playstore',
11-
'android-wear',
12-
'android-wear-cn',
13-
'android-tv',
14-
'google-tv',
15-
'android-automotive',
16-
'android-automotive-playstore',
17-
'android-desktop',
18-
];
195
exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a'];
206
exports.VALID_CHANNELS = ['stable', 'beta', 'dev', 'canary'];
217
exports.MIN_PORT = 5554;
228
exports.MAX_PORT = 5584;
23-
function checkTarget(target) {
24-
if (!exports.VALID_TARGETS.includes(target)) {
25-
throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${exports.VALID_TARGETS}.`);
26-
}
9+
function playstoreTargetSubstitution(target) {
10+
// "playstore" is an allowed shorthand for "google_apis_playstore" images
11+
// this is idempotent - return same even if run multiple times on same target
12+
if (target === 'playstore')
13+
return 'google_apis_playstore';
14+
if (target === 'playstore_ps16k')
15+
return 'google_apis_playstore_ps16k';
16+
return target;
2717
}
28-
exports.checkTarget = checkTarget;
18+
exports.playstoreTargetSubstitution = playstoreTargetSubstitution;
2919
function checkArch(arch) {
3020
if (!exports.VALID_ARCHS.includes(arch)) {
3121
throw new Error(`Value for input.arch '${arch}' is unknown. Supported options: ${exports.VALID_ARCHS}.`);

lib/main.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +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;
75-
(0, input_validator_1.checkTarget)(target);
73+
const target = (0, input_validator_1.playstoreTargetSubstitution)(core.getInput('target'));
7674
console.log(`target: ${target}`);
7775
// CPU architecture of the system image
7876
const arch = core.getInput('arch');

src/input-validator.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
export const MIN_API_LEVEL = 15;
2-
export const VALID_TARGETS: Array<string> = [
3-
'default',
4-
'google_apis',
5-
'aosp_atd',
6-
'google_atd',
7-
'google_apis_playstore',
8-
'android-wear',
9-
'android-wear-cn',
10-
'android-tv',
11-
'google-tv',
12-
'android-automotive',
13-
'android-automotive-playstore',
14-
'android-desktop',
15-
];
162
export const VALID_ARCHS: Array<string> = ['x86', 'x86_64', 'arm64-v8a'];
173
export const VALID_CHANNELS: Array<string> = ['stable', 'beta', 'dev', 'canary'];
184
export const MIN_PORT = 5554;
195
export const MAX_PORT = 5584;
206

21-
export function checkTarget(target: string): void {
22-
if (!VALID_TARGETS.includes(target)) {
23-
throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${VALID_TARGETS}.`);
24-
}
7+
export function playstoreTargetSubstitution(target: string): string {
8+
// "playstore" is an allowed shorthand for "google_apis_playstore" images
9+
// this is idempotent - return same even if run multiple times on same target
10+
if (target === 'playstore') return 'google_apis_playstore';
11+
if (target === 'playstore_ps16k') return 'google_apis_playstore_ps16k';
12+
return target;
2513
}
2614

2715
export function checkArch(arch: string): void {

src/main.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as core from '@actions/core';
22
import { installAndroidSdk } from './sdk-installer';
33
import {
4-
checkTarget,
54
checkArch,
65
checkDisableAnimations,
76
checkEmulatorBuild,
@@ -12,6 +11,7 @@ import {
1211
checkEnableHardwareKeyboard,
1312
checkDiskSize,
1413
checkPort,
14+
playstoreTargetSubstitution,
1515
MIN_PORT,
1616
} from './input-validator';
1717
import { createAvd, launchEmulator, killEmulator } from './emulator-manager';
@@ -52,9 +52,7 @@ async function run() {
5252
console.log(`System image API level: ${systemImageApiLevel}`);
5353

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

6058
// CPU architecture of the system image

0 commit comments

Comments
 (0)