-
Notifications
You must be signed in to change notification settings - Fork 2.2k
257 lines (231 loc) · 9.59 KB
/
tests_e2e_android.yml
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: Testing E2E Android
on:
workflow_dispatch:
inputs:
clearCaches:
description: "Clear workflow caches where possible"
required: false
type: string
pull_request:
branches:
- '**'
paths-ignore:
- 'docs/**'
- 'website/**'
- '.spellcheck.dict.txt'
- '**/*.md'
push:
branches:
- main
- v14-release
paths-ignore:
- 'docs/**'
- 'website/**'
- '.spellcheck.dict.txt'
- '**/*.md'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
android:
name: Android
runs-on: macos-13
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
# Refactor to make these dynamic with a low/high bracket only on schedule, not push
# For now this is just the fastest combo (api/arch/target/snapshot-warm-time) based on testing
api-level: [30]
arch: [x86_64]
target: [google_apis]
first-boot-delay: [600]
# This is useful for benchmarking, do 0, 1, 2, etc (up to 256 max job-per-matrix limit) for averages
iteration: [0]
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
EMULATOR_COMMAND: "-avd TestingAVD -noaudio -gpu swiftshader_indirect -camera-back none -no-snapshot -no-window -no-boot-anim -nojni -memory 2048 -timezone 'Europe/London' -cores 2"
EMULATOR_EXECUTABLE: qemu-system-x86_64-headless
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 50
# Set up tool versions
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Configure JDK
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
# Set path variables needed for caches
- name: Set workflow variables
id: workflow-variables
run: |
echo "metro-cache=$HOME/.metro" >> $GITHUB_OUTPUT
echo "yarn-cache-dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
echo "tempdir=$TMPDIR" >> $GITHUB_OUTPUT
- uses: actions/cache/restore@v3
name: Yarn Cache Restore
id: yarn-cache
with:
path: ${{ steps.workflow-variables.outputs.yarn-cache-dir }}
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('yarn.lock') }}
restore-keys: ${{ runner.os }}-yarn-v1
- name: Yarn Install
uses: nick-fields/retry@v2
with:
timeout_minutes: 15
retry_wait_seconds: 60
max_attempts: 3
command: DETOX_DISABLE_POSTINSTALL=1 yarn --no-audit --prefer-offline
- name: Cache Firestore Emulator
uses: actions/cache@v3
with:
path: ~/.cache/firebase/emulators
key: firebase-emulators-v1-${{ github.run_id }}
restore-keys: firebase-emulators-v1
- name: Start Firestore Emulator
run: yarn tests:emulator:start-ci
- uses: actions/cache@v3
name: Gradle Cache
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-v1-${{ hashFiles('yarn.lock', 'tests/android/build.gradle', 'tests/android/app/build.gradle') }}
restore-keys: ${{ runner.os }}-gradle-v1
# This appears to be 'Cache Size: ~1230 MB (1290026823 B)' based on watching action logs
# Repo limit is 10GB; branch caches are independent; branches may read default branch cache.
# We don't want branches to evict main branch snapshot, so save on main, read-only all else
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}-${{ matrix.arch }}-${{matrix.target}}-v1-${{ github.event.inputs.clearCaches }}
restore-keys: |
avd-${{ matrix.api-level }}-${{ matrix.arch }}-${{matrix.target}}-v1
- name: Clear Caches Optionally
if: "${{ github.event.inputs.clearCaches != '' }}"
shell: bash
run: |
du -sk ~/.gradle
du -sk ~/.android
rm -fr ~/.gradle
rm -fr ~/.android
du -sk ~/.gradle || echo ~/.gradle is gone
du -sk ~/.android || echo ~/.android is gone
- name: Build Android App
uses: nick-fields/retry@v2
with:
timeout_minutes: 25
retry_wait_seconds: 60
max_attempts: 3
command: yarn tests:android:build
- name: Metro Bundler Cache
uses: actions/cache@v3
with:
path: ${{ steps.workflow-variables.outputs.metro-cache }}
key: ${{ runner.os }}-metro-v1-${{ github.run_id }}
restore-keys: ${{ runner.os }}-metro-v1
- name: Pre-fetch Javascript bundle
# Prebuild the bundle so that's fast when the app starts.
run: |
nohup yarn tests:packager:jet-ci &
printf 'Waiting for packager to come online'
until curl --output /dev/null --silent --head --fail http://localhost:8081/status; do
printf '.'
sleep 2
done
echo "Packager is online! Preparing javascript bundle..."
curl --output /dev/null --silent --head --fail "http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&inlineSourceMap=true"
echo "...javascript bundle ready."
- name: AVD Boot and Snapshot Creation
# Only generate a snapshot with a cache miss
# Comment the if out to generate snapshots on branch for performance testing
if: "${{ github.event.inputs.clearCaches != '' || (steps.avd-cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/main') }}"
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
avd-name: TestingAVD
force-avd-creation: false
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
sdcard-path-or-size: 100M
disable-animations: true
# Give the emulator a little time to run and do first boot stuff before taking snapshot
script: |
$ANDROID_HOME/platform-tools/adb logcat '*:D' -d > adb-snapshot-log.txt
$ANDROID_HOME/platform-tools/adb logcat --clear
echo "Generated AVD snapshot for caching."
# This step is separate so pure install time may be calculated as a step
- name: Emulator Snapshot After Firstboot Warmup
# Only generate a snapshot for saving with a cache miss
# Switch the if statements via comment if generating snapshots for performance testing
# if: matrix.first-boot-delay != '0'
if: "${{ github.event.inputs.clearCaches != '' || (steps.avd-cache.outputs.cache-hit != 'true' && github.ref == 'refs/heads/main') }}"
env:
FIRST_BOOT_DELAY: ${{ matrix.first-boot-delay }}
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
avd-name: TestingAVD
force-avd-creation: false
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
sdcard-path-or-size: 100M
disable-animations: true
# Give the emulator a little time to run and do first boot stuff before taking snapshot
# The zygote restart makes sure zygote has correct heap size as a workaround for android emulator init bug
script: |
$ANDROID_HOME/platform-tools/adb shell su root "setprop ctl.restart zygote"
sleep $FIRST_BOOT_DELAY
$ANDROID_HOME/platform-tools/adb logcat '*:D' -d > adb-warmup-log.txt
$ANDROID_HOME/platform-tools/adb logcat --clear
echo "First boot warmup completed."
- name: Test Tapper
# Run this outside the emulator runner so the emulator runner does not wait on it for cleanup
run: |
nohup sh -c "until false; do $ANDROID_HOME/platform-tools/adb shell input tap 100 800; sleep 0.2; done" &
shell: bash
- name: Detox Tests
uses: reactivecircus/android-emulator-runner@v2
timeout-minutes: 60
with:
api-level: ${{ matrix.api-level }}
avd-name: TestingAVD
force-avd-creation: false
target: ${{ matrix.target }}
arch: ${{ matrix.arch }}
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
sdcard-path-or-size: 100M
disable-animations: true
# Detox uses Espresso to choreograph steps in reaction to UI events, so we need to send a stream of taps.
script: |
$ANDROID_HOME/platform-tools/adb devices
nohup sh -c "$ANDROID_HOME/platform-tools/adb logcat '*:D' > adb-log.txt" &
yarn tests:android:test-cover
yarn tests:android:test:jacoco-report
- uses: codecov/codecov-action@v3
with:
verbose: true
- uses: actions/cache/save@v3
name: Yarn Cache Save
if: "${{ github.ref == 'refs/heads/main' }}"
with:
path: ${{ steps.workflow-variables.outputs.yarn-cache-dir }}
key: ${{ runner.os }}-yarn-v1-${{ hashFiles('yarn.lock') }}
- name: Compress Emulator Log
if: always()
run: gzip -9 adb-*.txt
shell: bash
- name: Upload Emulator Log
uses: actions/upload-artifact@v3
if: always()
with:
name: adb_logs
path: adb-*.gz