Repository navigation
257 lines (218 loc) · 9.64 KB
/
Copy pathandroid-tests.yml
File metadata and controls
257 lines (218 loc) · 9.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
name: Android Tests
# Runs on PRs (pre-merge feedback) and in the merge queue (merge_group),
# which is the gate before a PR lands. No secrets here, so it's safe on
# fork/Dependabot PRs too.
on:
pull_request:
branches: [main]
merge_group:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
env:
NODEJS_MOBILE_VERSION: v24.19.0-2
# NDK the generated example app builds against. Sourced from React Native's
# node_modules/react-native/gradle/libs.versions.toml (Expo's default); keep
# in sync on RN bumps. We install it explicitly (with retry) so Gradle never
# auto-downloads it mid-build, where a corrupt sdkmanager zip would fail hard.
NDK_VERSION: 27.1.12297006
jobs:
# Defer the slow instrumented suite to the merge queue: skip it on a plain PR
# (it then reports as skipped, which satisfies the required check) and run it
# on merge_group, on manual dispatch, or on a PR labeled `run-e2e`. The fast
# JVM unit tests below stay on every PR.
changes:
permissions:
contents: read
pull-requests: read
uses: ./.github/workflows/detect-heavy-ci.yml
unit-tests:
name: JVM Unit Tests
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
with:
node-version-file: package.json
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4.0.4
- name: Cache nodejs-mobile binaries
id: cache-libnode
uses: actions/cache@v6
with:
path: android/libnode
# hashFiles(...) folds the BASE_URL (defined inside the
# download script) into the cache key, so any swap of the
# source repo automatically invalidates stale caches.
key: nodejs-mobile-${{ env.NODEJS_MOBILE_VERSION }}-android-${{ hashFiles('scripts/download-nodejs-mobile.sh') }}
- name: Download nodejs-mobile binaries
if: steps.cache-libnode.outputs.cache-hit != 'true'
run: ./scripts/download-nodejs-mobile.sh
# strict-allow-scripts (skip dependency install scripts via the committed
# allowlists) requires npm >= 11.16; the runner image ships an older 11.x.
- name: Upgrade npm
run: npm install -g npm@latest
- name: Install npm dependencies
run: npm install && cd apps/integration && npm install
- name: Expo prebuild (generates apps/integration/android)
run: cd apps/integration && npx expo prebuild --platform android --no-install
- name: Setup Gradle
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
- name: Run JVM unit tests
run: |
cd apps/integration/android
./gradlew :comapeo-core-react-native:testDebugUnitTest --no-daemon
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: unit-test-results
path: |
android/build/reports/tests/
android/build/test-results/
instrumented-tests:
# The "(30)" is baked into the name (not a matrix) on purpose: a *matrix*
# job skipped by `if` reports its check without the matrix suffix, so the
# required `Instrumented Tests (30)` context would never report and the PR
# would hang on "Expected — Waiting". A plain job reports the exact name as
# skipped (= passing) when gated out.
name: Instrumented Tests (30)
needs: [changes]
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@v7
- name: Free disk space
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be # v1.3.1
with:
android: false
dotnet: true
haskell: true
large-packages: true
docker-images: true
tool-cache: false
swap-storage: false
- uses: actions/setup-node@v7
with:
node-version-file: package.json
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: 17
- name: Setup Android SDK
uses: android-actions/setup-android@be39fa834029ff78f1a44aa3bb0819b8fc2bd8fd # v4.0.4
- name: Clean up unused SDK components
run: |
# Remove pre-installed NDKs (~1-2GB each) — Gradle auto-installs what it needs
rm -rf "$ANDROID_HOME/ndk"
# Remove unused platform versions
for dir in "$ANDROID_HOME/platforms"/*/; do
plat=$(basename "$dir")
case "$plat" in
android-34|android-30) ;; # keep what we need
*) echo "Removing unused platform $plat"; rm -rf "$dir" ;;
esac
done
echo "=== Disk space after cleanup ==="
df -h /
# Cache + retry the one NDK the build needs. A cache hit skips the download
# entirely; on a miss we install it ourselves with retries so a corrupt
# sdkmanager zip ("Error on ZipFile unknown archive") no longer fails the
# job — previously Gradle auto-installed it mid-build with no retry.
- name: Cache Android NDK
id: cache-ndk
uses: actions/cache@v6
with:
# ANDROID_HOME on GitHub-hosted ubuntu runners; the install step below
# uses $ANDROID_HOME directly, which resolves to the same location.
path: /usr/local/lib/android/sdk/ndk/${{ env.NDK_VERSION }}
key: android-ndk-${{ env.NDK_VERSION }}
- name: Install Android NDK (retry on corrupt download)
if: steps.cache-ndk.outputs.cache-hit != 'true'
run: |
for attempt in 1 2 3; do
if yes | sdkmanager "ndk;${NDK_VERSION}"; then
exit 0
fi
echo "::warning::NDK install attempt ${attempt} failed; purging partial download and retrying"
rm -rf "${ANDROID_HOME}/ndk/${NDK_VERSION}"
sleep 10
done
echo "::error::NDK ${NDK_VERSION} install failed after 3 attempts"
exit 1
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Cache nodejs-mobile binaries
id: cache-libnode
uses: actions/cache@v6
with:
path: android/libnode
# hashFiles(...) folds the BASE_URL (defined inside the
# download script) into the cache key, so any swap of the
# source repo automatically invalidates stale caches.
key: nodejs-mobile-${{ env.NODEJS_MOBILE_VERSION }}-android-${{ hashFiles('scripts/download-nodejs-mobile.sh') }}
- name: Download nodejs-mobile binaries
if: steps.cache-libnode.outputs.cache-hit != 'true'
run: ./scripts/download-nodejs-mobile.sh
# strict-allow-scripts (skip dependency install scripts via the committed
# allowlists) requires npm >= 11.16; the runner image ships an older 11.x.
- name: Upgrade npm
run: npm install -g npm@latest
- name: Install npm dependencies
run: npm install && cd apps/integration && npm install
- name: Build backend
run: npm run backend:build
- name: Expo prebuild (generates apps/integration/android)
run: cd apps/integration && npx expo prebuild --platform android --no-install
- name: Setup Gradle
uses: gradle/actions/setup-gradle@9c971963bec38e04b3d30dcc455b5382be2fdbfb # v6.3.0
- name: Build test APKs
run: |
cd apps/integration/android
./gradlew :comapeo-core-react-native:assembleDebugAndroidTest :app:assembleDebugAndroidTest --no-daemon -PreactNativeArchitectures=x86_64
# Snapshot caching was tried but is not portable across GitHub
# runner machines on this google_atd image: restored snapshots
# boot but system_server is dead-on-arrival (DeadSystemException
# on the first adb input call). Cold boot every run instead.
- name: Run instrumented tests
timeout-minutes: 15
uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # v2.38.0
with:
api-level: 30
target: google_atd
arch: x86_64
force-avd-creation: false
ram-size: 4096M
emulator-options:
-no-snapshot-save -no-window -gpu swiftshader_indirect
-noaudio -no-boot-anim
disable-animations: false
script: |
adb shell settings put global window_animation_scale 0.0
adb shell settings put global transition_animation_scale 0.0
adb shell settings put global animator_duration_scale 0.0
# -i prints per-test STARTED/PASSED/FAILED so a hanging test is
# identifiable
cd apps/integration/android && ./gradlew :comapeo-core-react-native:connectedDebugAndroidTest :app:connectedDebugAndroidTest --no-daemon -i -PreactNativeArchitectures=x86_64
- name: Upload test results
if: always()
uses: actions/upload-artifact@v7
with:
name: instrumented-test-results-api30
path: |
android/build/reports/androidTests/
android/build/outputs/androidTest-results/
apps/integration/android/app/build/reports/androidTests/
apps/integration/android/app/build/outputs/androidTest-results/