Skip to content

Commit 8bbe814

Browse files
authored
Cache Android Emulator generation (#4605)
* Cache Android Emulator generation As outline in https://github.com/marketplace/actions/android-emulator-runner#usage--examples we can cache the android emulator AVD generation. * Fix whitespace * Update agp-matrix.yml * Update agp-matrix.yml * Improve Cache key * Add AVD caching to integration tests too * Update integration-tests-ui-critical.yml * Fix missing target spec * Update agp-matrix.yml
1 parent 510eb18 commit 8bbe814

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

.github/workflows/agp-matrix.yml

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,36 @@ jobs:
4343
with:
4444
cache-encryption-key: ${{ secrets.GRADLE_ENCRYPTION_KEY }}
4545

46-
- name: Setup KVM
47-
shell: bash
46+
- name: Enable KVM
4847
run: |
49-
# check if virtualization is supported...
50-
sudo apt install -y --no-install-recommends cpu-checker coreutils && echo "CPUs=$(nproc --all)" && kvm-ok
51-
# allow access to KVM to run the emulator
52-
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
53-
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
48+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
5449
sudo udevadm control --reload-rules
5550
sudo udevadm trigger --name-match=kvm
5651
52+
- name: AVD cache
53+
uses: actions/cache@v4
54+
id: avd-cache
55+
with:
56+
path: |
57+
~/.android/avd/*
58+
~/.android/adb*
59+
key: avd-api-30-x86_64-aosp_atd
60+
61+
- name: Create AVD and generate snapshot for caching
62+
if: steps.avd-cache.outputs.cache-hit != 'true'
63+
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # pin@v2
64+
with:
65+
api-level: 30
66+
target: aosp_atd
67+
channel: canary # Necessary for ATDs
68+
arch: x86_64
69+
force-avd-creation: false
70+
disable-animations: true
71+
disable-spellchecker: true
72+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
73+
disk-size: 4096M
74+
script: echo "Generated AVD snapshot for caching."
75+
5776
# Clean, build and release a test apk
5877
- name: Make assembleUiTests
5978
run: make assembleUiTests
@@ -63,13 +82,13 @@ jobs:
6382
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # pin@v2
6483
with:
6584
api-level: 30
85+
target: aosp_atd
86+
channel: canary # Necessary for ATDs
87+
arch: x86_64
6688
force-avd-creation: false
67-
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
6889
disable-animations: true
6990
disable-spellchecker: true
70-
target: 'aosp_atd'
71-
arch: x86
72-
channel: canary # Necessary for ATDs
91+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
7392
disk-size: 4096M
7493
script: ./gradlew sentry-android-integration-tests:sentry-uitest-android:connectedReleaseAndroidTest -DtestBuildType=release -Denvironment=github --daemon
7594

.github/workflows/integration-tests-ui-critical.yml

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,36 @@ jobs:
7979
- name: Checkout code
8080
uses: actions/checkout@v4
8181

82-
- name: Setup KVM
83-
shell: bash
82+
- name: Enable KVM
8483
run: |
85-
# check if virtualization is supported...
86-
sudo apt install -y --no-install-recommends cpu-checker coreutils && echo "CPUs=$(nproc --all)" && kvm-ok
87-
# allow access to KVM to run the emulator
88-
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' \
89-
| sudo tee /etc/udev/rules.d/99-kvm4all.rules
84+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
9085
sudo udevadm control --reload-rules
9186
sudo udevadm trigger --name-match=kvm
9287
88+
- name: AVD cache
89+
uses: actions/cache@v4
90+
id: avd-cache
91+
with:
92+
path: |
93+
~/.android/avd/*
94+
~/.android/adb*
95+
key: avd-api-${{ matrix.api-level }}-${{ matrix.arch }}-${{ matrix.target }}
96+
97+
- name: Create AVD and generate snapshot for caching
98+
if: steps.avd-cache.outputs.cache-hit != 'true'
99+
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # pin@v2
100+
with:
101+
api-level: ${{ matrix.api-level }}
102+
target: ${{ matrix.target }}
103+
channel: ${{ matrix.channel }}
104+
arch: ${{ matrix.arch }}
105+
force-avd-creation: false
106+
disable-animations: true
107+
disable-spellchecker: true
108+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
109+
disk-size: 4096M
110+
script: echo "Generated AVD snapshot for caching."
111+
93112
- name: Download APK artifact
94113
uses: actions/download-artifact@v5
95114
with:
@@ -104,21 +123,13 @@ jobs:
104123
uses: reactivecircus/android-emulator-runner@1dcd0090116d15e7c562f8db72807de5e036a4ed # [email protected]
105124
with:
106125
api-level: ${{ matrix.api-level }}
107-
force-avd-creation: false
108-
disable-animations: true
109-
disable-spellchecker: true
110126
target: ${{ matrix.target }}
111127
channel: ${{ matrix.channel }}
112128
arch: ${{ matrix.arch }}
113-
emulator-options: >
114-
-no-window
115-
-no-snapshot-save
116-
-gpu swiftshader_indirect
117-
-noaudio
118-
-no-boot-anim
119-
-camera-back none
120-
-camera-front none
121-
-timezone US/Pacific
129+
force-avd-creation: false
130+
disable-animations: true
131+
disable-spellchecker: true
132+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-snapshot-save
122133
script: |
123134
adb install -r -d "${{env.APK_NAME}}"
124135
maestro test "${{env.BASE_PATH}}/maestro" --debug-output "${{env.BASE_PATH}}/maestro-logs"

0 commit comments

Comments
 (0)