mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-08-31 17:49:33 +00:00
Add support for configuring hardware profile and running custom script.
This commit is contained in:
@@ -8,7 +8,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: macOS-latest
|
runs-on: macOS-latest
|
||||||
timeout-minutes: 20
|
timeout-minutes: 10
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
api-level: [21, 23, 29]
|
api-level: [21, 23, 29]
|
||||||
@@ -27,9 +27,13 @@ jobs:
|
|||||||
|
|
||||||
- name: run action
|
- name: run action
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
api-level: ${{ matrix.api-level }}
|
api-level: ${{ matrix.api-level }}
|
||||||
target: default
|
target: default
|
||||||
abi: x86
|
arch: x86
|
||||||
|
profile: Nexus 6
|
||||||
headless: true
|
headless: true
|
||||||
disable-animations: true
|
disable-animations: true
|
||||||
|
script: |
|
||||||
|
adb devices -l
|
||||||
|
adb --help
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ This action must be run on a **macOS** VM, e.g. `macOS-latest` or `macOS-10.14`.
|
|||||||
## Configurations
|
## Configurations
|
||||||
|
|
||||||
| | **Required** | **Default** | **Description** |
|
| | **Required** | **Default** | **Description** |
|
||||||
|----------------------|--------------|-------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|----------------------|--------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||||
| `api-level` | Required | N/A | API level of the platform system image - e.g. 23 for Android Marshmallow, 29 for Android 10. **Minimum API level supported is 21**. |
|
| `api-level` | Required | N/A | API level of the platform system image - e.g. 23 for Android Marshmallow, 29 for Android 10. **Minimum API level supported is 21**. |
|
||||||
| `target` | Optional | `default` | Target of the system image - `default` or `google_apis`. |
|
| `target` | Optional | `default` | Target of the system image - `default` or `google_apis`. |
|
||||||
| `abi` | Optional | `x86` | CPU / ABI of the system image - `x86` or `x86_64`. |
|
| `arch` | Optional | `x86` | CPU architecture of the system image - `x86` or `x86_64`. |
|
||||||
|
| `profile` | Optional | N/A | Hardware profile used for creating the AVD - e.g. `Nexus 6`. For a list of all profiles available, run `$ANDROID_HOME/tools/bin/avdmanager list` and refer to the results under "Available Android Virtual Devices". |
|
||||||
| `headless` | Optional | `true` | Whether to launch emulator without UI - `true` or `false`. When set to `true` this is equivalent to running the emulator with `emulator -no-window`. |
|
| `headless` | Optional | `true` | Whether to launch emulator without UI - `true` or `false`. When set to `true` this is equivalent to running the emulator with `emulator -no-window`. |
|
||||||
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
|
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
|
||||||
|
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` |
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
|
|||||||
@@ -56,22 +56,22 @@ describe('target validator tests', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('abi validator tests', () => {
|
describe('arch validator tests', () => {
|
||||||
it('Throws if abi is unknown', () => {
|
it('Throws if arch is unknown', () => {
|
||||||
const func = () => {
|
const func = () => {
|
||||||
validator.checkAbi('some-abi');
|
validator.checkArch('some-arch');
|
||||||
};
|
};
|
||||||
expect(func).toThrowError(`Value for input.abi 'some-abi' is unknown. Supported options: ${validator.VALID_ABIS}`);
|
expect(func).toThrowError(`Value for input.arch 'some-arch' is unknown. Supported options: ${validator.VALID_ARCHS}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Validates successfully with valid abi', () => {
|
it('Validates successfully with valid arch', () => {
|
||||||
const func1 = () => {
|
const func1 = () => {
|
||||||
validator.checkAbi('x86');
|
validator.checkArch('x86');
|
||||||
};
|
};
|
||||||
expect(func1).not.toThrow();
|
expect(func1).not.toThrow();
|
||||||
|
|
||||||
const func2 = () => {
|
const func2 = () => {
|
||||||
validator.checkAbi('x86_64');
|
validator.checkArch('x86_64');
|
||||||
};
|
};
|
||||||
expect(func2).not.toThrow();
|
expect(func2).not.toThrow();
|
||||||
});
|
});
|
||||||
|
|||||||
+7
-2
@@ -11,15 +11,20 @@ inputs:
|
|||||||
target:
|
target:
|
||||||
description: 'target of the system image - default or google_apis'
|
description: 'target of the system image - default or google_apis'
|
||||||
default: 'default'
|
default: 'default'
|
||||||
abi:
|
arch:
|
||||||
description: 'CPU / ABI of the system image - x86 or x86_64'
|
description: 'CPU architecture of the system image - x86 or x86_64'
|
||||||
default: 'x86'
|
default: 'x86'
|
||||||
|
profile:
|
||||||
|
description: 'Hardware profile used for creating the AVD - e.g. `Nexus 6`.'
|
||||||
headless:
|
headless:
|
||||||
description: 'whether to launch emulator in without UI - true or false'
|
description: 'whether to launch emulator in without UI - true or false'
|
||||||
default: 'true'
|
default: 'true'
|
||||||
disable-animations:
|
disable-animations:
|
||||||
description: 'whether to disable animations - true or false'
|
description: 'whether to disable animations - true or false'
|
||||||
default: 'true'
|
default: 'true'
|
||||||
|
script:
|
||||||
|
description: 'custom script to run - e.g. `./gradlew connectedCheck`'
|
||||||
|
required: true
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'lib/main.js'
|
main: 'lib/main.js'
|
||||||
|
|||||||
@@ -17,35 +17,53 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const exec = __importStar(require("@actions/exec"));
|
const exec = __importStar(require("@actions/exec"));
|
||||||
const EMULATOR_BOOT_TIMEOUT_SECONDS = 120;
|
const EMULATOR_BOOT_TIMEOUT_SECONDS = 120;
|
||||||
|
const AVD_MANAGER_PATH = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
|
||||||
|
const ADB_PATH = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
||||||
/**
|
/**
|
||||||
* Creates and launches a new AVD instance with the specified configurations.
|
* Creates and launches a new AVD instance with the specified configurations.
|
||||||
*/
|
*/
|
||||||
function launchEmulator(apiLevel, target, abi, device, headless, disableAnimations) {
|
function launchEmulator(apiLevel, target, arch, profile, headless, disableAnimations) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const avdmangerPath = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
|
|
||||||
const adbPath = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
|
||||||
// create a new AVD
|
// create a new AVD
|
||||||
console.log('Creating AVD.');
|
if (profile.trim() !== '') {
|
||||||
yield exec.exec(`${avdmangerPath} create avd -n test --force --abi "${target}/${abi}" --package "system-images;android-${apiLevel};${target};${abi}" --device "${device}"`);
|
console.log(`Creating AVD with custom profile ${profile}`);
|
||||||
|
yield exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.log(`Creating AVD without custom profile.`);
|
||||||
|
yield exec.exec(`echo "no" | ${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}"`);
|
||||||
|
}
|
||||||
// start emulator
|
// start emulator
|
||||||
console.log('Starting emulator.');
|
console.log('Starting emulator.');
|
||||||
const noWindow = headless ? '-no-window' : '';
|
const noWindow = headless ? '-no-window' : '';
|
||||||
yield exec.exec(`bash -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${noWindow} -no-snapshot -noaudio -no-boot-anim &"`);
|
yield exec.exec(`bash -c \\"${process.env.ANDROID_HOME}/emulator/emulator -avd test ${noWindow} -no-snapshot -noaudio -no-boot-anim &"`);
|
||||||
// wait for emulator to complete booting
|
// wait for emulator to complete booting
|
||||||
yield waitForDevice();
|
yield waitForDevice();
|
||||||
yield exec.exec(`${adbPath} shell input keyevent 82`);
|
yield exec.exec(`${ADB_PATH} shell input keyevent 82`);
|
||||||
// disable animations
|
// disable animations
|
||||||
if (disableAnimations) {
|
if (disableAnimations) {
|
||||||
console.log('Disabling animations.');
|
console.log('Disabling animations.');
|
||||||
yield exec.exec(`${adbPath} shell settings put global window_animation_scale 0.0`);
|
yield exec.exec(`${ADB_PATH} shell settings put global window_animation_scale 0.0`);
|
||||||
yield exec.exec(`${adbPath} shell settings put global transition_animation_scale 0.0`);
|
yield exec.exec(`${ADB_PATH} shell settings put global transition_animation_scale 0.0`);
|
||||||
yield exec.exec(`${adbPath} shell settings put global animator_duration_scale 0.0`);
|
yield exec.exec(`${ADB_PATH} shell settings put global animator_duration_scale 0.0`);
|
||||||
}
|
}
|
||||||
// kill emulator
|
|
||||||
yield exec.exec(`${adbPath} -s emulator-5554 emu kill`);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.launchEmulator = launchEmulator;
|
exports.launchEmulator = launchEmulator;
|
||||||
|
/**
|
||||||
|
* Kills the running emulator on the defaut port.
|
||||||
|
*/
|
||||||
|
function killEmulator() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
try {
|
||||||
|
yield exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log('No emulator running on port 5554');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
exports.killEmulator = killEmulator;
|
||||||
/**
|
/**
|
||||||
* Wait for emulator to boot.
|
* Wait for emulator to boot.
|
||||||
*/
|
*/
|
||||||
@@ -72,8 +90,8 @@ function waitForDevice() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (error) {
|
||||||
console.error(e.message);
|
console.error(error.message);
|
||||||
}
|
}
|
||||||
if (attempts < maxAttemps) {
|
if (attempts < maxAttemps) {
|
||||||
yield delay(retryInterval * 1000);
|
yield delay(retryInterval * 1000);
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.MIN_API_LEVEL = 21;
|
exports.MIN_API_LEVEL = 21;
|
||||||
exports.VALID_TARGETS = ['default', 'google_apis'];
|
exports.VALID_TARGETS = ['default', 'google_apis'];
|
||||||
exports.VALID_ABIS = ['x86', 'x86_64'];
|
exports.VALID_ARCHS = ['x86', 'x86_64'];
|
||||||
function checkApiLevel(apiLevel) {
|
function checkApiLevel(apiLevel) {
|
||||||
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
|
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
|
||||||
throw new Error(`Unexpected API level: '${apiLevel}'.`);
|
throw new Error(`Unexpected API level: '${apiLevel}'.`);
|
||||||
@@ -18,12 +18,12 @@ function checkTarget(target) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.checkTarget = checkTarget;
|
exports.checkTarget = checkTarget;
|
||||||
function checkAbi(abi) {
|
function checkArch(arch) {
|
||||||
if (!exports.VALID_ABIS.includes(abi)) {
|
if (!exports.VALID_ARCHS.includes(arch)) {
|
||||||
throw new Error(`Value for input.abi '${abi}' is unknown. Supported options: ${exports.VALID_ABIS}.`);
|
throw new Error(`Value for input.arch '${arch}' is unknown. Supported options: ${exports.VALID_ARCHS}.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.checkAbi = checkAbi;
|
exports.checkArch = checkArch;
|
||||||
function checkHeadless(headless) {
|
function checkHeadless(headless) {
|
||||||
if (headless !== 'true' && headless !== 'false') {
|
if (headless !== 'true' && headless !== 'false') {
|
||||||
throw new Error(`Input for input.headless should be either 'true' or 'false'.`);
|
throw new Error(`Input for input.headless should be either 'true' or 'false'.`);
|
||||||
|
|||||||
+20
-11
@@ -18,7 +18,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const sdk_installer_1 = require("./sdk-installer");
|
const sdk_installer_1 = require("./sdk-installer");
|
||||||
const input_validator_1 = require("./input-validator");
|
const input_validator_1 = require("./input-validator");
|
||||||
const emulator_launcher_1 = require("./emulator-launcher");
|
const emulator_manager_1 = require("./emulator-manager");
|
||||||
|
const exec = __importStar(require("@actions/exec"));
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
@@ -35,10 +36,13 @@ function run() {
|
|||||||
const target = core.getInput('target');
|
const target = core.getInput('target');
|
||||||
input_validator_1.checkTarget(target);
|
input_validator_1.checkTarget(target);
|
||||||
console.log(`target: ${target}`);
|
console.log(`target: ${target}`);
|
||||||
// CPU / ABI of the system image
|
// CPU architecture of the system image
|
||||||
const abi = core.getInput('abi');
|
const arch = core.getInput('arch');
|
||||||
input_validator_1.checkAbi(abi);
|
input_validator_1.checkArch(arch);
|
||||||
console.log(`cpu/abi: ${abi}`);
|
console.log(`CPI architecture: ${arch}`);
|
||||||
|
// Hardware profile used for creating the AVD
|
||||||
|
const profile = core.getInput('profile');
|
||||||
|
console.log(`Hardware profile: ${profile}`);
|
||||||
// headless mode
|
// headless mode
|
||||||
const headlessInput = core.getInput('headless');
|
const headlessInput = core.getInput('headless');
|
||||||
input_validator_1.checkHeadless(headlessInput);
|
input_validator_1.checkHeadless(headlessInput);
|
||||||
@@ -49,15 +53,20 @@ function run() {
|
|||||||
input_validator_1.checkDisableAnimations(disableAnimationsInput);
|
input_validator_1.checkDisableAnimations(disableAnimationsInput);
|
||||||
const disableAnimations = disableAnimationsInput === 'true';
|
const disableAnimations = disableAnimationsInput === 'true';
|
||||||
console.log(`disable animations: ${disableAnimations}`);
|
console.log(`disable animations: ${disableAnimations}`);
|
||||||
|
// custom scrpt to run
|
||||||
|
const script = core.getInput('script', { required: true });
|
||||||
// install SDK
|
// install SDK
|
||||||
yield sdk_installer_1.installAndroidSdk(apiLevel, target, abi);
|
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch);
|
||||||
// launch emulator
|
// launch an emulator
|
||||||
// TODO get from input (source list of all profiles)
|
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, headless, disableAnimations);
|
||||||
const device = 'Nexus 6P';
|
// execute the custom script
|
||||||
yield emulator_launcher_1.launchEmulator(apiLevel, target, abi, device, headless, disableAnimations);
|
yield exec.exec(`${script}`);
|
||||||
// TODO start emulator
|
// finally kill the emulator
|
||||||
|
yield emulator_manager_1.killEmulator();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
// kill the emulator so the action can exit
|
||||||
|
yield emulator_manager_1.killEmulator();
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -18,12 +18,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|||||||
const exec = __importStar(require("@actions/exec"));
|
const exec = __importStar(require("@actions/exec"));
|
||||||
const tc = __importStar(require("@actions/tool-cache"));
|
const tc = __importStar(require("@actions/tool-cache"));
|
||||||
const fs = __importStar(require("fs"));
|
const fs = __importStar(require("fs"));
|
||||||
|
const BUILD_TOOLS_VERSION = '29.0.2';
|
||||||
const SDK_URL = 'https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip';
|
const SDK_URL = 'https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip';
|
||||||
/**
|
/**
|
||||||
* Downloads and installs the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
|
* Downloads and installs the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
|
||||||
* and the system image for the chosen API level, cpu/abi, and target.
|
* and the system image for the chosen API level, CPU arch, and target.
|
||||||
*/
|
*/
|
||||||
function installAndroidSdk(apiLevel, target, abi) {
|
function installAndroidSdk(apiLevel, target, arch) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// download Android SDK if not already installed
|
// download Android SDK if not already installed
|
||||||
if (fs.existsSync(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager`)) {
|
if (fs.existsSync(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager`)) {
|
||||||
@@ -38,8 +39,9 @@ function installAndroidSdk(apiLevel, target, abi) {
|
|||||||
console.log('Installing build tools, platform tools, platform and system image.');
|
console.log('Installing build tools, platform tools, platform and system image.');
|
||||||
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
||||||
yield exec.exec(`echo "y" | ${sdkmangerPath} --licenses > /dev/null`);
|
yield exec.exec(`echo "y" | ${sdkmangerPath} --licenses > /dev/null`);
|
||||||
yield exec.exec(`${sdkmangerPath} tools platform-tools "platforms;android-${apiLevel}"`);
|
yield exec.exec(`${sdkmangerPath} "build-tools;${BUILD_TOOLS_VERSION}"`);
|
||||||
yield exec.exec(`${sdkmangerPath} "system-images;android-${apiLevel};${target};${abi}"`);
|
yield exec.exec(`${sdkmangerPath} platform-tools "platforms;android-${apiLevel}"`);
|
||||||
|
yield exec.exec(`${sdkmangerPath} "system-images;android-${apiLevel};${target};${arch}"`);
|
||||||
yield exec.exec(`bash -c \\"${sdkmangerPath} --update > /dev/null"`);
|
yield exec.exec(`bash -c \\"${sdkmangerPath} --update > /dev/null"`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
const EMULATOR_BOOT_TIMEOUT_SECONDS = 120;
|
const EMULATOR_BOOT_TIMEOUT_SECONDS = 120;
|
||||||
|
const AVD_MANAGER_PATH = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
|
||||||
|
const ADB_PATH = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and launches a new AVD instance with the specified configurations.
|
* Creates and launches a new AVD instance with the specified configurations.
|
||||||
*/
|
*/
|
||||||
export async function launchEmulator(apiLevel: number, target: string, abi: string, device: string, headless: boolean, disableAnimations: boolean): Promise<void> {
|
export async function launchEmulator(apiLevel: number, target: string, arch: string, profile: string, headless: boolean, disableAnimations: boolean): Promise<void> {
|
||||||
const avdmangerPath = `${process.env.ANDROID_HOME}/tools/bin/avdmanager`;
|
|
||||||
const adbPath = `${process.env.ANDROID_HOME}/platform-tools/adb`;
|
|
||||||
|
|
||||||
// create a new AVD
|
// create a new AVD
|
||||||
console.log('Creating AVD.');
|
if (profile.trim() !== '') {
|
||||||
await exec.exec(`${avdmangerPath} create avd -n test --force --abi "${target}/${abi}" --package "system-images;android-${apiLevel};${target};${abi}" --device "${device}"`);
|
console.log(`Creating AVD with custom profile ${profile}`);
|
||||||
|
await exec.exec(`${AVD_MANAGER_PATH} create avd --force -n test --abi "${target}/${arch}" --package "system-images;android-${apiLevel};${target};${arch}" --device "${profile}"`);
|
||||||
|
} else {
|
||||||
|
console.log(`Creating AVD without custom profile.`);
|
||||||
|
await exec.exec(`bash -c \\"echo no | ${AVD_MANAGER_PATH} create avd --force -n test --abi '${target}/${arch}' --package 'system-images;android-${apiLevel};${target};${arch}'`);
|
||||||
|
}
|
||||||
|
|
||||||
// start emulator
|
// start emulator
|
||||||
console.log('Starting emulator.');
|
console.log('Starting emulator.');
|
||||||
@@ -20,18 +24,26 @@ export async function launchEmulator(apiLevel: number, target: string, abi: stri
|
|||||||
|
|
||||||
// wait for emulator to complete booting
|
// wait for emulator to complete booting
|
||||||
await waitForDevice();
|
await waitForDevice();
|
||||||
await exec.exec(`${adbPath} shell input keyevent 82`);
|
await exec.exec(`${ADB_PATH} shell input keyevent 82`);
|
||||||
|
|
||||||
// disable animations
|
// disable animations
|
||||||
if (disableAnimations) {
|
if (disableAnimations) {
|
||||||
console.log('Disabling animations.');
|
console.log('Disabling animations.');
|
||||||
await exec.exec(`${adbPath} shell settings put global window_animation_scale 0.0`);
|
await exec.exec(`${ADB_PATH} shell settings put global window_animation_scale 0.0`);
|
||||||
await exec.exec(`${adbPath} shell settings put global transition_animation_scale 0.0`);
|
await exec.exec(`${ADB_PATH} shell settings put global transition_animation_scale 0.0`);
|
||||||
await exec.exec(`${adbPath} shell settings put global animator_duration_scale 0.0`);
|
await exec.exec(`${ADB_PATH} shell settings put global animator_duration_scale 0.0`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// kill emulator
|
/**
|
||||||
await exec.exec(`${adbPath} -s emulator-5554 emu kill`);
|
* Kills the running emulator on the defaut port.
|
||||||
|
*/
|
||||||
|
export async function killEmulator(): Promise<void> {
|
||||||
|
try {
|
||||||
|
await exec.exec(`${ADB_PATH} -s emulator-5554 emu kill`);
|
||||||
|
} catch (error) {
|
||||||
|
console.log('No emulator running on port 5554');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,8 +70,8 @@ async function waitForDevice(): Promise<void> {
|
|||||||
booted = true;
|
booted = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (error) {
|
||||||
console.error(e.message);
|
console.error(error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attempts < maxAttemps) {
|
if (attempts < maxAttemps) {
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
export const MIN_API_LEVEL = 21;
|
export const MIN_API_LEVEL = 21;
|
||||||
export const VALID_TARGETS: Array<string> = ['default', 'google_apis'];
|
export const VALID_TARGETS: Array<string> = ['default', 'google_apis'];
|
||||||
export const VALID_ABIS: Array<string> = ['x86', 'x86_64'];
|
export const VALID_ARCHS: Array<string> = ['x86', 'x86_64'];
|
||||||
|
|
||||||
export function checkApiLevel(apiLevel: string): void {
|
export function checkApiLevel(apiLevel: string): void {
|
||||||
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
|
if (isNaN(Number(apiLevel)) || !Number.isInteger(Number(apiLevel))) {
|
||||||
@@ -17,9 +17,9 @@ export function checkTarget(target: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function checkAbi(abi: string): void {
|
export function checkArch(arch: string): void {
|
||||||
if (!VALID_ABIS.includes(abi)) {
|
if (!VALID_ARCHS.includes(arch)) {
|
||||||
throw new Error(`Value for input.abi '${abi}' is unknown. Supported options: ${VALID_ABIS}.`);
|
throw new Error(`Value for input.arch '${arch}' is unknown. Supported options: ${VALID_ARCHS}.`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+27
-12
@@ -1,7 +1,8 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { installAndroidSdk } from './sdk-installer';
|
import { installAndroidSdk } from './sdk-installer';
|
||||||
import { checkApiLevel, checkTarget, checkAbi, checkHeadless, checkDisableAnimations } from './input-validator';
|
import { checkApiLevel, checkTarget, checkArch, checkHeadless, checkDisableAnimations } from './input-validator';
|
||||||
import { launchEmulator } from './emulator-launcher';
|
import { launchEmulator, killEmulator } from './emulator-manager';
|
||||||
|
import * as exec from '@actions/exec';
|
||||||
|
|
||||||
async function run() {
|
async function run() {
|
||||||
try {
|
try {
|
||||||
@@ -21,10 +22,14 @@ async function run() {
|
|||||||
checkTarget(target);
|
checkTarget(target);
|
||||||
console.log(`target: ${target}`);
|
console.log(`target: ${target}`);
|
||||||
|
|
||||||
// CPU / ABI of the system image
|
// CPU architecture of the system image
|
||||||
const abi = core.getInput('abi');
|
const arch = core.getInput('arch');
|
||||||
checkAbi(abi);
|
checkArch(arch);
|
||||||
console.log(`cpu/abi: ${abi}`);
|
console.log(`CPI architecture: ${arch}`);
|
||||||
|
|
||||||
|
// Hardware profile used for creating the AVD
|
||||||
|
const profile = core.getInput('profile');
|
||||||
|
console.log(`Hardware profile: ${profile}`);
|
||||||
|
|
||||||
// headless mode
|
// headless mode
|
||||||
const headlessInput = core.getInput('headless');
|
const headlessInput = core.getInput('headless');
|
||||||
@@ -38,16 +43,26 @@ async function run() {
|
|||||||
const disableAnimations = disableAnimationsInput === 'true';
|
const disableAnimations = disableAnimationsInput === 'true';
|
||||||
console.log(`disable animations: ${disableAnimations}`);
|
console.log(`disable animations: ${disableAnimations}`);
|
||||||
|
|
||||||
|
// custom scrpt to run
|
||||||
|
const scriptInput = core.getInput('script', { required: true });
|
||||||
|
const commands = scriptInput.split(/\r?\n/);
|
||||||
|
|
||||||
// install SDK
|
// install SDK
|
||||||
await installAndroidSdk(apiLevel, target, abi);
|
await installAndroidSdk(apiLevel, target, arch);
|
||||||
|
|
||||||
// launch emulator
|
// launch an emulator
|
||||||
// TODO get from input (source list of all profiles)
|
await launchEmulator(apiLevel, target, arch, profile, headless, disableAnimations);
|
||||||
const device = 'Nexus 6P';
|
|
||||||
await launchEmulator(apiLevel, target, abi, device, headless, disableAnimations);
|
|
||||||
|
|
||||||
// TODO start emulator
|
// execute the custom script
|
||||||
|
commands.forEach(async command => {
|
||||||
|
await exec.exec(`${command}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// finally kill the emulator
|
||||||
|
await killEmulator();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
// kill the emulator so the action can exit
|
||||||
|
await killEmulator();
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,13 +2,14 @@ import * as exec from '@actions/exec';
|
|||||||
import * as tc from '@actions/tool-cache';
|
import * as tc from '@actions/tool-cache';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
|
|
||||||
|
const BUILD_TOOLS_VERSION = '29.0.2';
|
||||||
const SDK_URL = 'https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip';
|
const SDK_URL = 'https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads and installs the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
|
* Downloads and installs the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator,
|
||||||
* and the system image for the chosen API level, cpu/abi, and target.
|
* and the system image for the chosen API level, CPU arch, and target.
|
||||||
*/
|
*/
|
||||||
export async function installAndroidSdk(apiLevel: number, target: string, abi: string): Promise<void> {
|
export async function installAndroidSdk(apiLevel: number, target: string, arch: string): Promise<void> {
|
||||||
// download Android SDK if not already installed
|
// download Android SDK if not already installed
|
||||||
if (fs.existsSync(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager`)) {
|
if (fs.existsSync(`${process.env.ANDROID_HOME}/tools/bin/sdkmanager`)) {
|
||||||
console.log('Android SDK already installed.');
|
console.log('Android SDK already installed.');
|
||||||
@@ -22,7 +23,8 @@ export async function installAndroidSdk(apiLevel: number, target: string, abi: s
|
|||||||
console.log('Installing build tools, platform tools, platform and system image.');
|
console.log('Installing build tools, platform tools, platform and system image.');
|
||||||
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
||||||
await exec.exec(`echo "y" | ${sdkmangerPath} --licenses > /dev/null`);
|
await exec.exec(`echo "y" | ${sdkmangerPath} --licenses > /dev/null`);
|
||||||
await exec.exec(`${sdkmangerPath} tools platform-tools "platforms;android-${apiLevel}"`);
|
await exec.exec(`${sdkmangerPath} "build-tools;${BUILD_TOOLS_VERSION}"`);
|
||||||
await exec.exec(`${sdkmangerPath} "system-images;android-${apiLevel};${target};${abi}"`);
|
await exec.exec(`${sdkmangerPath} platform-tools "platforms;android-${apiLevel}"`);
|
||||||
|
await exec.exec(`${sdkmangerPath} "system-images;android-${apiLevel};${target};${arch}"`);
|
||||||
await exec.exec(`bash -c \\"${sdkmangerPath} --update > /dev/null"`);
|
await exec.exec(`bash -c \\"${sdkmangerPath} --update > /dev/null"`);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user