-
Notifications
You must be signed in to change notification settings - Fork 39
345 lines (306 loc) · 10.9 KB
/
build_and_test.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
# vim:ai et ts=2 sts=2 sw=2:
name: Build and test
on:
pull_request:
push:
branches:
- 'master'
concurrency:
# https://docs.github.com/en/actions/using-jobs/using-concurrency
# The latest queued workflow is preferred; the ones already in progress get cancelled
# Workflows on master branch shouldn't be cancelled, that's why they are identified by commit SHA
group: ${{ github.ref == 'refs/heads/master' && format('{0}-{1}', github.workflow, github.sha) || format('{0}-{1}', github.workflow, github.ref) }}
cancel-in-progress: true
jobs:
build_and_test_with_code_coverage:
name: Build, test and upload code coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
# required for correct codecov upload
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Retrieve Kotlin version
run: |
kv=$(cat gradle/libs.versions.toml | grep '^kotlin =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KOTLIN_VERSION=$kv >> $GITHUB_ENV
shell: bash
- name: Cache konan
uses: actions/cache@v3
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}
- name: Build all
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
arguments: |
build
-x detekt
--scan
--build-cache
- name: Upload gradle reports
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: gradle-reports
path: '**/build/reports/'
retention-days: 1
- name: Upload diktat-ruleset jar
uses: actions/upload-artifact@v3
with:
name: diktat-ruleset
path: diktat-ruleset/build/libs/diktat-*.jar
# no need to store artifact longer, it is used only by dependant jobs
retention-days: 1
- name: Upload diktat-cli jar
uses: actions/upload-artifact@v3
with:
name: diktat-cli
path: diktat-cli/build/libs/diktat-cli-*.jar
# no need to store artifact longer, it is used only by dependant jobs
retention-days: 1
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
run_diktat_from_CLI:
name: Run diktat via CLI
runs-on: ${{ matrix.os }}
needs: build_and_test_with_code_coverage
strategy:
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
java-version: [8, 11]
type: [ ktlint, cli ]
steps:
- uses: actions/checkout@v3
- name: Retrieve Ktlint version
if: matrix.type == 'ktlint'
run: |
ktlint_version=$(cat gradle/libs.versions.toml | grep '^ktlint =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KTLINT_VERSION=$ktlint_version >> $GITHUB_ENV
shell: bash
- name: Setup environment
if: matrix.type == 'ktlint'
run: |
curl -o ktlint -sSL https://github.com/pinterest/ktlint/releases/download/${{ env.KTLINT_VERSION }}/ktlint && chmod a+x ktlint
java -version
shell: bash
- name: Download diktat jar
if: matrix.type == 'ktlint'
uses: actions/download-artifact@v3
with:
name: diktat-ruleset
- name: Generate run command using ktlint
if: matrix.type == 'ktlint'
run: |
filename=$(ls -1 diktat-*.jar | head -n1)
echo DIKTAT_RUN="java -jar ktlint -R \"$filename\"" >> $GITHUB_ENV
shell: bash
- name: Download diktat cli jar
if: matrix.type == 'cli'
uses: actions/download-artifact@v3
with:
name: diktat-cli
- name: Generate run command using cli
if: matrix.type == 'cli'
run: |
filename=$(ls -1 diktat-cli-*.jar | head -n1)
echo DIKTAT_RUN="java -jar \"$filename\"" >> $GITHUB_ENV
shell: bash
- name: Run diKTat from cli
continue-on-error: true
run: |
${{ env.DIKTAT_RUN }} 'examples/maven/src/main/kotlin/Test.kt' &>out.txt
shell: bash
- name: Check output
run: |
cat out.txt
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out.txt
rm out.txt
shell: bash
- name: Run diKTat from cli (absolute paths)
continue-on-error: true
if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
run: |
${{ env.DIKTAT_RUN }} "$PWD/examples/maven/src/main/kotlin/Test.kt" &>out.txt
shell: bash
- name: Run diKTat from cli on windows (absolute paths)
continue-on-error: true
if: runner.os == 'Windows'
# cannot use '&>out.txt' since it's Windows
run: |
${{ env.DIKTAT_RUN }} "%cd%/examples/maven/src/main/kotlin/Test.kt" > out.txt 2>&1
shell: cmd
- name: Check output (absolute paths)
run: |
cat out.txt
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out.txt
rm out.txt
shell: bash
- name: Run diKTat from cli (glob paths, 1 of 4)
continue-on-error: true
run: |
${{ env.DIKTAT_RUN }} 'examples/maven/src/main/kotlin/*.kt' &>out.txt
shell: bash
- name: Check output (glob paths, 1 of 4)
run: |
cat out.txt
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out.txt
rm out.txt
shell: bash
- name: Run diKTat from cli (glob paths, 2 of 4)
continue-on-error: true
run: |
${{ env.DIKTAT_RUN }} 'examples/**/main/kotlin/*.kt' &>out.txt
shell: bash
- name: Check output (glob paths, 2 of 4)
run: |
cat out.txt
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out.txt
rm out.txt
shell: bash
- name: Run diKTat from cli (glob paths, 3 of 4)
continue-on-error: true
run: |
${{ env.DIKTAT_RUN }} 'examples/**/*.kt' &>out.txt
shell: bash
- name: Check output (glob paths, 3 of 4)
run: |
cat out.txt
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out.txt
rm out.txt
shell: bash
- name: Run diKTat from cli (glob paths, 4 of 4)
continue-on-error: true
run: |
${{ env.DIKTAT_RUN }} '**/*.kt' &>out.txt
shell: bash
- name: Check output (glob paths, 4 of 4)
run: |
cat out.txt
grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out.txt
rm out.txt
shell: bash
build_and_test:
name: Build and test
runs-on: ${{ matrix.os }}
strategy:
# We need multiple builds to run even if the 1st one is failing, because
# test failures may be OS-specific (or the tests themselves flaky).
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
# A possible workaround for <https://github.com/dorny/test-reporter/issues/168>.
permissions:
checks: write
contents: write
pull-requests: write
statuses: write
steps:
- uses: actions/checkout@v3
with:
# required for correct codecov upload
fetch-depth: 0
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: temurin
- name: Retrieve Kotlin version
run: |
kv=$(cat gradle/libs.versions.toml | grep '^kotlin =' | awk -F'[=]' '{print $2}' | tr -d '" ')
echo KOTLIN_VERSION=$kv >> $GITHUB_ENV
shell: bash
- name: Cache konan
uses: actions/cache@v3
with:
path: ~/.konan
key: ${{ runner.os }}-gradle-konan-${{ env.KOTLIN_VERSION }}
- name: Build all
uses: gradle/gradle-build-action@v2
with:
gradle-version: wrapper
gradle-home-cache-cleanup: true
arguments: |
build
-x detekt
--scan
--build-cache
# This step needs a Git repository, so it's impossible to extract it
# into a separate job (or, otherwise, we'd need to upload the content
# of the whole `.git` folder as an artifact).
- name: JUnit Tests (dorny/test-reporter@v1)
uses: dorny/test-reporter@v1
if: ${{ always() }}
with:
name: JUnit Tests (${{ runner.os }}, dorny/test-reporter@v1)
# Comma-separated values.
path: "**/build/test-results/*/TEST-*.xml"
reporter: java-junit
# Ignore the "Resource not accessible by integration" error when a PR
# originates from a non-collaborator. This is
# <https://github.com/dorny/test-reporter/issues/168> which may be
# potentially fixed with <https://github.com/dorny/test-reporter/pull/174>.
continue-on-error: true
- name: Upload test results
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: xml-test-reports-${{ runner.os }}
path: |
**/build/test-results/*/TEST-*.xml
retention-days: 1
- name: Upload gradle reports
if: ${{ always() }}
uses: actions/upload-artifact@v3
with:
name: gradle-test-report-${{ matrix.os }}
path: '**/build/reports/'
retention-days: 1
- name: Code coverage report
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
report:
name: Publish JUnit test results
if: ${{ always() }}
needs: build_and_test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest, macos-latest ]
permissions:
checks: write
pull-requests: write
steps:
- uses: actions/download-artifact@v3
if: ${{ always() }}
with:
name: xml-test-reports-${{ runner.os }}
# Uses Docker, that's why Linux-only.
- name: JUnit Tests (EnricoMi/publish-unit-test-result-action@v2, Linux)
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ runner.os == 'Linux' }}
with:
check_name: JUnit Tests (${{ runner.os }}, EnricoMi/publish-unit-test-result-action@v2)
junit_files: |
**/target/*-reports/TEST-*.xml
**/build/test-results/*/TEST-*.xml
- name: JUnit Tests (EnricoMi/publish-unit-test-result-action@v2, Windows or Mac OS X)
uses: EnricoMi/publish-unit-test-result-action/composite@v2
if: ${{ runner.os == 'Windows' || runner.os == 'macOS' }}
with:
check_name: JUnit Tests (${{ runner.os }}, EnricoMi/publish-unit-test-result-action@v2)
junit_files: |
**/target/*-reports/TEST-*.xml
**/build/test-results/*/TEST-*.xml