mirror of
https://github.com/reactivecircus/android-emulator-runner.git
synced 2026-09-01 01:59:32 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2754675516 | |||
| aaa1121ed1 | |||
| ff311e8a7d | |||
| d0fa6c63f8 | |||
| bdf1f83901 | |||
| d3a226f97f | |||
| 4082c705ad | |||
| 5dd12aaed5 | |||
| e53c6d9838 | |||
| cb6efbb995 | |||
| 97f77e3305 | |||
| 128c6a83e1 | |||
| d27f7ec817 | |||
| 1162b6cd2f | |||
| e756009f0d | |||
| 2c5dfd9240 |
@@ -16,9 +16,10 @@ jobs:
|
||||
api-level: [21, 23, 29]
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
fetch-depth: 1
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: validate gradle wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
|
||||
- name: build, test and lint
|
||||
run: |
|
||||
@@ -27,8 +28,10 @@ jobs:
|
||||
npm run lint
|
||||
npm test
|
||||
|
||||
- name: Prepare test fixture
|
||||
run: cp -a ./test-fixture/* ./
|
||||
- name: Java 13
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 13
|
||||
|
||||
- name: run action
|
||||
uses: ./
|
||||
@@ -39,6 +42,8 @@ jobs:
|
||||
profile: Nexus 6
|
||||
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
|
||||
disable-animations: true
|
||||
working-directory: ./test-fixture/
|
||||
script: |
|
||||
echo $GITHUB_REPOSITORY
|
||||
./gradlew help
|
||||
./gradlew connectedDebugAndroidTest
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
# Change Log
|
||||
|
||||
## v2.4.0
|
||||
|
||||
* Added support for setting custom `working-directory` - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository.
|
||||
|
||||
## v2.3.2
|
||||
|
||||
* Fixed an issue where environment variables are escaped in script.
|
||||
|
||||
## v2.3.1
|
||||
|
||||
* Bumped Android Build tools to 29.0.3.
|
||||
|
||||
## v2.3.0
|
||||
|
||||
* Added support for running the action with Java 9+ by forcing SDK manager and AVD manager to use Java 8.
|
||||
|
||||
## v2.2.0
|
||||
|
||||
* Fixed an issue where emulator is killed prematurely.
|
||||
|
||||
@@ -32,9 +32,7 @@ jobs:
|
||||
runs-on: macOS-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
fetch-depth: 1
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: run tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
@@ -55,9 +53,7 @@ jobs:
|
||||
target: [default, google_apis]
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v1
|
||||
with:
|
||||
fetch-depth: 1
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: run tests
|
||||
uses: reactivecircus/android-emulator-runner@v2
|
||||
@@ -80,6 +76,7 @@ jobs:
|
||||
| `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`. |
|
||||
| `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. |
|
||||
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` |
|
||||
|
||||
Default `emulator-options`: `-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim`.
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||
result["default"] = mod;
|
||||
return result;
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
/**
|
||||
* Returns the current $JAVA_HOME path.
|
||||
*/
|
||||
function getCurrentJavaHome() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let defaultJavaHome = '';
|
||||
yield exec.exec(`sh -c \\"echo $JAVA_HOME"`, [], {
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
defaultJavaHome += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
return defaultJavaHome.trim();
|
||||
});
|
||||
}
|
||||
exports.getCurrentJavaHome = getCurrentJavaHome;
|
||||
/**
|
||||
* Returns the Java 8 $JAVA_HOME path.
|
||||
*/
|
||||
function getJavaHomeV8() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let javaHomeV8 = '';
|
||||
yield exec.exec(`/usr/libexec/java_home -v 1.8`, [], {
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
javaHomeV8 += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
return javaHomeV8.trim();
|
||||
});
|
||||
}
|
||||
exports.getJavaHomeV8 = getJavaHomeV8;
|
||||
/**
|
||||
* Sets $JAVA_HOME to the specified path.
|
||||
*/
|
||||
function setJavaHome(path) {
|
||||
core.exportVariable('JAVA_HOME', path);
|
||||
}
|
||||
exports.setJavaHome = setJavaHome;
|
||||
+17
-1
@@ -21,6 +21,7 @@ const input_validator_1 = require("./input-validator");
|
||||
const emulator_manager_1 = require("./emulator-manager");
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const script_parser_1 = require("./script-parser");
|
||||
const java_version_manager_1 = require("./java-version-manager");
|
||||
function run() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
@@ -59,6 +60,12 @@ function run() {
|
||||
console.log(`using emulator build: ${emulatorBuildInput}`);
|
||||
}
|
||||
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;
|
||||
// custom working directory
|
||||
const workingDirectoryInput = core.getInput('working-directory');
|
||||
if (workingDirectoryInput) {
|
||||
console.log(`custom working directory: ${workingDirectoryInput}`);
|
||||
}
|
||||
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;
|
||||
// custom script to run
|
||||
const scriptInput = core.getInput('script', { required: true });
|
||||
const scripts = script_parser_1.parseScript(scriptInput);
|
||||
@@ -66,6 +73,9 @@ function run() {
|
||||
scripts.forEach((script) => __awaiter(this, void 0, void 0, function* () {
|
||||
console.log(`${script}`);
|
||||
}));
|
||||
// use Java 8 for sdkmanager and avdmanager
|
||||
const defaultJavaHome = yield java_version_manager_1.getCurrentJavaHome();
|
||||
java_version_manager_1.setJavaHome(yield java_version_manager_1.getJavaHomeV8());
|
||||
// install SDK
|
||||
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild);
|
||||
try {
|
||||
@@ -75,10 +85,16 @@ function run() {
|
||||
catch (error) {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
// use default JAVA_HOME for running custom script
|
||||
java_version_manager_1.setJavaHome(defaultJavaHome);
|
||||
// execute the custom script
|
||||
try {
|
||||
// move to custom working directory if set
|
||||
if (workingDirectory) {
|
||||
process.chdir(workingDirectory);
|
||||
}
|
||||
for (const script of scripts) {
|
||||
yield exec.exec(`${script}`);
|
||||
yield exec.exec(`sh -c \\"${script}"`);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
@@ -16,16 +16,16 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const exec = __importStar(require("@actions/exec"));
|
||||
const BUILD_TOOLS_VERSION = '29.0.2';
|
||||
const BUILD_TOOLS_VERSION = '29.0.3';
|
||||
/**
|
||||
* Installs & updates 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 arch, and target.
|
||||
*/
|
||||
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
||||
const sdkmanagerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
||||
console.log('Installing latest build tools, platform tools, and platform.');
|
||||
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
|
||||
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
|
||||
if (emulatorBuild) {
|
||||
console.log(`Installing emulator build ${emulatorBuild}.`);
|
||||
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
|
||||
@@ -35,10 +35,10 @@ function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
|
||||
}
|
||||
else {
|
||||
console.log('Installing latest emulator.');
|
||||
yield exec.exec(`sh -c \\"${sdkmangerPath} --install emulator > /dev/null"`);
|
||||
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install emulator > /dev/null"`);
|
||||
}
|
||||
console.log('Installing system images.');
|
||||
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
|
||||
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
|
||||
});
|
||||
}
|
||||
exports.installAndroidSdk = installAndroidSdk;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
/**
|
||||
* Returns the current $JAVA_HOME path.
|
||||
*/
|
||||
export async function getCurrentJavaHome(): Promise<string> {
|
||||
let defaultJavaHome = '';
|
||||
await exec.exec(`sh -c \\"echo $JAVA_HOME"`, [], {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
defaultJavaHome += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
return defaultJavaHome.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Java 8 $JAVA_HOME path.
|
||||
*/
|
||||
export async function getJavaHomeV8(): Promise<string> {
|
||||
let javaHomeV8 = '';
|
||||
await exec.exec(`/usr/libexec/java_home -v 1.8`, [], {
|
||||
listeners: {
|
||||
stdout: (data: Buffer) => {
|
||||
javaHomeV8 += data.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
return javaHomeV8.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets $JAVA_HOME to the specified path.
|
||||
*/
|
||||
export function setJavaHome(path: string) {
|
||||
core.exportVariable('JAVA_HOME', path);
|
||||
}
|
||||
+20
-1
@@ -4,6 +4,7 @@ import { checkApiLevel, checkTarget, checkArch, checkDisableAnimations, checkEmu
|
||||
import { launchEmulator, killEmulator } from './emulator-manager';
|
||||
import * as exec from '@actions/exec';
|
||||
import { parseScript } from './script-parser';
|
||||
import { getCurrentJavaHome, getJavaHomeV8, setJavaHome } from './java-version-manager';
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
@@ -50,6 +51,13 @@ async function run() {
|
||||
}
|
||||
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;
|
||||
|
||||
// custom working directory
|
||||
const workingDirectoryInput = core.getInput('working-directory');
|
||||
if (workingDirectoryInput) {
|
||||
console.log(`custom working directory: ${workingDirectoryInput}`);
|
||||
}
|
||||
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;
|
||||
|
||||
// custom script to run
|
||||
const scriptInput = core.getInput('script', { required: true });
|
||||
const scripts = parseScript(scriptInput);
|
||||
@@ -58,6 +66,10 @@ async function run() {
|
||||
console.log(`${script}`);
|
||||
});
|
||||
|
||||
// use Java 8 for sdkmanager and avdmanager
|
||||
const defaultJavaHome = await getCurrentJavaHome();
|
||||
setJavaHome(await getJavaHomeV8());
|
||||
|
||||
// install SDK
|
||||
await installAndroidSdk(apiLevel, target, arch, emulatorBuild);
|
||||
|
||||
@@ -68,10 +80,17 @@ async function run() {
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
|
||||
// use default JAVA_HOME for running custom script
|
||||
setJavaHome(defaultJavaHome);
|
||||
|
||||
// execute the custom script
|
||||
try {
|
||||
// move to custom working directory if set
|
||||
if (workingDirectory) {
|
||||
process.chdir(workingDirectory);
|
||||
}
|
||||
for (const script of scripts) {
|
||||
await exec.exec(`${script}`);
|
||||
await exec.exec(`sh -c \\"${script}"`);
|
||||
}
|
||||
} catch (error) {
|
||||
core.setFailed(error.message);
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
const BUILD_TOOLS_VERSION = '29.0.2';
|
||||
const BUILD_TOOLS_VERSION = '29.0.3';
|
||||
|
||||
/**
|
||||
* Installs & updates 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 arch, and target.
|
||||
*/
|
||||
export async function installAndroidSdk(apiLevel: number, target: string, arch: string, emulatorBuild?: string): Promise<void> {
|
||||
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
||||
const sdkmanagerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
|
||||
console.log('Installing latest build tools, platform tools, and platform.');
|
||||
await exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
|
||||
await exec.exec(`sh -c \\"${sdkmanagerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
|
||||
if (emulatorBuild) {
|
||||
console.log(`Installing emulator build ${emulatorBuild}.`);
|
||||
await exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
|
||||
@@ -18,8 +18,8 @@ export async function installAndroidSdk(apiLevel: number, target: string, arch:
|
||||
await exec.exec(`rm -f emulator.zip`);
|
||||
} else {
|
||||
console.log('Installing latest emulator.');
|
||||
await exec.exec(`sh -c \\"${sdkmangerPath} --install emulator > /dev/null"`);
|
||||
await exec.exec(`sh -c \\"${sdkmanagerPath} --install emulator > /dev/null"`);
|
||||
}
|
||||
console.log('Installing system images.');
|
||||
await exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
|
||||
await exec.exec(`sh -c \\"${sdkmanagerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ apply plugin: 'kotlin-android-extensions'
|
||||
|
||||
android {
|
||||
compileSdkVersion 29
|
||||
buildToolsVersion "29.0.2"
|
||||
buildToolsVersion "29.0.3"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.example.testapp"
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
|
||||
|
||||
Reference in New Issue
Block a user