-
Notifications
You must be signed in to change notification settings - Fork 11
456 lines (383 loc) · 16.9 KB
/
ci.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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
name: CI
on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 8 * * *'
workflow_dispatch:
jobs:
build-cfg:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
if ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch') }}
then
MATRIX='
{"sdk": "21"},
{"sdk": "22"},
{"sdk": "23"},
{"sdk": "24"},
{"sdk": "25"},
{"sdk": "26"},
{"sdk": "27"},
{"sdk": "28"},
{"sdk": "29"},
{"sdk": "30"},
{"sdk": "31"},
{"sdk": "32"},
{"sdk": "33"},
{"sdk": "34"},
{"sdk": "35"}
'
else
MATRIX='
{"sdk": "21"},
{"sdk": "35"}
'
fi
echo "matrix={\"include\":[${MATRIX//$'\n'/}]}" >> $GITHUB_OUTPUT
build-cfg-check:
needs: build-cfg
runs-on: ubuntu-latest
steps:
- name: Check matrix configuration
run: |
matrix='${{ needs.build-cfg.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
build:
needs: build-cfg
runs-on: ubuntu-latest
concurrency:
group: ci-build-${{ github.event_name }}-${{ github.ref }}-${{ matrix.sdk }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-cfg.outputs.matrix) }}
steps:
- name: Set ANDROID_USER_HOME
run: echo "ANDROID_USER_HOME=$HOME/.android" >> $GITHUB_ENV
- name: Enable KVM group perms
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
ls /dev/kvm
- name: Download emulator package
run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager emulator
- name: Checkout
uses: actions/checkout@v4
with:
# Use PAT if on a pull request from the main repo, in preparation for auto-committing fixes
# Otherwise use the default token
token: ${{ (matrix.sdk == '35' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' && secrets.PAT) || github.token}}
- name: Copy ci-gradle.properties
run: |
mkdir -p ~/.gradle
cp .github/ci-gradle.properties ~/.gradle/gradle.properties
- name: Configure JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
- name: Accept license
run: echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_SDK_ROOT/licenses/android-sdk-preview-license"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Create CI robolectric.properties
run: |
robolectric_projects=($(find . -regex ".*/src/androidUnitTest/resources/com/alexvanyo/robolectric.properties" | grep -oP '\./(.*?)/'))
for project in "${robolectric_projects[@]}"
do
mkdir "$project"src/androidUnitTest/resources/com/alexvanyo/composelife
echo sdk=${{ matrix.sdk }} > "$project"src/androidUnitTest/resources/com/alexvanyo/composelife/robolectric.properties
done
- name: Run checks
id: check
run: ./gradlew check --stacktrace
- name: Auto-commit formatting changes
if: ${{ !cancelled() && matrix.sdk == '35' && steps.check.outcome == 'failure' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Fix formatting issues
push_options: --force-with-lease
- name: Update dependency guard baseline
if: ${{ !cancelled() && matrix.sdk == '35' && steps.check.outcome == 'failure' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }}
run: ./gradlew dependencyGuardBaseline
- name: Auto-commit dependency guard baseline changes
if: ${{ !cancelled() && matrix.sdk == '35' && steps.check.outcome == 'failure' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Auto update dependency guard baseline
push_options: --force-with-lease
- name: Update screenshots
if: ${{ !cancelled() && matrix.sdk == '35' && steps.check.outcome == 'failure' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }}
run: ./gradlew recordRoborazziDebug
- name: Auto-commit screenshot changes
if: ${{ !cancelled() && matrix.sdk == '35' && steps.check.outcome == 'failure' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Auto update screenshots
push_options: --force-with-lease
- name: Update badging
if: ${{ !cancelled() && matrix.sdk == '35' && steps.check.outcome == 'failure' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }}
run: ./gradlew updateReleaseBadging
- name: Auto-commit badging changes
if: ${{ !cancelled() && matrix.sdk == '35' && steps.check.outcome == 'failure' && github.event.pull_request.head.repo.full_name == github.repository && github.event_name == 'pull_request' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: Auto update badging
push_options: --force-with-lease
- name: Upload unit test results
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: unit-test-results-${{ matrix.sdk }}
path: '**/build/test-results/*Test/**.xml'
- name: Generate code coverage
run: ./gradlew jacocoUnitTestCoverageReport --stacktrace
- name: Upload code coverage to GitHub
uses: actions/upload-artifact@v4
with:
name: unit-code-coverage-${{ matrix.sdk }}
path: build/reports/jacoco/**/*.xml
- name: Assemble
if: matrix.sdk == '35'
# Assemble with running benchmarks and generating baseline profile to ensure those compile
run: ./gradlew assemble -Pcom.alexvanyo.composelife.runBenchmarks=true -Pandroidx.baselineprofile.skipgeneration
- name: Upload APKs
if: matrix.sdk == '35'
uses: actions/upload-artifact@v4
with:
name: apks
path: "**/build/outputs/apk/**/*.apk"
codecov-unit-coverage-upload:
needs: [build, build-cfg]
if: always()
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-cfg.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download code coverage from GitHub
uses: actions/download-artifact@v4
with:
name: unit-code-coverage-${{ matrix.sdk }}
path: codecoverage
- name: List code coverage
run: ls -R codecoverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
directory: codecoverage
flags: unit,${{ matrix.sdk }}
codecov-unit-test-upload:
needs: [build, build-cfg]
if: always()
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.build-cfg.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download test results from GitHub
uses: actions/download-artifact@v4
with:
name: unit-test-results-${{ matrix.sdk }}
path: testresults
- id: test-result-files
run: |
echo -n "files=" >> $GITHUB_OUTPUT
find testresults -name "*.xml" | paste -s -d "," - >> $GITHUB_OUTPUT
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ${{ steps.test-result-files.outputs.files }}
flags: unit,${{ matrix.sdk }}
android-test-gmd-cfg:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- id: set-matrix
run: |
if ${{ github.event_name == 'schedule' || (github.event_name == 'workflow_dispatch') }}
then
MATRIX='
{"api-level": "21", "target": "aosp", "device": "nexus4"},
{"api-level": "22", "target": "aosp", "device": "nexus4"},
{"api-level": "23", "target": "aosp", "device": "nexus4"},
{"api-level": "24", "target": "aosp", "device": "nexus4"},
{"api-level": "25", "target": "aosp", "device": "nexus4"},
{"api-level": "26", "target": "aosp", "device": "nexus4"},
{"api-level": "27", "target": "aosp", "device": "pixel2"},
{"api-level": "28", "target": "aosp", "device": "pixel2"},
{"api-level": "28", "target": "wear", "device": "wearoslargeround"},
{"api-level": "28", "target": "wear", "device": "wearossquare"},
{"api-level": "29", "target": "aosp", "device": "pixel2"},
{"api-level": "30", "target": "aosp", "device": "pixel3xl"},
{"api-level": "30", "target": "aospatd", "device": "pixel2"},
{"api-level": "30", "target": "wear", "device": "wearoslargeround"},
{"api-level": "30", "target": "wear", "device": "wearossquare"},
{"api-level": "31", "target": "aospatd", "device": "pixel2"},
{"api-level": "32", "target": "aospatd", "device": "pixel6pro"},
{"api-level": "32", "target": "aospatd", "device": "pixeltablet"},
{"api-level": "32", "target": "desktop", "device": "mediumdesktop"},
{"api-level": "33", "target": "aospatd", "device": "pixel6pro"},
{"api-level": "33", "target": "aospatd", "device": "pixeltablet"},
{"api-level": "33", "target": "wear", "device": "wearoslargeround"},
{"api-level": "33", "target": "wear", "device": "wearossquare"},
{"api-level": "34", "target": "aospatd", "device": "pixel6pro"},
{"api-level": "34", "target": "aosptablet", "device": "pixeltablet"},
{"api-level": "34", "target": "wear", "device": "wearoslargeround"},
{"api-level": "34", "target": "wear", "device": "wearossquare"},
{"api-level": "35", "target": "google", "device": "pixel6pro"},
{"api-level": "35", "target": "googletablet", "device": "pixeltablet"}
'
else
MATRIX='
{"api-level": "23", "target": "aosp", "device": "nexus4"},
{"api-level": "34", "target": "aosp", "device": "pixel2"},
{"api-level": "30", "target": "wear", "device": "wearoslargeround"}
'
fi
echo "matrix={\"include\":[${MATRIX//$'\n'/}]}" >> $GITHUB_OUTPUT
android-test-gmd-cfg-check:
needs: android-test-gmd-cfg
runs-on: ubuntu-latest
steps:
- name: Check matrix configuration
run: |
matrix='${{ needs.android-test-gmd-cfg.outputs.matrix }}'
echo $matrix
echo $matrix | jq .
android-test-gmd:
needs: android-test-gmd-cfg
runs-on: ubuntu-latest
timeout-minutes: 120
concurrency:
group: ci-android-test-gmd-${{ github.event_name }}-${{ github.ref }}-${{ matrix.device }}-${{ matrix.api-level }}
cancel-in-progress: true
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.android-test-gmd-cfg.outputs.matrix) }}
steps:
- name: Set ANDROID_USER_HOME
run: echo "ANDROID_USER_HOME=$HOME/.android" >> $GITHUB_ENV
- name: Enable KVM group perms
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
ls /dev/kvm
- name: Download emulator package
run: $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager emulator
- name: Checkout
uses: actions/checkout@v4
- name: Copy ci-gradle.properties
run: |
mkdir -p ~/.gradle
cp .github/ci-gradle.properties ~/.gradle/gradle.properties
- name: Update gradle.properties with chosen device
run: |
echo "com.alexvanyo.composelife.enabledGradleManagedDevices=${{ matrix.target }}${{ matrix.device }}api${{ matrix.api-level }}" > ~/.gradle/gradle.properties
- name: Cache AVD
if: false
uses: actions/cache@v4
id: avd-cache
with:
path: |
${{ env.ANDROID_USER_HOME }}/avd/gradle-managed/*
${{ env.ANDROID_USER_HOME }}/adb*
key: v5-${{ runner.os }}-gmd-${{ matrix.device }}-${{ matrix.api-level }}-${{ matrix.target }}
- name: Configure JDK
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: 21
- name: Accept licenses
run: yes | $ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager --licenses
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Run device checks
run: |
# run the tests, with one retry attempt
run_tests () { ./gradlew ${{ matrix.target }}${{ matrix.device }}api${{ matrix.api-level }}Check --no-parallel -Dorg.gradle.workers.max=1 --stacktrace; }
(echo "==== Attempt 1 ====" && run_tests) || (echo "==== Attempt 2 ====" && run_tests) || (echo "==== Both attempts failed ====" && exit 1)
- name: Upload device test results
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: device-test-results-${{ matrix.target }}-${{ matrix.device }}-${{ matrix.api-level }}
path: '**/build/outputs/androidTest-results/managedDevice/**/TEST*.xml'
- name: Generate coverage report
run: |
run_tests () { ./gradlew jacocoAndroidTestCoverageReport --stacktrace; }
(echo "==== Attempt 1 ====" && run_tests) || (echo "==== Attempt 2 ====" && run_tests) || (echo "==== Both attempts failed ====" && exit 1)
- name: Upload code coverage to GitHub
uses: actions/upload-artifact@v4
with:
name: device-code-coverage-${{ matrix.target }}-${{ matrix.device }}-${{ matrix.api-level }}
path: build/reports/jacoco/**/*.xml
codecov-device-coverage-upload:
needs: [android-test-gmd, android-test-gmd-cfg]
if: always()
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.android-test-gmd-cfg.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download code coverage from GitHub
uses: actions/download-artifact@v4
with:
name: device-code-coverage-${{ matrix.target }}-${{ matrix.device }}-${{ matrix.api-level }}
path: codecoverage
- name: List code coverage
run: ls -R codecoverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
directory: codecoverage
flags: device,${{ matrix.target }}-${{ matrix.device }}-${{ matrix.api-level }}
codecov-device-test-upload:
needs: [android-test-gmd, android-test-gmd-cfg]
if: always()
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.android-test-gmd-cfg.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download test results from GitHub
uses: actions/download-artifact@v4
with:
name: device-test-results-${{ matrix.target }}-${{ matrix.device }}-${{ matrix.api-level }}
path: testresults
- id: test-result-files
run: |
echo -n "files=" >> $GITHUB_OUTPUT
find testresults -name "*.xml" | paste -s -d "," - >> $GITHUB_OUTPUT
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
files: ${{ steps.test-result-files.outputs.files }}
flags: device,${{ matrix.target }}-${{ matrix.device }}-${{ matrix.api-level }}