Skip to content

Commit

Permalink
Allow multiple sdkversion to be specified
Browse files Browse the repository at this point in the history
  • Loading branch information
amyu committed Oct 30, 2023
1 parent 4492ecb commit 08a2c47
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 25 deletions.
43 changes: 40 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
15 changes: 12 additions & 3 deletions dist/cleanup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 16 additions & 6 deletions dist/setup/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -42,7 +47,7 @@ export async function restoreCache(
}

export async function saveCache(
sdkVersion: string,
sdkVersion: string[],
buildToolsVersion: string,
ndkVersion: string,
cmakeVersion: string,
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/cleanup-android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ async function run(): Promise<void> {
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)
Expand Down
12 changes: 8 additions & 4 deletions src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
import {restoreCache} from './cache'

export async function getAndroidSdk(
sdkVersion: string,
sdkVersion: string[],
buildToolsVersion: string,
ndkVersion: string,
cmakeVersion: string,
Expand Down Expand Up @@ -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'])
}
Expand Down
2 changes: 1 addition & 1 deletion src/setup-android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {getAndroidSdk} from './installer'

async function run(): Promise<void> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/summary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 08a2c47

Please sign in to comment.