diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index fc5a0a4d..ecde5787 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,7 +47,7 @@ jobs: ./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: @@ -86,7 +86,7 @@ jobs: ./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/dist/cleanup/index.js b/dist/cleanup/index.js index 9d15f373..062afd17 100644 --- a/dist/cleanup/index.js +++ b/dist/cleanup/index.js @@ -59641,11 +59641,15 @@ 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) { if (cacheKey) return cacheKey; - return `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.2`; + return (`${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.4` + // 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 +59676,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 +59749,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 0db96131..f0d70012 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -60583,11 +60583,15 @@ 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) { if (cacheKey) return cacheKey; - return `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.2`; + return (`${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.4` + // 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 +60618,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 +60800,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 +60866,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 8cae0cb5..fb336d30 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,23 +1,28 @@ 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` + return ( + `${sdkVersion}-${buildToolsVersion}-${ndkVersion}-${cmakeVersion}-v3.4` + // cache keys can't contain `,` + .replace(/,/g, '') + .toLowerCase() + ) } export async function restoreCache( - sdkVersion: string, + sdkVersion: string[], buildToolsVersion: string, ndkVersion: string, cmakeVersion: string, @@ -42,7 +47,7 @@ export async function restoreCache( } export async function saveCache( - sdkVersion: string, + sdkVersion: string[], buildToolsVersion: string, ndkVersion: string, cmakeVersion: string, @@ -69,7 +74,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 e7d6571a..7b96eed5 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 cddbb103..7c183a5b 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 7a45b122..bf7d8fdd 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 2c83b4dc..6c456724 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,