diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc5a0a4..f7cc793 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: 'build-test' +name: build-test on: pull_request: @@ -39,15 +39,15 @@ jobs: with: cache-disabled: false sdk-version: ${{ matrix.sdk }} - build-tools-version: '34.0.0' - cmake-version: '3.10.2.4988404' - ndk-version: '25.1.8937393' + build-tools-version: 34.0.0 + cmake-version: 3.10.2.4988404 + ndk-version: 25.1.8937393 - run: | ./sample-android-project/gradlew -p sample-android-project assembleDebug --stacktrace test_not_use_cache: - name: run test not use cache + name: run test not use cache ${{ matrix.os }} runs-on: ${{ matrix.os }} timeout-minutes: 20 strategy: @@ -78,15 +78,15 @@ jobs: with: cache-disabled: true sdk-version: 33 - build-tools-version: '34.0.0' - cmake-version: '3.10.2.4988404' - ndk-version: '25.1.8937393' + build-tools-version: 34.0.0 + cmake-version: 3.10.2.4988404 + ndk-version: 25.1.8937393 - run: | ./sample-android-project/gradlew -p sample-android-project assembleDebug --stacktrace test_check_cmdline_tools_path: - name: run check cmdline-tools path + name: run check cmdline-tools path ${{ matrix.os }} runs-on: ${{ matrix.os }} timeout-minutes: 20 strategy: @@ -118,7 +118,7 @@ jobs: sdkmanager --install "system-images;android-31;default;x86_64" test_custom_cache_key: - name: run test custom cache key + name: run test custom cache key ${{ matrix.os }} runs-on: ${{ matrix.os }} timeout-minutes: 20 strategy: @@ -148,3 +148,40 @@ jobs: - run: | sdkmanager --install emulator + + test_install_multiple_sdk_version: + name: run test install multiple sdk ${{ matrix.os }} + runs-on: ${{ matrix.os }} + timeout-minutes: 20 + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macos-latest] + concurrency: + group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.os }}-test_install_multiple_sdk_version + cancel-in-progress: true + + steps: + - uses: actions/checkout@v4 + + - name: remove android sdk from ubuntu-latest + shell: bash + run: | + echo 'ANDROID_HOME=' >> $GITHUB_ENV + echo 'ANDROID_SDK_ROOT=' >> $GITHUB_ENV + rm -rf ~/android + + - name: Setup JDK 17 + uses: actions/setup-java@v3 + with: + java-version: 17 + distribution: temurin + + - name: Setup Android SDK + uses: ./ + with: + sdk-version: | + 33 + 34 + + - run: | + sdkmanager --list_installed \ No newline at end of file diff --git a/README.md b/README.md index 33f3b92..2e5f3ca 100644 --- a/README.md +++ b/README.md @@ -53,29 +53,33 @@ steps: # Custom key for cache. It is invalid when `cache-disabled: true` cache-key: 'custom-cache-key' - # default: '33' + # default: 33 # sdk version # see https://developer.android.com/studio/releases/platforms # It will always be installed. - sdk-version: '33' + sdk-version: 33 + # or + sdk-version: | + 33 + 34 - # default: '33.0.2' + # default: 33.0.2 # build tools version # see https://developer.android.com/studio/releases/build-tools # It will always be installed. - build-tools-version: '33.0.2' + build-tools-version: 33.0.2 # default: '' # cmake version # see https://developer.android.com/studio/projects/install-ndk # Installed when the version is specified - cmake-version: '3.10.2.4988404' + cmake-version: 3.10.2.4988404 # default: '' # cmake version # see https://developer.android.com/studio/projects/install-ndk # Installed when the version is specified - ndk-version: '23.1.7779620' + ndk-version: 23.1.7779620 # default: true # Whether to generate or not the job summary diff --git a/dist/cleanup/index.js b/dist/cleanup/index.js index 9d15f37..49a88e6 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -59641,11 +59641,16 @@ exports.getRestoredEntry = exports.saveCache = exports.restoreCache = void 0; const core = __importStar(__nccwpck_require__(2186)); const cache = __importStar(__nccwpck_require__(7799)); const constants_1 = __nccwpck_require__(9042); +const cache_1 = __nccwpck_require__(7799); const RESTORED_ENTRY_STATE_KEY = 'restoredEntry'; function generateRestoreKey(sdkVersion, buildToolsVersion, ndkVersion, cmakeVersion, cacheKey) { + const suffixVersion = 'v3.4'; if (cacheKey) - return cacheKey; - return `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.2`; + return `${cacheKey}-${suffixVersion}`; + return (`${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-${suffixVersion}` + // cache keys can't contain `,` + .replace(/,/g, '') + .toLowerCase()); } function restoreCache(sdkVersion, buildToolsVersion, ndkVersion, cmakeVersion, cacheKey) { return __awaiter(this, void 0, void 0, function* () { @@ -59672,7 +59677,15 @@ function saveCache(sdkVersion, buildToolsVersion, ndkVersion, cmakeVersion, cach return; } core.info(`caching "${restoreKey}" ...`); - return yield cache.saveCache([constants_1.ANDROID_HOME_DIR], restoreKey); + try { + const savedEntry = yield cache.saveCache([constants_1.ANDROID_HOME_DIR], restoreKey); + return Promise.resolve(savedEntry); + } + catch (error) { + if (error instanceof cache_1.ReserveCacheError) { + core.info(error.message); + } + } }); } exports.saveCache = saveCache; @@ -59737,7 +59750,7 @@ function run() { if (!isJobStatusSuccess()) { return Promise.resolve(); } - const sdkVersion = core.getInput(constants.INPUT_SDK_VERSION); + const sdkVersion = core.getMultilineInput(constants.INPUT_SDK_VERSION); const buildToolsVersion = core.getInput(constants.INPUT_BUILD_TOOLS_VERSION); const ndkVersion = core.getInput(constants.INPUT_NDK_VERSION); const cmakeVersion = core.getInput(constants.INPUT_CMAKE_VERSION); diff --git a/dist/setup/index.js b/dist/setup/index.js index 0db9613..19cb109 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -60583,11 +60583,16 @@ exports.getRestoredEntry = exports.saveCache = exports.restoreCache = void 0; const core = __importStar(__nccwpck_require__(2186)); const cache = __importStar(__nccwpck_require__(7799)); const constants_1 = __nccwpck_require__(9042); +const cache_1 = __nccwpck_require__(7799); const RESTORED_ENTRY_STATE_KEY = 'restoredEntry'; function generateRestoreKey(sdkVersion, buildToolsVersion, ndkVersion, cmakeVersion, cacheKey) { + const suffixVersion = 'v3.4'; if (cacheKey) - return cacheKey; - return `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.2`; + return `${cacheKey}-${suffixVersion}`; + return (`${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-${suffixVersion}` + // cache keys can't contain `,` + .replace(/,/g, '') + .toLowerCase()); } function restoreCache(sdkVersion, buildToolsVersion, ndkVersion, cmakeVersion, cacheKey) { return __awaiter(this, void 0, void 0, function* () { @@ -60614,7 +60619,15 @@ function saveCache(sdkVersion, buildToolsVersion, ndkVersion, cmakeVersion, cach return; } core.info(`caching "${restoreKey}" ...`); - return yield cache.saveCache([constants_1.ANDROID_HOME_DIR], restoreKey); + try { + const savedEntry = yield cache.saveCache([constants_1.ANDROID_HOME_DIR], restoreKey); + return Promise.resolve(savedEntry); + } + catch (error) { + if (error instanceof cache_1.ReserveCacheError) { + core.info(error.message); + } + } }); } exports.saveCache = saveCache; @@ -60788,10 +60801,11 @@ function getAndroidSdk(sdkVersion, buildToolsVersion, ndkVersion, cmakeVersion, default: throw Error(`Unsupported platform: ${process.platform}`); } - yield exec.exec('sdkmanager', [`build-tools;${buildToolsVersion}`]); - yield exec.exec('sdkmanager', [`platform-tools`, '--verbose']); + const sdkVersionCommand = sdkVersion.map(version => `platforms;android-${version}`); yield exec.exec('sdkmanager', [ - `platforms;android-${sdkVersion}`, + `build-tools;${buildToolsVersion}`, + `platform-tools`, + ...sdkVersionCommand, '--verbose' ]); if (cmakeVersion) { @@ -60853,7 +60867,7 @@ const installer_1 = __nccwpck_require__(2574); function run() { return __awaiter(this, void 0, void 0, function* () { try { - const sdkVersion = core.getInput(constants.INPUT_SDK_VERSION); + const sdkVersion = core.getMultilineInput(constants.INPUT_SDK_VERSION); const buildToolsVersion = core.getInput(constants.INPUT_BUILD_TOOLS_VERSION); const ndkVersion = core.getInput(constants.INPUT_NDK_VERSION); const cmakeVersion = core.getInput(constants.INPUT_CMAKE_VERSION); diff --git a/src/cache.ts b/src/cache.ts index 8cae0cb..7aa5798 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,23 +1,29 @@ import * as core from '@actions/core' import * as cache from '@actions/cache' import {ANDROID_HOME_DIR} from './constants' -import {CacheEntry} from '@actions/cache' +import {CacheEntry, ReserveCacheError} from '@actions/cache' const RESTORED_ENTRY_STATE_KEY = 'restoredEntry' function generateRestoreKey( - sdkVersion: string, + sdkVersion: string[], buildToolsVersion: string, ndkVersion: string, cmakeVersion: string, cacheKey: string ): string { - if (cacheKey) return cacheKey - return `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.2` + const suffixVersion = 'v3.4' + if (cacheKey) return `${cacheKey}-${suffixVersion}` + return ( + `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-${suffixVersion}` + // cache keys can't contain `,` + .replace(/,/g, '') + .toLowerCase() + ) } export async function restoreCache( - sdkVersion: string, + sdkVersion: string[], buildToolsVersion: string, ndkVersion: string, cmakeVersion: string, @@ -42,7 +48,7 @@ export async function restoreCache( } export async function saveCache( - sdkVersion: string, + sdkVersion: string[], buildToolsVersion: string, ndkVersion: string, cmakeVersion: string, @@ -69,7 +75,14 @@ export async function saveCache( } core.info(`caching "${restoreKey}" ...`) - return await cache.saveCache([ANDROID_HOME_DIR], restoreKey) + try { + const savedEntry = await cache.saveCache([ANDROID_HOME_DIR], restoreKey) + return Promise.resolve(savedEntry) + } catch (error) { + if (error instanceof ReserveCacheError) { + core.info(error.message) + } + } } export function getRestoredEntry(): CacheEntry | undefined { diff --git a/src/cleanup-android.ts b/src/cleanup-android.ts index e7d6571..7b96eed 100644 --- a/src/cleanup-android.ts +++ b/src/cleanup-android.ts @@ -10,7 +10,7 @@ async function run(): Promise { return Promise.resolve() } - const sdkVersion = core.getInput(constants.INPUT_SDK_VERSION) + const sdkVersion = core.getMultilineInput(constants.INPUT_SDK_VERSION) const buildToolsVersion = core.getInput(constants.INPUT_BUILD_TOOLS_VERSION) const ndkVersion = core.getInput(constants.INPUT_NDK_VERSION) const cmakeVersion = core.getInput(constants.INPUT_CMAKE_VERSION) diff --git a/src/installer.ts b/src/installer.ts index cddbb10..7c183a5 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -12,7 +12,7 @@ import { import {restoreCache} from './cache' export async function getAndroidSdk( - sdkVersion: string, + sdkVersion: string[], buildToolsVersion: string, ndkVersion: string, cmakeVersion: string, @@ -100,12 +100,16 @@ export async function getAndroidSdk( throw Error(`Unsupported platform: ${process.platform}`) } - await exec.exec('sdkmanager', [`build-tools;${buildToolsVersion}`]) - await exec.exec('sdkmanager', [`platform-tools`, '--verbose']) + const sdkVersionCommand = sdkVersion.map( + version => `platforms;android-${version}` + ) await exec.exec('sdkmanager', [ - `platforms;android-${sdkVersion}`, + `build-tools;${buildToolsVersion}`, + `platform-tools`, + ...sdkVersionCommand, '--verbose' ]) + if (cmakeVersion) { await exec.exec('sdkmanager', [`cmake;${cmakeVersion}`, '--verbose']) } diff --git a/src/setup-android.ts b/src/setup-android.ts index 7a45b12..bf7d8fd 100644 --- a/src/setup-android.ts +++ b/src/setup-android.ts @@ -5,7 +5,7 @@ import {getAndroidSdk} from './installer' async function run(): Promise { try { - const sdkVersion = core.getInput(constants.INPUT_SDK_VERSION) + const sdkVersion = core.getMultilineInput(constants.INPUT_SDK_VERSION) const buildToolsVersion = core.getInput(constants.INPUT_BUILD_TOOLS_VERSION) const ndkVersion = core.getInput(constants.INPUT_NDK_VERSION) const cmakeVersion = core.getInput(constants.INPUT_CMAKE_VERSION) diff --git a/src/summary.ts b/src/summary.ts index 2c83b4d..6c45672 100644 --- a/src/summary.ts +++ b/src/summary.ts @@ -4,7 +4,7 @@ import {getRestoredEntry} from './cache' import {CacheEntry} from '@actions/cache' export async function renderSummary( - sdkVersion: string, + sdkVersion: string[], buildToolsVersion: string, ndkVersion: string, cmakeVersion: string,