From e5aa8c74ac248733d65f2ae5fbd2e5438e491e33 Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Mon, 30 Jun 2025 09:34:13 -0500 Subject: [PATCH 1/3] test: remove target validator test these appear to have too much maintenance burden as they only ever add more over time --- __tests__/input-validator.test.ts | 63 ------------------------------- 1 file changed, 63 deletions(-) diff --git a/__tests__/input-validator.test.ts b/__tests__/input-validator.test.ts index 91c409039..d41434a96 100644 --- a/__tests__/input-validator.test.ts +++ b/__tests__/input-validator.test.ts @@ -9,69 +9,6 @@ describe('target validator tests', () => { expect(func).toThrowError(`Value for input.target 'some-target' is unknown. Supported options: ${validator.VALID_TARGETS}`); }); - it('Validates successfully with valid target', () => { - const func1 = () => { - validator.checkTarget('default'); - }; - expect(func1).not.toThrow(); - - const func2 = () => { - validator.checkTarget('google_apis'); - }; - expect(func2).not.toThrow(); - - const func3 = () => { - validator.checkTarget('aosp_atd'); - }; - expect(func3).not.toThrow(); - - const func4 = () => { - validator.checkTarget('google_atd'); - }; - expect(func4).not.toThrow(); - - const func5 = () => { - validator.checkTarget('google_apis_playstore'); - }; - expect(func5).not.toThrow(); - - const func6 = () => { - validator.checkTarget('android-wear'); - }; - expect(func6).not.toThrow(); - - const func7 = () => { - validator.checkTarget('android-wear-cn'); - }; - expect(func7).not.toThrow(); - - const func8 = () => { - validator.checkTarget('android-tv'); - }; - expect(func8).not.toThrow(); - - const func9 = () => { - validator.checkTarget('google-tv'); - }; - expect(func9).not.toThrow(); - - const func10 = () => { - validator.checkTarget('android-automotive'); - }; - expect(func10).not.toThrow(); - - const func11 = () => { - validator.checkTarget('android-automotive-playstore'); - }; - expect(func11).not.toThrow(); - - const func12 = () => { - validator.checkTarget('android-desktop'); - }; - expect(func12).not.toThrow(); - }); -}); - describe('arch validator tests', () => { it('Throws if arch is unknown', () => { const func = () => { From fddfc032bb363bbe0511bcfea79847bef870e7cd Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Wed, 25 Jun 2025 11:05:54 -0500 Subject: [PATCH 2/3] fix: allow google_apis_ps16k and google_apis_playstore_ps16k as valid targets Fixes #403 Co-authored-by: Yang --- README.md | 2 +- __tests__/input-validator.test.ts | 12 ++++++++++++ action.yml | 2 +- lib/input-validator.js | 16 ++++++++++++++-- lib/main.js | 3 +-- src/input-validator.ts | 12 +++++++++++- src/main.ts | 4 ++-- 7 files changed, 42 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index c0afc828a..0c2b60add 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ jobs: |-|-|-|-| | `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**. | | `system-image-api-level` | Optional | same as `api-level` | API level of the system image - e.g. `34-ext10`, `35-ext15`. | -| `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`. | +| `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. | | `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). | | `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`. | | `cores` | Optional | 2 | Number of cores to use for the emulator (`hw.cpu.ncore` in config.ini). | diff --git a/__tests__/input-validator.test.ts b/__tests__/input-validator.test.ts index d41434a96..ff08056bb 100644 --- a/__tests__/input-validator.test.ts +++ b/__tests__/input-validator.test.ts @@ -9,6 +9,18 @@ describe('target validator tests', () => { expect(func).toThrowError(`Value for input.target 'some-target' is unknown. Supported options: ${validator.VALID_TARGETS}`); }); + it('Validates successfully with playstore target shorthands', () => { + const func1 = () => { + validator.checkTarget('playstore'); + }; + expect(func1).not.toThrow(); + const func2 = () => { + validator.checkTarget('playstore_ps16k'); + }; + expect(func2).not.toThrow(); + }); +}); + describe('arch validator tests', () => { it('Throws if arch is unknown', () => { const func = () => { diff --git a/action.yml b/action.yml index 35dcccd62..30a20249e 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,7 @@ inputs: description: 'API level of the system image - e.g. 34-ext10, 35-ext15. If not set the `api-level` input will be used.' required: false target: - 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' + 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' default: 'default' arch: description: 'CPU architecture of the system image - x86, x86_64 or arm64-v8a' diff --git a/lib/input-validator.js b/lib/input-validator.js index 9960b46bb..cef1a4865 100644 --- a/lib/input-validator.js +++ b/lib/input-validator.js @@ -1,13 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -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; +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; exports.MIN_API_LEVEL = 15; exports.VALID_TARGETS = [ 'default', 'google_apis', + 'google_apis_ps16k', 'aosp_atd', 'google_atd', 'google_apis_playstore', + 'google_apis_playstore_ps16k', 'android-wear', 'android-wear-cn', 'android-tv', @@ -20,8 +22,18 @@ exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a']; exports.VALID_CHANNELS = ['stable', 'beta', 'dev', 'canary']; exports.MIN_PORT = 5554; exports.MAX_PORT = 5584; +function playstoreTargetSubstitution(target) { + // "playstore" is an allowed shorthand for "google_apis_playstore" images + // this is idempotent - return same even if run multiple times on same target + if (target === 'playstore') + return 'google_apis_playstore'; + if (target === 'playstore_ps16k') + return 'google_apis_playstore_ps16k'; + return target; +} +exports.playstoreTargetSubstitution = playstoreTargetSubstitution; function checkTarget(target) { - if (!exports.VALID_TARGETS.includes(target)) { + if (!exports.VALID_TARGETS.includes(playstoreTargetSubstitution(target))) { throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${exports.VALID_TARGETS}.`); } } diff --git a/lib/main.js b/lib/main.js index fd352a44c..d894dbdb1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -70,8 +70,7 @@ function run() { } console.log(`System image API level: ${systemImageApiLevel}`); // target of the system image - const targetInput = core.getInput('target'); - const target = targetInput == 'playstore' ? 'google_apis_playstore' : targetInput; + const target = (0, input_validator_1.playstoreTargetSubstitution)(core.getInput('target')); (0, input_validator_1.checkTarget)(target); console.log(`target: ${target}`); // CPU architecture of the system image diff --git a/src/input-validator.ts b/src/input-validator.ts index e88740543..91b0c01ab 100644 --- a/src/input-validator.ts +++ b/src/input-validator.ts @@ -2,9 +2,11 @@ export const MIN_API_LEVEL = 15; export const VALID_TARGETS: Array = [ 'default', 'google_apis', + 'google_apis_ps16k', 'aosp_atd', 'google_atd', 'google_apis_playstore', + 'google_apis_playstore_ps16k', 'android-wear', 'android-wear-cn', 'android-tv', @@ -18,8 +20,16 @@ export const VALID_CHANNELS: Array = ['stable', 'beta', 'dev', 'canary'] export const MIN_PORT = 5554; export const MAX_PORT = 5584; +export function playstoreTargetSubstitution(target: string): string { + // "playstore" is an allowed shorthand for "google_apis_playstore" images + // this is idempotent - return same even if run multiple times on same target + if (target === 'playstore') return 'google_apis_playstore'; + if (target === 'playstore_ps16k') return 'google_apis_playstore_ps16k'; + return target; +} + export function checkTarget(target: string): void { - if (!VALID_TARGETS.includes(target)) { + if (!VALID_TARGETS.includes(playstoreTargetSubstitution(target))) { throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${VALID_TARGETS}.`); } } diff --git a/src/main.ts b/src/main.ts index df521a579..e3b303bdf 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,6 +12,7 @@ import { checkEnableHardwareKeyboard, checkDiskSize, checkPort, + playstoreTargetSubstitution, MIN_PORT, } from './input-validator'; import { createAvd, launchEmulator, killEmulator } from './emulator-manager'; @@ -52,8 +53,7 @@ async function run() { console.log(`System image API level: ${systemImageApiLevel}`); // target of the system image - const targetInput = core.getInput('target'); - const target = targetInput == 'playstore' ? 'google_apis_playstore' : targetInput; + const target = playstoreTargetSubstitution(core.getInput('target')); checkTarget(target); console.log(`target: ${target}`); From 686d6bb8913064d4e46a8bd39586043ed89be6ea Mon Sep 17 00:00:00 2001 From: Mike Hardy Date: Mon, 30 Jun 2025 10:21:11 -0500 Subject: [PATCH 3/3] fix: remove target validation entirely, any valid sdkmanager target will work no longer requires code changes here to access new targets --- __tests__/input-validator.test.ts | 20 -------------------- lib/input-validator.js | 24 +----------------------- lib/main.js | 1 - src/input-validator.ts | 22 ---------------------- src/main.ts | 2 -- 5 files changed, 1 insertion(+), 68 deletions(-) diff --git a/__tests__/input-validator.test.ts b/__tests__/input-validator.test.ts index ff08056bb..068501208 100644 --- a/__tests__/input-validator.test.ts +++ b/__tests__/input-validator.test.ts @@ -1,26 +1,6 @@ import * as validator from '../src/input-validator'; import { MAX_PORT, MIN_PORT } from '../src/input-validator'; -describe('target validator tests', () => { - it('Throws if target is unknown', () => { - const func = () => { - validator.checkTarget('some-target'); - }; - expect(func).toThrowError(`Value for input.target 'some-target' is unknown. Supported options: ${validator.VALID_TARGETS}`); - }); - - it('Validates successfully with playstore target shorthands', () => { - const func1 = () => { - validator.checkTarget('playstore'); - }; - expect(func1).not.toThrow(); - const func2 = () => { - validator.checkTarget('playstore_ps16k'); - }; - expect(func2).not.toThrow(); - }); -}); - describe('arch validator tests', () => { it('Throws if arch is unknown', () => { const func = () => { diff --git a/lib/input-validator.js b/lib/input-validator.js index cef1a4865..bcb4443f1 100644 --- a/lib/input-validator.js +++ b/lib/input-validator.js @@ -1,23 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -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; +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; exports.MIN_API_LEVEL = 15; -exports.VALID_TARGETS = [ - 'default', - 'google_apis', - 'google_apis_ps16k', - 'aosp_atd', - 'google_atd', - 'google_apis_playstore', - 'google_apis_playstore_ps16k', - 'android-wear', - 'android-wear-cn', - 'android-tv', - 'google-tv', - 'android-automotive', - 'android-automotive-playstore', - 'android-desktop', -]; exports.VALID_ARCHS = ['x86', 'x86_64', 'arm64-v8a']; exports.VALID_CHANNELS = ['stable', 'beta', 'dev', 'canary']; exports.MIN_PORT = 5554; @@ -32,12 +16,6 @@ function playstoreTargetSubstitution(target) { return target; } exports.playstoreTargetSubstitution = playstoreTargetSubstitution; -function checkTarget(target) { - if (!exports.VALID_TARGETS.includes(playstoreTargetSubstitution(target))) { - throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${exports.VALID_TARGETS}.`); - } -} -exports.checkTarget = checkTarget; function checkArch(arch) { if (!exports.VALID_ARCHS.includes(arch)) { throw new Error(`Value for input.arch '${arch}' is unknown. Supported options: ${exports.VALID_ARCHS}.`); diff --git a/lib/main.js b/lib/main.js index d894dbdb1..50e7a5090 100644 --- a/lib/main.js +++ b/lib/main.js @@ -71,7 +71,6 @@ function run() { console.log(`System image API level: ${systemImageApiLevel}`); // target of the system image const target = (0, input_validator_1.playstoreTargetSubstitution)(core.getInput('target')); - (0, input_validator_1.checkTarget)(target); console.log(`target: ${target}`); // CPU architecture of the system image const arch = core.getInput('arch'); diff --git a/src/input-validator.ts b/src/input-validator.ts index 91b0c01ab..2fd0c6237 100644 --- a/src/input-validator.ts +++ b/src/input-validator.ts @@ -1,20 +1,4 @@ export const MIN_API_LEVEL = 15; -export const VALID_TARGETS: Array = [ - 'default', - 'google_apis', - 'google_apis_ps16k', - 'aosp_atd', - 'google_atd', - 'google_apis_playstore', - 'google_apis_playstore_ps16k', - 'android-wear', - 'android-wear-cn', - 'android-tv', - 'google-tv', - 'android-automotive', - 'android-automotive-playstore', - 'android-desktop', -]; export const VALID_ARCHS: Array = ['x86', 'x86_64', 'arm64-v8a']; export const VALID_CHANNELS: Array = ['stable', 'beta', 'dev', 'canary']; export const MIN_PORT = 5554; @@ -28,12 +12,6 @@ export function playstoreTargetSubstitution(target: string): string { return target; } -export function checkTarget(target: string): void { - if (!VALID_TARGETS.includes(playstoreTargetSubstitution(target))) { - throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${VALID_TARGETS}.`); - } -} - export function checkArch(arch: string): void { if (!VALID_ARCHS.includes(arch)) { throw new Error(`Value for input.arch '${arch}' is unknown. Supported options: ${VALID_ARCHS}.`); diff --git a/src/main.ts b/src/main.ts index e3b303bdf..8562dbcd0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,7 +1,6 @@ import * as core from '@actions/core'; import { installAndroidSdk } from './sdk-installer'; import { - checkTarget, checkArch, checkDisableAnimations, checkEmulatorBuild, @@ -54,7 +53,6 @@ async function run() { // target of the system image const target = playstoreTargetSubstitution(core.getInput('target')); - checkTarget(target); console.log(`target: ${target}`); // CPU architecture of the system image