Skip to content

Commit

Permalink
Merge pull request #206 from amyu/feat-sdk-versions
Browse files Browse the repository at this point in the history
Allow multiple sdkversion to be specified
  • Loading branch information
amyu authored Oct 30, 2023
2 parents 4492ecb + 673ffa1 commit cf0838b
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 41 deletions.
57 changes: 47 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'build-test'
name: build-test
on:
pull_request:

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
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
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions dist/cleanup/index.js

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

28 changes: 21 additions & 7 deletions dist/setup/index.js

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

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

export async function saveCache(
sdkVersion: string,
sdkVersion: string[],
buildToolsVersion: string,
ndkVersion: string,
cmakeVersion: string,
Expand All @@ -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 {
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 cf0838b

Please sign in to comment.