Skip to content

Commit 6697056

Browse files
authored
Merge pull request #1091 from square/rick/save_porcelain_AVD_on_cache_miss
Cache the AVD in CI before executing any tests
2 parents 5ff0058 + 63fc5a5 commit 6697056

File tree

1 file changed

+44
-33
lines changed
  • .github/actions/gradle-tasks-with-emulator

1 file changed

+44
-33
lines changed

.github/actions/gradle-tasks-with-emulator/action.yml

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
name : Run Android Instrumentation Tests with Artifact and AVD Caching
2-
description: This action sets up Gradle, runs a preparatory task, runs Android tests on an emulator, and uploads test results.
2+
description : This action sets up Gradle, runs a preparatory task, runs Android tests on an emulator, and uploads test results.
33

4-
inputs:
5-
prepare-task:
6-
description: 'Gradle task for preparing necessary artifacts. Supports multi-line input.'
7-
required: true
8-
test-task:
9-
description: 'Gradle task for running instrumentation tests. Supports multi-line input.'
10-
required: true
4+
inputs :
5+
prepare-task :
6+
description : 'Gradle task for preparing necessary artifacts. Supports multi-line input.'
7+
required : true
8+
test-task :
9+
description : 'Gradle task for running instrumentation tests. Supports multi-line input.'
10+
required : true
1111
api-level :
1212
description : 'The Android SDK api level, like `29`'
1313
required : true
@@ -43,40 +43,51 @@ runs :
4343
write-cache-key : ${{ inputs.write-cache-key }}
4444

4545
# Get the AVD if it's already cached.
46-
- name: AVD cache
47-
uses: actions/cache@v3
48-
id: avd-cache
49-
with:
50-
path: |
46+
- name : AVD cache
47+
uses : actions/cache/restore@v3
48+
id : restore-avd-cache
49+
with :
50+
path : |
5151
~/.android/avd/*
5252
~/.android/adb*
53-
key: avd-${{ matrix.api-level }}
53+
key : avd-${{ matrix.api-level }}
5454

55-
# If the AVD cache didn't exist, create an AVD and cache it.
56-
- name: create AVD and generate snapshot for caching
57-
if: steps.avd-cache.outputs.cache-hit != 'true'
58-
uses: reactivecircus/android-emulator-runner@v2
59-
with:
60-
api-level: ${{ inputs.api-level }}
55+
# If the AVD cache didn't exist, create an AVD
56+
- name : create AVD and generate snapshot for caching
57+
if : steps.restore-avd-cache.outputs.cache-hit != 'true'
58+
uses : reactivecircus/android-emulator-runner@v2
59+
with :
60+
api-level : ${{ inputs.api-level }}
6161
arch : x86_64
62-
disable-animations: false
63-
emulator-boot-timeout: 12000
64-
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
65-
force-avd-creation: false
62+
disable-animations : false
63+
emulator-boot-timeout : 12000
64+
emulator-options : -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
65+
force-avd-creation : false
6666
profile : Galaxy Nexus
67-
ram-size: 4096M
68-
script: echo "Generated AVD snapshot."
67+
ram-size : 4096M
68+
script : echo "Generated AVD snapshot."
69+
70+
# If we just created an AVD because there wasn't one in the cache, then cache that AVD.
71+
- name : cache new AVD before tests
72+
if : steps.restore-avd-cache.outputs.cache-hit != 'true'
73+
id : save-avd-cache
74+
uses : actions/cache/save@v3
75+
with :
76+
path : |
77+
~/.android/avd/*
78+
~/.android/adb*
79+
key : avd-${{ matrix.api-level }}
6980

7081
# Run the actual emulator tests.
7182
# At this point every task should be up-to-date and the AVD should be ready to go.
72-
- name: run tests
73-
uses: reactivecircus/android-emulator-runner@v2
74-
with:
75-
api-level: ${{ inputs.api-level }}
83+
- name : run tests
84+
uses : reactivecircus/android-emulator-runner@v2
85+
with :
86+
api-level : ${{ inputs.api-level }}
7687
arch : x86_64
77-
disable-animations: true
78-
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
79-
force-avd-creation: false
88+
disable-animations : true
89+
emulator-options : -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
90+
force-avd-creation : false
8091
profile : Galaxy Nexus
8192
script : ./gradlew ${{ inputs.test-task }}
8293

0 commit comments

Comments
 (0)