-
-
Notifications
You must be signed in to change notification settings - Fork 1
340 lines (301 loc) · 13.1 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
name: CI
on:
push
concurrency:
# Documentation suggests ${{ github.head_ref }}, but that's only available on pull_request/pull_request_target triggers, so using ${{ github.ref }}.
# On main, we want all builds to complete even if merging happens faster to make it easier to discover at which point something broke.
# More info: https://stackoverflow.com/a/68422069/253468:
group: ${{ github.ref == 'refs/heads/main' && format('ci-main-{0}', github.sha) || format('ci-{0}', github.ref) }}
cancel-in-progress: true
jobs:
build:
name: 🔨 Build & Verify
runs-on: ubuntu-latest
# A local build took 20 seconds, CI takes 3 minutes with setup.
# Because it's cloud, give it a bit of a buffer and constrain.
timeout-minutes: 10
steps:
- name: Set up JDK 17.
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
- name: Set up Android SDK.
uses: android-actions/setup-android@v2
- name: Set up Android SDK components.
run: |
# The following are already done by setup-android@v2 action:
# sdkmanager --install "cmdline-tools;latest"
# sdkmanager --install "tools"
# sdkmanager --install "platform-tools"
# Install Android API used to build the project.
echo sdkmanager --install "platforms;android-33"
sdkmanager --install "platforms;android-33"
- name: Checkout ${{ github.ref }} branch in ${{ github.repository }} repository.
uses: actions/checkout@v3
- name: Register problem matchers.
run: echo "::add-matcher::.github/problemMatchers.json"
- name: Validate Gradle Wrapper JARs.
uses: gradle/wrapper-validation-action@v1
- name: Build & Verify project using Gradle.
id: gradle
run: >
./gradlew
--no-daemon
--no-build-cache
--stacktrace
--continue
--scan
assemble
check
detekt
detektMain
detektTest
detektReportMergeSarif
detektReportMergeXml
lintReportMergeSarif
violationReportHtml
- name: Publish "Gradle" result and Build Scan URL.
if: (success() || failure()) && steps.gradle != null && steps.gradle.outputs.result-success != null
uses: actions/github-script@v6
with:
debug: ${{ secrets.ACTIONS_STEP_DEBUG || false }}
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: ${{ toJSON(fromJSON(steps.gradle.outputs.result-success)) }} === true ? "success" : "failure",
context: "CI / Build & Verify / Gradle",
description: ${{ toJSON(fromJSON(steps.gradle.outputs.result-text)) }},
target_url: ${{ toJSON(fromJSON(steps.gradle.outputs.build-scan-url)) }}
});
- name: Upload "Lint Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Lint Results
path: |
${{ github.workspace }}/**/build/reports/lint-results*.*
${{ github.workspace }}/build/reports/lint/merge-*.*
${{ github.workspace }}/build/reports/violations.*
- name: Publish "Code scanning results / Android Lint".
uses: github/codeql-action/upload-sarif@v2
if: success() || failure()
with:
# merge-debug.sarif and merge-release.sarif in the folder.
sarif_file: ${{ github.workspace }}/build/reports/lint/
- name: Upload "Unit Test Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Unit Test Results
path: ${{ github.workspace }}/**/build/reports/tests/*/
- name: Publish "Unit Results" check suite.
if: success() || failure()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
check_name: "🔔 Test: Unit Results"
comment_mode: off
report_individual_runs: true
test_changes_limit: 0
junit_files: ${{ github.workspace }}/**/build/test-results/*/TEST-*.xml
- name: Upload "Detekt Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Detekt Results
path: |
${{ github.workspace }}/**/build/reports/detekt/detekt.*
${{ github.workspace }}/build/reports/detekt/merge.*
- name: Publish "Code scanning results / detekt".
uses: github/codeql-action/upload-sarif@v2
if: success() || failure()
with:
sarif_file: ${{ github.workspace }}/build/reports/detekt/merge.sarif
pull_request:
name: Find PR
# Don't execute on main, it'll never be PR'd.
if: github.ref != 'refs/heads/main' && (success() || failure())
runs-on: ubuntu-latest
timeout-minutes: 1
outputs:
found: ${{ steps.current_pr.outputs.number != null }}
# Simulate github.event.pull_request.base.ref on push trigger.
base_ref: ${{ steps.current_pr.outputs.number != null && fromJSON(steps.current_pr.outputs.pr).base.ref }}
base_sha: ${{ steps.current_pr.outputs.number != null && fromJSON(steps.current_pr.outputs.pr).base.sha }}
# Simulate github.event.pull_request.head.ref on push trigger.
head_ref: ${{ steps.current_pr.outputs.number != null && fromJSON(steps.current_pr.outputs.pr).head.ref }}
head_sha: ${{ steps.current_pr.outputs.number != null && fromJSON(steps.current_pr.outputs.pr).head.sha }}
steps:
- name: "Determine which PR this commit belongs to, so we can clone its base branch for comparison."
id: current_pr
uses: 8BitJonny/gh-get-current-pr@v2.2.0
- name: "Pull Request #${{ steps.current_pr.outputs.number }}"
run: true
record-base:
name: 📸 Screenshot Tests / Record
needs: pull_request
# Don't execute on main, as it'll just verify against itself.
if: github.ref != 'refs/heads/main' && needs.pull_request.outputs.found == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Set up JDK 17.
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
- name: Set up Android SDK.
uses: android-actions/setup-android@v2
- name: Set up Android SDK components.
run: |
# The following are already done by setup-android@v2 action:
# sdkmanager --install "cmdline-tools;latest"
# sdkmanager --install "tools"
# sdkmanager --install "platform-tools"
# Install Android API used to build the project.
echo sdkmanager --install "platforms;android-33"
sdkmanager --install "platforms;android-33"
- name: Checkout ${{ needs.pull_request.outputs.base_ref }} branch in ${{ github.repository }} repository.
uses: actions/checkout@v3
with:
ref: ${{ format('refs/heads/{0}', needs.pull_request.outputs.base_ref) }}
- name: Validate Gradle Wrapper JARs.
uses: gradle/wrapper-validation-action@v1
- name: Record screenshots golden values for ${{ needs.pull_request.outputs.base_ref }}.
id: gradle
run: >
./gradlew
--no-daemon
--no-build-cache
--stacktrace
--continue
--scan
recordPaparazziDebug
-Pnet.twisterrob.build.screenshot-tests=true
- name: Publish "Gradle" result and Build Scan URL.
if: (success() || failure()) && steps.gradle != null && steps.gradle.outputs.result-success != null
uses: actions/github-script@v6
with:
debug: ${{ secrets.ACTIONS_STEP_DEBUG || false }}
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: ${{ toJSON(fromJSON(steps.gradle.outputs.result-success)) }} === true ? "success" : "failure",
context: "CI / Screenshot Tests / Record / Gradle",
description: ${{ toJSON(fromJSON(steps.gradle.outputs.result-text)) }},
target_url: ${{ toJSON(fromJSON(steps.gradle.outputs.build-scan-url)) }}
});
- name: Upload "Screenshot Golden Values" artifact.
if: success()
uses: actions/upload-artifact@v3
with:
name: Screenshot Golden Values
path: |
${{ github.workspace }}/**/src/test/snapshots/images/*.png
- name: Upload "Screenshot Record Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Screenshot Record Results
path: |
${{ github.workspace }}/**/build/reports/tests/*/
${{ github.workspace }}/**/build/reports/paparazzi/
${{ github.workspace }}/**/build/test-results/*/TEST-*.xml
- name: Publish "Screenshot Record Results" check suite.
if: success() || failure()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
check_name: "🔔 Test: Screenshot Record Results"
comment_mode: off
report_individual_runs: true
test_changes_limit: 0
junit_files: ${{ github.workspace }}/**/build/test-results/*/TEST-*.xml
verify-pr:
name: 🧪 Screenshot Tests / Verify
needs:
# If build fails, there's not much point in running screenshot tests.
- build
# Need to run after recording base branch golden values to compare against them.
- record-base
- pull_request
if: needs.pull_request.outputs.found == 'true'
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Set up JDK 17.
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: 17
- name: Set up Android SDK.
uses: android-actions/setup-android@v2
- name: Set up Android SDK components.
run: |
# The following are already done by setup-android@v2 action:
# sdkmanager --install "cmdline-tools;latest"
# sdkmanager --install "tools"
# sdkmanager --install "platform-tools"
# Install Android API used to build the project.
echo sdkmanager --install "platforms;android-33"
sdkmanager --install "platforms;android-33"
- name: Checkout ${{ needs.pull_request.outputs.head_ref }} branch in ${{ github.repository }} repository.
uses: actions/checkout@v3
with:
ref: ${{ format('refs/heads/{0}', needs.pull_request.outputs.head_ref) }}
- name: Validate Gradle Wrapper JARs.
uses: gradle/wrapper-validation-action@v1
- name: Download 'Screenshot Golden Values' artifact.
uses: actions/download-artifact@v3
with:
name: Screenshot Golden Values
- name: Run screenshot tests to verify ${{ needs.pull_request.outputs.head_ref }}.
id: gradle
run: >
./gradlew
--no-daemon
--no-build-cache
--stacktrace
--continue
--scan
verifyPaparazziDebug
-Pnet.twisterrob.build.screenshot-tests=true
- name: Publish "Gradle" result and Build Scan URL.
if: (success() || failure()) && steps.gradle != null && steps.gradle.outputs.result-success != null
uses: actions/github-script@v6
with:
debug: ${{ secrets.ACTIONS_STEP_DEBUG || false }}
script: |
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: ${{ toJSON(fromJSON(steps.gradle.outputs.result-success)) }} === true ? "success" : "failure",
context: "CI / Screenshot Tests / Verify / Gradle",
description: ${{ toJSON(fromJSON(steps.gradle.outputs.result-text)) }},
target_url: ${{ toJSON(fromJSON(steps.gradle.outputs.build-scan-url)) }}
});
- name: Upload "Screenshot Test Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Screenshot Test Results
# Notice that `${{ github.workspace }}/**/build/reports/paparazzi/` folder is not uploaded,
# that's because Paparazzi doesn't generate a report on failure...
path: |
${{ github.workspace }}/**/build/reports/tests/*/
${{ github.workspace }}/**/build/test-results/*/TEST-*.xml
${{ github.workspace }}/**/out/failures/delta-*.png
${{ github.workspace }}/**/out/failures/*.png
- name: Publish "Screenshot Verify Results" check suite.
if: success() || failure()
uses: EnricoMi/publish-unit-test-result-action@v2
with:
check_name: "🔔 Test: Screenshot Verify Results"
comment_mode: off
report_individual_runs: true
test_changes_limit: 0
junit_files: ${{ github.workspace }}/**/build/test-results/*/TEST-*.xml