-
-
Notifications
You must be signed in to change notification settings - Fork 0
225 lines (205 loc) · 8.59 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
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:
validate:
name: 🦺 Validation
runs-on: ubuntu-latest
timeout-minutes: 2
steps:
- name: Checkout ${{ github.ref }} branch in ${{ github.repository }} repository.
uses: actions/checkout@v3
- name: Validate Gradle Wrapper JARs.
uses: gradle/wrapper-validation-action@v1
build:
name: 🔨 Build & Verify
needs: validate
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: 15
steps:
- name: Set up JDK 17.
uses: actions/setup-java@v3
with:
java-version: 17
distribution: zulu
- name: Checkout ${{ github.ref }} branch in ${{ github.repository }} repository.
uses: actions/checkout@v3
- name: Build & Verify project.
id: gradle
run: >
./gradlew
--no-daemon
--no-build-cache
--continue
--stacktrace
--scan
assemble
lint
detekt
test
check
violationReportHtml
violationCountFile
- 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: |
const description = ${{ toJSON(fromJSON(steps.gradle.outputs.result-text)) }}
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",
// Truncate to be sure it fits:
// > HttpError: Validation Failed: {"resource":"Status","code":"custom",
// > "field":"description","message":"description is too long (maximum is 140 characters)"}
// Max length is 140, give some space for potential Unicode.
description: description.length > 130
? `${description.substring(0, 130)}…`
: description,
target_url: ${{ steps.gradle.outputs.build-scan-url && toJSON(fromJSON(steps.gradle.outputs.build-scan-url)) || 'undefined' }}
});
- name: Upload "Lint Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Lint Results HTMLs
path: ${{ github.workspace }}/**/build/reports/lint-results*.html
- name: Upload "Lint Merged Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Lint Merged Results
path: ${{ github.workspace }}/build/reports/violations.*
- name: Fail if there are violations.
if: success() || failure()
run: |
count=$(cat "${{ github.workspace }}/build/reports/violations.count")
if [[ "$count" != "0" ]]; then
echo "There were $count violations"
exit 1
else
echo "No violations found."
exit 0
fi
- 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.*
- name: Upload "Detekt Merged Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Detekt Merged Results
path: ${{ github.workspace }}/build/reports/detekt/merge.*
- name: Publish "detekt" GitHub Code Scanning analysis.
uses: github/codeql-action/upload-sarif@v2
if: success() || failure()
with:
checkout_path: ${{ github.workspace }}
sarif_file: ${{ github.workspace }}/build/reports/detekt/merge.sarif
instrumentation:
name: 🧪 Instrumentation Tests
needs: validate
runs-on: macos-latest
timeout-minutes: 30
steps:
- name: Set up JDK 17.
uses: actions/setup-java@v3
with:
java-version: 17
distribution: zulu
- name: Checkout ${{ github.ref }} branch in ${{ github.repository }} repository.
uses: actions/checkout@v3
- name: Run Instrumentation Tests on emulator.
id: gradle
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 29
script: >
./gradlew
--no-daemon
--no-build-cache
--continue
--stacktrace
--scan
connectedCheck
mergeAndroidReports
- 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: |
const description = ${{ toJSON(fromJSON(steps.gradle.outputs.result-text)) }}
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 / Instrumentation Tests / Gradle",
// Truncate to be sure it fits:
// > HttpError: Validation Failed: {"resource":"Status","code":"custom",
// > "field":"description","message":"description is too long (maximum is 140 characters)"}
// Max length is 140, give some space for potential Unicode.
description: description.length > 130
? `${description.substring(0, 130)}…`
: description,
target_url: ${{ steps.gradle.outputs.build-scan-url && toJSON(fromJSON(steps.gradle.outputs.build-scan-url)) || 'undefined' }}
});
- name: Upload "Instrumentation Test Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Instrumentation Test Results
# Exclude names with colon: https://issuetracker.google.com/issues/223643506
path: |
${{ github.workspace }}/**/build/outputs/androidTest-results/connected/
${{ github.workspace }}/**/build/outputs/connected_android_test_additional_output/
!**/*:*
- name: Upload "Instrumentation Merged Results" artifact.
if: success() || failure()
uses: actions/upload-artifact@v3
with:
name: Instrumentation Merged Results
# Exclude names with colon: https://issuetracker.google.com/issues/223643506
path: |
${{ github.workspace }}/build/androidTest-results/
!**/*:*
- name: Publish "Instrumentation Results" check suite.
if: success() || failure()
uses: EnricoMi/publish-unit-test-result-action/composite@v2
with:
check_name: "🔔 Test: Instrumentation Results"
comment_mode: off
report_individual_runs: true
test_changes_limit: 0
junit_files: ${{ github.workspace }}/**/build/outputs/androidTest-results/connected/TEST-*.xml