diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d483db50..789976aac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## v2.7.0 + +* Added support for specifying versions of **NDK** and **CMake** to install. + ## v2.6.2 * Fixed an issue where the Linux command-line tools binary is used for `macos`. diff --git a/README.md b/README.md index 43bce09fd..9255cd556 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,25 @@ jobs: 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 | | **Required** | **Default** | **Description** | @@ -79,6 +98,8 @@ jobs: | `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. | +| `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` | Default `emulator-options`: `-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim`. diff --git a/action.yml b/action.yml index e71bb0123..6d8976d81 100644 --- a/action.yml +++ b/action.yml @@ -15,7 +15,7 @@ inputs: description: 'CPU architecture of the system image - x86 or x86_64' default: 'x86' 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: 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' @@ -23,7 +23,13 @@ inputs: description: 'whether to disable animations - true or false' default: 'true' 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: description: 'custom script to run - e.g. `./gradlew connectedCheck`' required: true diff --git a/lib/main.js b/lib/main.js index d9a61644a..367f7e437 100644 --- a/lib/main.js +++ b/lib/main.js @@ -70,6 +70,18 @@ function run() { console.log(`custom working directory: ${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 const scriptInput = core.getInput('script', { required: true }); const scripts = script_parser_1.parseScript(scriptInput); @@ -78,7 +90,7 @@ function run() { console.log(`${script}`); })); // 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 yield emulator_manager_1.launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations); // execute the custom script diff --git a/lib/sdk-installer.js b/lib/sdk-installer.js index 9a96b13fd..112cfdca8 100644 --- a/lib/sdk-installer.js +++ b/lib/sdk-installer.js @@ -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, * 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* () { const isOnMac = process.platform === 'darwin'; console.log('Installing new cmdline-tools.'); @@ -55,6 +55,14 @@ function installAndroidSdk(apiLevel, target, arch, emulatorBuild) { } console.log('Installing system images.'); 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; diff --git a/package-lock.json b/package-lock.json index f6e9cc8de..e4e3073e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4937,20 +4937,12 @@ } }, "mkdirp": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", + "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", "dev": true, "requires": { - "minimist": "0.0.8" - }, - "dependencies": { - "minimist": { - "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true - } + "minimist": "^1.2.5" } }, "ms": { diff --git a/src/main.ts b/src/main.ts index 447a79352..721f315f6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -63,6 +63,20 @@ async function run() { } 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 const scriptInput = core.getInput('script', { required: true }); const scripts = parseScript(scriptInput); @@ -72,7 +86,7 @@ async function run() { }); // install SDK - await installAndroidSdk(apiLevel, target, arch, emulatorBuild); + await installAndroidSdk(apiLevel, target, arch, emulatorBuild, ndkVersion, cmakeVersion); // launch an emulator await launchEmulator(apiLevel, target, arch, profile, emulatorOptions, disableAnimations); diff --git a/src/sdk-installer.ts b/src/sdk-installer.ts index 3833de013..d39e9c33f 100644 --- a/src/sdk-installer.ts +++ b/src/sdk-installer.ts @@ -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, * 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 { +export async function installAndroidSdk(apiLevel: number, target: string, arch: string, emulatorBuild?: string, ndkVersion?: string, cmakeVersion?: string): Promise { const isOnMac = process.platform === 'darwin'; console.log('Installing new cmdline-tools.'); 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.'); 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"`); + } }