-
Notifications
You must be signed in to change notification settings - Fork 119
320 lines (276 loc) · 10.5 KB
/
e2e-android-test.yml
File metadata and controls
320 lines (276 loc) · 10.5 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
name: End-to-End Tests for Android
concurrency:
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true
on:
pull_request:
types: [opened, synchronize, reopened]
paths:
- '.github/workflows/e2e-android-test.yml'
- 'example/**'
- 'packages/react-native-quick-crypto/cpp/**'
- 'packages/react-native-quick-crypto/nitrogen/**'
- 'packages/react-native-quick-crypto/src/**'
- 'packages/react-native-quick-crypto/android/**'
push:
branches: [main]
paths:
- 'example/**'
- 'packages/react-native-quick-crypto/cpp/**'
- 'packages/react-native-quick-crypto/nitrogen/**'
- 'packages/react-native-quick-crypto/src/**'
- 'packages/react-native-quick-crypto/android/**'
env:
EMULATOR_API_LEVEL: 34
jobs:
# ============================================================================
# Build Job - Gradle build + lint (runs in parallel with AVD setup)
# ============================================================================
build:
name: Build
runs-on: ubuntu-latest
env:
GRADLE_OPTS: '-Dorg.gradle.daemon=false -Dorg.gradle.caching=true'
steps:
- name: Maximize build space
uses: AdityaGarg8/remove-unwanted-software@v5
with:
remove-dotnet: 'true'
remove-haskell: 'true'
remove-codeql: 'true'
remove-docker-images: 'true'
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '20'
- name: Install Bun
uses: ./.github/actions/setup-bun
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
- name: Install System Dependencies
run: |
sudo apt-get update
sudo apt-get install -y libssl-dev pkg-config
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Install Dependencies
run: bun install
- name: Restore Gradle cache
uses: actions/cache/restore@v5
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
example/android/.gradle
example/android/build
example/android/app/.cxx
example/android/app/build
packages/react-native-quick-crypto/android/.cxx
packages/react-native-quick-crypto/android/build
node_modules/.bun/react-native-nitro-modules*/node_modules/react-native-nitro-modules/android/.cxx
node_modules/.bun/react-native-nitro-modules*/node_modules/react-native-nitro-modules/android/build
key: ${{ runner.os }}-gradle-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build Android App
working-directory: ./example/android
run: |
echo "Building Android app (x86_64 only)..."
./gradlew :app:assembleDebug -PreactNativeArchitectures=x86_64 --build-cache 2>&1 | tee $HOME/android-build.log
- name: Run Gradle Lint
working-directory: ./example/android
run: ./gradlew :react-native-quick-crypto:lintDebug -PreactNativeArchitectures=x86_64
- name: Parse Gradle Lint Report
uses: yutailang0119/action-android-lint@v4
with:
report-path: packages/react-native-quick-crypto/android/build/reports/lint-results-debug.xml
- name: Stop Gradle Daemon
if: always()
working-directory: ./example/android
run: ./gradlew --stop
- name: Upload APK
uses: actions/upload-artifact@v4
with:
name: android-apk
path: example/android/app/build/outputs/apk/debug/app-debug.apk
retention-days: 1
- name: Upload Build Log
if: always()
uses: actions/upload-artifact@v4
with:
name: android-build-log
path: ~/android-build.log
retention-days: 5
- name: Save Gradle cache
if: always()
uses: actions/cache/save@v5
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
example/android/.gradle
example/android/build
example/android/app/.cxx
example/android/app/build
packages/react-native-quick-crypto/android/.cxx
packages/react-native-quick-crypto/android/build
node_modules/.bun/react-native-nitro-modules*/node_modules/react-native-nitro-modules/android/.cxx
node_modules/.bun/react-native-nitro-modules*/node_modules/react-native-nitro-modules/android/build
key: ${{ runner.os }}-gradle-${{ github.run_id }}
# ============================================================================
# AVD Job - Create and cache emulator snapshot (runs in parallel with build)
# ============================================================================
avd:
name: Emulator
runs-on: ubuntu-latest
steps:
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- 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: Restore AVD cache
uses: actions/cache/restore@v5
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-pixel7pro-${{ env.EMULATOR_API_LEVEL }}-${{ github.run_id }}
restore-keys: |
avd-pixel7pro-${{ env.EMULATOR_API_LEVEL }}-
- 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: ${{ env.EMULATOR_API_LEVEL }}
arch: x86_64
profile: pixel_7_pro
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-metrics
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- name: Save AVD cache
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@v5
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-pixel7pro-${{ env.EMULATOR_API_LEVEL }}-${{ github.run_id }}
# ============================================================================
# Test Job - Run E2E tests (needs both build and AVD)
# ============================================================================
test:
name: Test
needs: [build, avd]
runs-on: ubuntu-latest
env:
OUTPUT_DIR: ~/output
steps:
- name: Checkout
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version: '20'
- name: Install Bun
uses: ./.github/actions/setup-bun
- name: Create Directories
run: |
mkdir -p $HOME/output
mkdir -p $HOME/.maestro/tests/
- name: Setup Android SDK
uses: android-actions/setup-android@v3
- name: Restore node_modules cache
uses: actions/cache/restore@v5
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-node-modules-
- name: Install Dependencies
run: bun install
- name: Save node_modules cache
uses: actions/cache/save@v5
with:
path: node_modules
key: ${{ runner.os }}-node-modules-${{ github.run_id }}
- name: Download APK
uses: actions/download-artifact@v4
with:
name: android-apk
path: example/android/app/build/outputs/apk/debug/
- name: Install Maestro CLI
run: |
export MAESTRO_VERSION=2.0.10
curl -Ls "https://get.maestro.mobile.dev" | bash
echo "$HOME/.maestro/bin" >> $GITHUB_PATH
- 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: Restore AVD cache
uses: actions/cache/restore@v5
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-pixel7pro-${{ env.EMULATOR_API_LEVEL }}-${{ github.run_id }}
restore-keys: |
avd-pixel7pro-${{ env.EMULATOR_API_LEVEL }}-
- name: Run E2E Tests
uses: reactivecircus/android-emulator-runner@v2
id: test_android
continue-on-error: true
with:
api-level: ${{ env.EMULATOR_API_LEVEL }}
arch: x86_64
profile: pixel_7_pro
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-metrics
disable-animations: true
working-directory: ./example
script: ./test/e2e/scripts/test-android.sh
- name: Collect Screenshots
if: always()
run: |
mkdir -p $HOME/output/screenshots
LATEST_SCREENSHOT=$(find $HOME/output -name "screenshot-*.png" -type f 2>/dev/null | sort -r | head -1)
if [ -n "$LATEST_SCREENSHOT" ]; then
echo "Copying screenshot from $LATEST_SCREENSHOT to screenshots/android-test-result.png"
cp "$LATEST_SCREENSHOT" $HOME/output/screenshots/android-test-result.png
else
echo "No screenshot found to copy"
fi
- name: Post Maestro Screenshot to PR
if: always()
uses: ./.github/actions/post-maestro-screenshot
with:
platform: android
github-token: ${{ secrets.GITHUB_TOKEN }}
test-outcome: ${{ steps.test_android.outcome }}
imgbb-api-key: ${{ secrets.IMGBB_API_KEY }}
- name: Upload Test Output
if: always()
uses: actions/upload-artifact@v4
with:
name: e2e-android-test-output
path: |
${{ env.OUTPUT_DIR }}/*.log
${{ env.OUTPUT_DIR }}/screenshots/*.png
retention-days: 5
- name: Exit with Test Result
if: always()
run: |
if [ "${{ steps.test_android.outcome }}" != "success" ]; then
exit 1
fi