Support specifying versions of NDK and CMake to install.

This commit is contained in:
Yang
2020-04-11 20:53:36 +10:00
committed by Yang
parent 61dd774a5b
commit 438dce7110
6 changed files with 76 additions and 6 deletions
+21
View File
@@ -67,6 +67,25 @@ jobs:
script: ./gradlew connectedCheck script: ./gradlew connectedCheck
``` ```
If you need specific versions of **NDK** and **CMake** installed:
```
jobs:
test:
runs-on: macos-latest
steps:
- name: checkout
uses: actions/checkout@v2
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
ndk: 21.0.6113669
cmake: 3.10.2.4988404
script: ./gradlew connectedCheck
```
## Configurations ## Configurations
| | **Required** | **Default** | **Description** | | | **Required** | **Default** | **Description** |
@@ -79,6 +98,8 @@ jobs:
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. | | `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. | | `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. | | `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` |
| `cmake` | Optional | N/A | Version of CMake to install - e.g. `3.10.2.4988404` |
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` | | `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`. Default `emulator-options`: `-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim`.
+8 -2
View File
@@ -15,7 +15,7 @@ inputs:
description: 'CPU architecture of the system image - x86 or x86_64' description: 'CPU architecture of the system image - x86 or x86_64'
default: 'x86' default: 'x86'
profile: profile:
description: 'Hardware profile used for creating the AVD - e.g. `Nexus 6`.' description: 'hardware profile used for creating the AVD - e.g. `Nexus 6`.'
emulator-options: emulator-options:
description: 'command-line options used when launching the emulator - e.g. `-no-window -no-snapshot -camera-back emulated`.' description: 'command-line options used when launching the emulator - e.g. `-no-window -no-snapshot -camera-back emulated`.'
default: '-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim' default: '-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim'
@@ -23,7 +23,13 @@ inputs:
description: 'whether to disable animations - true or false' description: 'whether to disable animations - true or false'
default: 'true' default: 'true'
emulator-build: emulator-build:
description: 'build number of a specific version of the emulator binary to use e.g. `6061023` for emulator v29.3.0.0.' description: 'build number of a specific version of the emulator binary to use - e.g. `6061023` for emulator v29.3.0.0.'
working-directory:
description: 'A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository.'
ndk:
description: 'version of NDK to install - e.g. 21.0.6113669'
cmake:
description: 'version of CMake to install - e.g. 3.10.2.4988404'
script: script:
description: 'custom script to run - e.g. `./gradlew connectedCheck`' description: 'custom script to run - e.g. `./gradlew connectedCheck`'
required: true required: true
+13 -1
View File
@@ -70,6 +70,18 @@ function run() {
console.log(`custom working directory: ${workingDirectoryInput}`); console.log(`custom working directory: ${workingDirectoryInput}`);
} }
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput; const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;
// version of NDK to install
const ndkInput = core.getInput('ndk');
if (ndkInput) {
console.log(`version of NDK to install: ${ndkInput}`);
}
const ndkVersion = !ndkInput ? undefined : ndkInput;
// version of CMake to install
const cmakeInput = core.getInput('cmake');
if (cmakeInput) {
console.log(`version of CMake to install: ${cmakeInput}`);
}
const cmakeVersion = !cmakeInput ? undefined : cmakeInput;
// custom script to run // custom script to run
const scriptInput = core.getInput('script', { required: true }); const scriptInput = core.getInput('script', { required: true });
const scripts = script_parser_1.parseScript(scriptInput); const scripts = script_parser_1.parseScript(scriptInput);
@@ -78,7 +90,7 @@ function run() {
console.log(`${script}`); console.log(`${script}`);
})); }));
// install SDK // install SDK
yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild); yield sdk_installer_1.installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
// launch an emulator // launch an emulator
yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations); yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
// execute the custom script // execute the custom script
+9 -1
View File
@@ -24,7 +24,7 @@ const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/comman
* Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator, * 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. * and the system image for the chosen API level, CPU arch, and target.
*/ */
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) { function installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const isOnMac = process.platform === 'darwin'; const isOnMac = process.platform === 'darwin';
console.log('Installing new cmdline-tools.'); console.log('Installing new cmdline-tools.');
@@ -55,6 +55,14 @@ function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
} }
console.log('Installing system images.'); console.log('Installing system images.');
yield exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`); yield exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
if (ndkVersion) {
console.log(`Installing NDK ${ndkVersion}.`);
yield exec.exec(`sh -c \\"sdkmanager --install 'ndk;${ndkVersion}' > /dev/null"`);
}
if (cmakeVersion) {
console.log(`Installing CMake ${cmakeVersion}.`);
yield exec.exec(`sh -c \\"sdkmanager --install 'cmake;${cmakeVersion}' > /dev/null"`);
}
}); });
} }
exports.installAndroidSdk = installAndroidSdk; exports.installAndroidSdk = installAndroidSdk;
+15 -1
View File
@@ -63,6 +63,20 @@ async function run() {
} }
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput; const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;
// version of NDK to install
const ndkInput = core.getInput('ndk');
if (ndkInput) {
console.log(`version of NDK to install: ${ndkInput}`);
}
const ndkVersion = !ndkInput ? undefined : ndkInput;
// version of CMake to install
const cmakeInput = core.getInput('cmake');
if (cmakeInput) {
console.log(`version of CMake to install: ${cmakeInput}`);
}
const cmakeVersion = !cmakeInput ? undefined : cmakeInput;
// custom script to run // custom script to run
const scriptInput = core.getInput('script', { required: true }); const scriptInput = core.getInput('script', { required: true });
const scripts = parseScript(scriptInput); const scripts = parseScript(scriptInput);
@@ -72,7 +86,7 @@ async function run() {
}); });
// install SDK // install SDK
await installAndroidSdk(apiLevel, target, arch, emulatorBuild); await installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion);
// launch an emulator // launch an emulator
await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations); await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations);
+10 -1
View File
@@ -9,7 +9,7 @@ const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/comman
* Installs & updates the Android SDK for the macOS platform, including SDK platform for the chosen API level, latest build tools, platform tools, Android Emulator, * 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. * 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> { export async function installAndroidSdk(apiLevel: number, target: string, arch: string, emulatorBuild?: string, ndkVersion?: string, cmakeVersion?: string): Promise<void> {
const isOnMac = process.platform === 'darwin'; const isOnMac = process.platform === 'darwin';
console.log('Installing new cmdline-tools.'); console.log('Installing new cmdline-tools.');
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX; const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
@@ -42,4 +42,13 @@ export async function installAndroidSdk(apiLevel: number, target: string, arch:
} }
console.log('Installing system images.'); console.log('Installing system images.');
await exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`); await exec.exec(`sh -c \\"sdkmanager --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
if (ndkVersion) {
console.log(`Installing NDK ${ndkVersion}.`);
await exec.exec(`sh -c \\"sdkmanager --install 'ndk;${ndkVersion}' > /dev/null"`);
}
if (cmakeVersion) {
console.log(`Installing CMake ${cmakeVersion}.`);
await exec.exec(`sh -c \\"sdkmanager --install 'cmake;${cmakeVersion}' > /dev/null"`);
}
} }