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 91c409039..068501208 100644 --- a/__tests__/input-validator.test.ts +++ b/__tests__/input-validator.test.ts @@ -1,77 +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 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 = () => { 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..bcb4443f1 100644 --- a/lib/input-validator.js +++ b/lib/input-validator.js @@ -1,31 +1,21 @@ "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.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', - 'aosp_atd', - 'google_atd', - 'google_apis_playstore', - '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; exports.MAX_PORT = 5584; -function checkTarget(target) { - if (!exports.VALID_TARGETS.includes(target)) { - throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${exports.VALID_TARGETS}.`); - } +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.checkTarget = checkTarget; +exports.playstoreTargetSubstitution = playstoreTargetSubstitution; 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 fd352a44c..50e7a5090 100644 --- a/lib/main.js +++ b/lib/main.js @@ -70,9 +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; - (0, input_validator_1.checkTarget)(target); + const target = (0, input_validator_1.playstoreTargetSubstitution)(core.getInput('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 e88740543..2fd0c6237 100644 --- a/src/input-validator.ts +++ b/src/input-validator.ts @@ -1,27 +1,15 @@ export const MIN_API_LEVEL = 15; -export const VALID_TARGETS: Array = [ - 'default', - 'google_apis', - 'aosp_atd', - 'google_atd', - 'google_apis_playstore', - '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; export const MAX_PORT = 5584; -export function checkTarget(target: string): void { - if (!VALID_TARGETS.includes(target)) { - throw new Error(`Value for input.target '${target}' is unknown. Supported options: ${VALID_TARGETS}.`); - } +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 checkArch(arch: string): void { diff --git a/src/main.ts b/src/main.ts index df521a579..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, @@ -12,6 +11,7 @@ import { checkEnableHardwareKeyboard, checkDiskSize, checkPort, + playstoreTargetSubstitution, MIN_PORT, } from './input-validator'; import { createAvd, launchEmulator, killEmulator } from './emulator-manager'; @@ -52,9 +52,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; - checkTarget(target); + const target = playstoreTargetSubstitution(core.getInput('target')); console.log(`target: ${target}`); // CPU architecture of the system image