mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-08-31 17:49:33 +00:00
Add option to disable spellcheck
Add input-validator and tests
This commit is contained in:
@@ -97,6 +97,7 @@ jobs:
|
||||
| `avd-name` | Optional | `test` | Custom AVD name used for creating the Android Virtual Device. |
|
||||
| `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`. |
|
||||
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
|
||||
| `disable-spellchecker` | Optional | `false` | Whether to disable spellchecker - `true` or `false`. |
|
||||
| `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. |
|
||||
| `working-directory` | Optional | `./` | A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository. |
|
||||
| `ndk` | Optional | N/A | Version of NDK to install - e.g. `21.0.6113669` |
|
||||
|
||||
@@ -103,6 +103,27 @@ describe('disable-animations validator tests', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('disable-spellchecker validator tests', () => {
|
||||
it('Throws if disable-spellchecker is not a boolean', () => {
|
||||
const func = () => {
|
||||
validator.checkDisableSpellchecker('yes');
|
||||
};
|
||||
expect(func).toThrowError(`Input for input.disable-spellchecker should be either 'true' or 'false'.`);
|
||||
});
|
||||
|
||||
it('Validates successfully if disable-spellchecker is either true or false', () => {
|
||||
const func1 = () => {
|
||||
validator.checkDisableSpellchecker('true');
|
||||
};
|
||||
expect(func1).not.toThrow();
|
||||
|
||||
const func2 = () => {
|
||||
validator.checkDisableSpellchecker('false');
|
||||
};
|
||||
expect(func2).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('emulator-build validator tests', () => {
|
||||
it('Throws if emulator-build is not a number', () => {
|
||||
const func = () => {
|
||||
|
||||
@@ -30,6 +30,9 @@ inputs:
|
||||
disable-animations:
|
||||
description: 'whether to disable animations - true or false'
|
||||
default: 'true'
|
||||
disable-spellchecker:
|
||||
description: Whether to disable spellchecker - `true` or `false`.
|
||||
default: 'false'
|
||||
emulator-build:
|
||||
description: 'build number of a specific version of the emulator binary to use - e.g. `6061023` for emulator v29.3.0.0'
|
||||
working-directory:
|
||||
|
||||
@@ -34,7 +34,7 @@ const EMULATOR_BOOT_TIMEOUT_SECONDS = 600;
|
||||
/**
|
||||
* Creates and launches a new AVD instance with the specified configurations.
|
||||
*/
|
||||
function launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations) {
|
||||
function launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellChecker) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// create a new AVD
|
||||
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
|
||||
@@ -69,6 +69,9 @@ function launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize
|
||||
yield exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
|
||||
yield exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
|
||||
}
|
||||
if (disableSpellChecker) {
|
||||
yield exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.launchEmulator = launchEmulator;
|
||||
|
||||
+11
-2
@@ -1,6 +1,6 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.checkEmulatorBuild = exports.checkDisableAnimations = exports.checkArch = exports.checkTarget = exports.checkApiLevel = exports.VALID_ARCHS = exports.VALID_TARGETS = exports.MIN_API_LEVEL = void 0;
|
||||
exports.checkEmulatorBuild = exports.checkDisableSpellchecker = exports.checkDisableAnimations = exports.checkArch = exports.checkTarget = exports.checkApiLevel = 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_playstore'];
|
||||
exports.VALID_ARCHS = ['x86', 'x86_64'];
|
||||
@@ -26,14 +26,23 @@ function checkArch(arch) {
|
||||
}
|
||||
exports.checkArch = checkArch;
|
||||
function checkDisableAnimations(disableAnimations) {
|
||||
if (disableAnimations !== 'true' && disableAnimations !== 'false') {
|
||||
if (!isValidBoolean(disableAnimations)) {
|
||||
throw new Error(`Input for input.disable-animations should be either 'true' or 'false'.`);
|
||||
}
|
||||
}
|
||||
exports.checkDisableAnimations = checkDisableAnimations;
|
||||
function checkDisableSpellchecker(disableSpellchecker) {
|
||||
if (!isValidBoolean(disableSpellchecker)) {
|
||||
throw new Error(`Input for input.disable-spellchecker should be either 'true' or 'false'.`);
|
||||
}
|
||||
}
|
||||
exports.checkDisableSpellchecker = checkDisableSpellchecker;
|
||||
function checkEmulatorBuild(emulatorBuild) {
|
||||
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
|
||||
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
|
||||
}
|
||||
}
|
||||
exports.checkEmulatorBuild = checkEmulatorBuild;
|
||||
function isValidBoolean(value) {
|
||||
return value === 'true' || value === 'false';
|
||||
}
|
||||
|
||||
+7
-2
@@ -80,6 +80,11 @@ function run() {
|
||||
input_validator_1.checkDisableAnimations(disableAnimationsInput);
|
||||
const disableAnimations = disableAnimationsInput === 'true';
|
||||
console.log(`disable animations: ${disableAnimations}`);
|
||||
// disable spellchecker
|
||||
const disableSpellcheckerInput = core.getInput('disable-spellchecker');
|
||||
input_validator_1.checkDisableSpellchecker(disableSpellcheckerInput);
|
||||
const disableSpellchecker = disableSpellcheckerInput === 'true';
|
||||
console.log(`disable spellchecker: ${disableSpellchecker}`);
|
||||
// emulator build
|
||||
const emulatorBuildInput = core.getInput('emulator-build');
|
||||
if (emulatorBuildInput) {
|
||||
@@ -115,7 +120,7 @@ function run() {
|
||||
// install SDK
|
||||
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
|
||||
// launch an emulator
|
||||
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
|
||||
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker);
|
||||
// execute the custom script
|
||||
try {
|
||||
// move to custom working directory if set
|
||||
@@ -126,7 +131,7 @@ function run() {
|
||||
// use array form to avoid various quote escaping problems
|
||||
// caused by exec(`sh -c "${script}"`)
|
||||
yield exec.exec('sh', ['-c', script]);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
||||
@@ -14,7 +14,8 @@ export async function launchEmulator(
|
||||
sdcardPathOrSize: string,
|
||||
avdName: string,
|
||||
emulatorOptions: string,
|
||||
disableAnimations: boolean
|
||||
disableAnimations: boolean,
|
||||
disableSpellChecker: boolean
|
||||
): Promise<void> {
|
||||
// create a new AVD
|
||||
const profileOption = profile.trim() !== '' ? `--device '${profile}'` : '';
|
||||
@@ -57,6 +58,9 @@ export async function launchEmulator(
|
||||
await exec.exec(`adb shell settings put global transition_animation_scale 0.0`);
|
||||
await exec.exec(`adb shell settings put global animator_duration_scale 0.0`);
|
||||
}
|
||||
if (disableSpellChecker) {
|
||||
await exec.exec(`adb shell settings put secure spell_checker_enabled 0`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+11
-1
@@ -24,13 +24,23 @@ export function checkArch(arch: string): void {
|
||||
}
|
||||
|
||||
export function checkDisableAnimations(disableAnimations: string): void {
|
||||
if (disableAnimations !== 'true' && disableAnimations !== 'false') {
|
||||
if (!isValidBoolean(disableAnimations)) {
|
||||
throw new Error(`Input for input.disable-animations should be either 'true' or 'false'.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function checkDisableSpellchecker(disableSpellchecker: string): void {
|
||||
if (!isValidBoolean(disableSpellchecker)) {
|
||||
throw new Error(`Input for input.disable-spellchecker should be either 'true' or 'false'.`);
|
||||
}
|
||||
}
|
||||
|
||||
export function checkEmulatorBuild(emulatorBuild: string): void {
|
||||
if (isNaN(Number(emulatorBuild)) || !Number.isInteger(Number(emulatorBuild))) {
|
||||
throw new Error(`Unexpected emulator build: '${emulatorBuild}'.`);
|
||||
}
|
||||
}
|
||||
|
||||
function isValidBoolean(value: string): boolean {
|
||||
return value === 'true' || value === 'false';
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core';
|
||||
import { installAndroidSdk } from './sdk-installer';
|
||||
import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmulatorBuild } from './input-validator';
|
||||
import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmulatorBuild, checkDisableSpellchecker } from './input-validator';
|
||||
import { launchEmulator, killEmulator } from './emulator-manager';
|
||||
import * as exec from '@actions/exec';
|
||||
import { parseScript } from './script-parser';
|
||||
@@ -61,6 +61,12 @@ async function run() {
|
||||
const disableAnimations = disableAnimationsInput === 'true';
|
||||
console.log(`disable animations: ${disableAnimations}`);
|
||||
|
||||
// disable spellchecker
|
||||
const disableSpellcheckerInput = core.getInput('disable-spellchecker');
|
||||
checkDisableSpellchecker(disableSpellcheckerInput);
|
||||
const disableSpellchecker = disableSpellcheckerInput === 'true';
|
||||
console.log(`disable spellchecker: ${disableSpellchecker}`);
|
||||
|
||||
// emulator build
|
||||
const emulatorBuildInput = core.getInput('emulator-build');
|
||||
if (emulatorBuildInput) {
|
||||
@@ -102,7 +108,7 @@ async function run() {
|
||||
await installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
|
||||
|
||||
// launch an emulator
|
||||
await launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations);
|
||||
await launchEmulator(apiLevel, target, arch, profile, cores, sdcardPathOrSize, avdName, emulatorOptions, disableAnimations, disableSpellchecker);
|
||||
|
||||
// execute the custom script
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user