Skip to content

Cache the AVD in CI before executing any tests #1091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 44 additions & 33 deletions .github/actions/gradle-tasks-with-emulator/action.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name : Run Android Instrumentation Tests with Artifact and AVD Caching
description: This action sets up Gradle, runs a preparatory task, runs Android tests on an emulator, and uploads test results.
description : This action sets up Gradle, runs a preparatory task, runs Android tests on an emulator, and uploads test results.

inputs:
prepare-task:
description: 'Gradle task for preparing necessary artifacts. Supports multi-line input.'
required: true
test-task:
description: 'Gradle task for running instrumentation tests. Supports multi-line input.'
required: true
inputs :
prepare-task :
description : 'Gradle task for preparing necessary artifacts. Supports multi-line input.'
required : true
test-task :
description : 'Gradle task for running instrumentation tests. Supports multi-line input.'
required : true
api-level :
description : 'The Android SDK api level, like `29`'
required : true
Expand Down Expand Up @@ -43,40 +43,51 @@ runs :
write-cache-key : ${{ inputs.write-cache-key }}

# Get the AVD if it's already cached.
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
- name : AVD cache
uses : actions/cache/restore@v3
id : restore-avd-cache
with :
path : |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}
key : avd-${{ matrix.api-level }}

# If the AVD cache didn't exist, create an AVD and cache it.
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ inputs.api-level }}
# If the AVD cache didn't exist, create an AVD
- name : create AVD and generate snapshot for caching
if : steps.restore-avd-cache.outputs.cache-hit != 'true'
uses : reactivecircus/android-emulator-runner@v2
with :
api-level : ${{ inputs.api-level }}
arch : x86_64
disable-animations: false
emulator-boot-timeout: 12000
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations : false
emulator-boot-timeout : 12000
emulator-options : -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation : false
profile : Galaxy Nexus
ram-size: 4096M
script: echo "Generated AVD snapshot."
ram-size : 4096M
script : echo "Generated AVD snapshot."

# If we just created an AVD because there wasn't one in the cache, then cache that AVD.
- name : cache new AVD before tests
if : steps.restore-avd-cache.outputs.cache-hit != 'true'
id : save-avd-cache
uses : actions/cache/save@v3
with :
path : |
~/.android/avd/*
~/.android/adb*
key : avd-${{ matrix.api-level }}

# Run the actual emulator tests.
# At this point every task should be up-to-date and the AVD should be ready to go.
- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ inputs.api-level }}
- name : run tests
uses : reactivecircus/android-emulator-runner@v2
with :
api-level : ${{ inputs.api-level }}
arch : x86_64
disable-animations: true
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations : true
emulator-options : -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation : false
profile : Galaxy Nexus
script : ./gradlew ${{ inputs.test-task }}

Expand Down