-
Notifications
You must be signed in to change notification settings - Fork 0
504 lines (455 loc) · 17.8 KB
/
integration-test.yml
File metadata and controls
504 lines (455 loc) · 17.8 KB
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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
name: Integration tests
on:
push:
branches: [ "**" ]
concurrency:
group: integration-test-${{ github.ref }}
cancel-in-progress: true
env:
split-total: 4
jobs:
checkout-junit-reports:
name: Checkout JUnit reports
runs-on: ubuntu-latest
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Create JUnit reports branch
run: |
BRANCH=junit-reports-it-${{ github.sha }}-download
echo "Creating branch $BRANCH"
git switch --orphan $BRANCH
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
touch first.xml
git add *.xml
git commit -m "Initial commit for JUnit reports branch"
SHA=$(git rev-parse HEAD)
git push origin --set-upstream $BRANCH
git switch ${{ github.ref_name }}
echo "Saving expexted JUnit reports SHA $SHA"
echo "expected-junit-reports-sha=${SHA}" >> "$GITHUB_ENV"
- name: Checkout JUnit reports (split-index 1)
uses: ./checkout-junit-reports
with:
split-index: 1
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-1
- name: Checkout JUnit reports (split-index 0a)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-0
- name: Checkout JUnit reports (split-index 2)
uses: ./checkout-junit-reports
with:
split-index: 2
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-2
- name: Checkout JUnit reports (split-index 0b)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-3
- name: Checkout JUnit reports (split-index 0c)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-first-index-4
upload-artifact: false
- name: Assert JUnit reports
run: |
for SPLIT_INDEX in {0..3}; do
echo "Checking JUnit reports for split-index $SPLIT_INDEX"
if [[ ! -d "junit-reports-first-index-$SPLIT_INDEX" ]]; then
echo "Error: JUnit report directory not found!"
ls -l
exit 1
fi
cd junit-reports-first-index-$SPLIT_INDEX
REPORT_FILE="first.xml"
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 1 ]]; then
echo "Error: Expected 1 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
cd ..
done
- name: Update JUnit reports
working-directory: junit-reports-first-index-0
run: |
touch second.xml
git add *.xml
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git commit -m "Second commit for JUnit reports branch"
git push origin HEAD:junit-reports-it-${{ github.sha }}-download
- name: Download JUnit reports
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-${{ github.sha }}-download
path: junit-reports-second
- name: Assert JUnit reports
working-directory: junit-reports-second
run: |
REPORT_FILE="first.xml"
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 1 ]]; then
echo "Error: Expected 1 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Download JUnit reports SHA artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: junit-xml-reports-sha
path: junit-xml-reports-sha-artifact-assertion
- name: Assert JUnit reports SHA artifact
working-directory: junit-xml-reports-sha-artifact-assertion
run: |
SHA_FILE="junit-reports-sha.txt"
if [[ ! -f "$SHA_FILE" ]]; then
echo "Error: JUnit reports SHA file $SHA_FILE not found!"
ls -l
exit 1
fi
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 1 ]]; then
echo "Error: Expected 1 JUnit reports SHA file, but found $FILE_COUNT files!"
ls -l
exit 1
fi
ARTIFACT_SHA=$(cat $SHA_FILE)
if [ "$ARTIFACT_SHA" != "${{ env.expected-junit-reports-sha }}" ]; then
echo "Error: JUnit reports SHA $ARTIFACT_SHA in artifact does not match expected SHA ${{ env.expected-junit-reports-sha }}"
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }}-download || true
- name: Clean up JUnit reports artifact
uses: geekyeggo/delete-artifact@176a747ab7e287e3ff4787bf8a148716375ca118 # v6
with:
name: junit-xml-reports-sha
failOnError: false
checkout-junit-reports-with-nonexistent-branch:
name: Checkout JUnit reports with non-existent branch
runs-on: ubuntu-latest
needs:
- checkout-junit-reports
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Checkout JUnit reports (split-index 1)
uses: ./checkout-junit-reports
with:
split-index: 1
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-1
- name: Checkout JUnit reports (split-index 0a)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-0
- name: Checkout JUnit reports (split-index 2)
uses: ./checkout-junit-reports
with:
split-index: 2
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-2
- name: Checkout JUnit reports (split-index 0b)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-3
- name: Checkout JUnit reports (split-index 0c)
uses: ./checkout-junit-reports
with:
split-index: 0
git-branch: junit-reports-it-nonexistent
path: junit-reports-first-index-4
upload-artifact: false
- name: Assert JUnit reports
run: |
for SPLIT_INDEX in {0..3}; do
echo "Checking JUnit reports for split-index $SPLIT_INDEX"
if [[ ! -d "junit-reports-first-index-$SPLIT_INDEX" ]]; then
echo "Error: JUnit report directory not found!"
ls -l
exit 1
fi
cd junit-reports-first-index-$SPLIT_INDEX || exit 1
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 0 ]]; then
echo "Error: Expected empty directory, but found $FILE_COUNT files!"
ls -l
exit 1
fi
cd ..
done
generate-split-index-json:
name: Generate split indexes
runs-on: ubuntu-latest
needs:
- checkout-junit-reports-with-nonexistent-branch
outputs:
json: ${{ steps.generate.outputs.split-index-json }}
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Generate split index list
id: generate
uses: ./generate-split-index-json
with:
split-total: ${{ env.split-total }}
integration-test:
name: "Test #${{ matrix.split-index }}"
runs-on: ubuntu-latest
needs:
- generate-split-index-json
permissions:
contents: read
checks: write
strategy:
fail-fast: false
matrix:
split-index: ${{ fromjson(needs.generate-split-index-json.outputs.json) }}
env:
DOWNLOAD_JAR: false
JAR_PATH: split-tests-java/build/libs/split-tests-java.jar
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Checkout split-tests-java
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
repository: Donnerbart/split-tests-java
path: split-tests-java
- name: Set up JDK 21
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5
with:
distribution: temurin
java-version: 21
- name: Set up Gradle
uses: gradle/actions/setup-gradle@0723195856401067f7a2779048b490ace7a47d7c # v5
- name: Compile split-tests-java
working-directory: split-tests-java
run: ./gradlew shadowJar
- name: Split tests
id: split-tests
uses: ./
with:
split-index: ${{ matrix.split-index }}
split-total: ${{ env.split-total }}
glob: '**/integration-test/tests/*Test.java'
exclude-glob: '**/NoClassNameTest.java'
junit-glob: '**/integration-test/reports/*.xml'
format: 'list'
new-test-time: 'average'
calculate-optimal-total-split: true
debug: true
- name: Assert split tests
env:
SPLIT_INDEX: ${{ matrix.split-index }}
ACTUAL: ${{ steps.split-tests.outputs.test-suite }}
run: |
case "$SPLIT_INDEX" in
"0")
EXPECTED="de.donnerbart.example.SlowestTest"
;;
"1")
EXPECTED="NoPackageTest de.donnerbart.example.ThirdPartyLibraryTest"
;;
"2")
EXPECTED="de.donnerbart.example.NoTimingOneTest de.donnerbart.example.WhitespaceClassDefinitionTest"
;;
"3")
EXPECTED="de.donnerbart.example.NoTimingTwoTest de.donnerbart.example.SlowTest de.donnerbart.example.FastTest"
;;
*)
echo "Unexpected split index"
exit 1
;;
esac
echo "Expected: $EXPECTED"
echo "Actual: $ACTUAL"
if [ "$ACTUAL" != "$EXPECTED" ]; then
echo "The split tests are not matching"
exit 1
fi
- name: Create simulated JUnit report
run: |
mkdir -p build/reports/test-results
CLASS="de.donnerbart.example.ActionSplit${{ matrix.split-index }}Test"
FILE="build/reports/test-results/TEST-$CLASS.xml"
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $FILE
echo "<testsuite name=\"$CLASS\" tests=\"1\" skipped=\"0\" failures=\"0\" errors=\"0\" timestamp=\"1970-01-01T00:00:00\" hostname=\"foobar\" time=\"23.42\">" >> $FILE
echo " <properties/>" >> $FILE
echo " <testcase name=\"testMethod()\" classname=\"$CLASS\" time=\"23.42\">" >> $FILE
echo " <system-out><![CDATA[00:00:00.000 [Test] INFO Test log for split ${{ matrix.split-index }}" >> $FILE
echo "00:00:00.001 [Test] INFO Done" >> $FILE
echo "]]></system-out>" >> $FILE
echo " <system-err><![CDATA[]]></system-err>" >> $FILE
echo " </testcase>" >> $FILE
echo "</testsuite>" >> $FILE
- name: Upload JUnit report artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: junit-xml-reports-${{ matrix.split-index }}
path: build/reports/test-results/*.xml
merge-junit-reports-with-existing-branch:
name: Merge JUnit reports with existing branch
runs-on: ubuntu-latest
needs:
- integration-test
permissions:
contents: write
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Create JUnit reports branch
run: |
BRANCH=junit-reports-it-${{ github.sha }}-existing
echo "Creating branch $BRANCH"
git switch --orphan $BRANCH
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git commit --allow-empty -m "Initial commit for JUnit reports branch"
git push origin --set-upstream $BRANCH
git switch ${{ github.ref_name }}
- name: Merge JUnit reports
uses: ./merge-junit-reports
with:
git-branch: junit-reports-it-${{ github.sha }}-existing
artifact-name: junit-xml-report-existing
split-artifact-pattern: junit-xml-reports-*
split-artifact-delete-merged: false
- name: Checkout JUnit reports
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
path: junit-reports-assertion
ref: junit-reports-it-${{ github.sha }}-existing
- name: Assert JUnit reports
working-directory: junit-reports-assertion
run: |
for SPLIT_INDEX in {0..3}; do
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
cat $REPORT_FILE
exit 1
fi
echo "JUnit report $REPORT_FILE is valid"
done
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 4 ]]; then
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }}-existing || true
merge-junit-reports-with-new-branch:
name: Merge JUnit reports with new branch
runs-on: ubuntu-latest
needs:
- merge-junit-reports-with-existing-branch
permissions:
contents: write
steps:
- name: Checkout split-tests-java-action
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Merge JUnit reports
uses: ./merge-junit-reports
with:
git-branch: junit-reports-it-${{ github.sha }}-new
artifact-name: junit-xml-report-new
split-artifact-pattern: junit-xml-reports-*
- name: Checkout JUnit reports
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
path: junit-reports-assertion
ref: junit-reports-it-${{ github.sha }}-new
- name: Assert JUnit reports
working-directory: junit-reports-assertion
run: |
for SPLIT_INDEX in {0..3}; do
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
cat $REPORT_FILE
exit 1
fi
echo "JUnit report $REPORT_FILE is valid"
done
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 4 ]]; then
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Download JUnit reports artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
with:
name: junit-xml-report-new
path: junit-reports-artifact-assertion
- name: Assert JUnit reports artifact
working-directory: junit-reports-artifact-assertion
run: |
for SPLIT_INDEX in {0..3}; do
REPORT_FILE="TEST-de.donnerbart.example.ActionSplit${SPLIT_INDEX}Test.xml"
SEARCH_STRING='name="de.donnerbart.example.ActionSplit'${SPLIT_INDEX}'Test"'
if [[ ! -f "$REPORT_FILE" ]]; then
echo "Error: JUnit report $REPORT_FILE not found!"
ls -l
exit 1
fi
if ! grep -q "$SEARCH_STRING" "$REPORT_FILE"; then
echo "Error: JUnit report $REPORT_FILE does not contain the required string '$SEARCH_STRING'!"
cat $REPORT_FILE
exit 1
fi
echo "JUnit report $REPORT_FILE is valid"
done
FILE_COUNT=$(ls -1 | wc -l)
if [[ "$FILE_COUNT" -ne 4 ]]; then
echo "Error: Expected 4 JUnit reports, but found $FILE_COUNT files!"
ls -l
exit 1
fi
- name: Clean up JUnit reports branch
if: always()
run: |
git push origin --delete junit-reports-it-${{ github.sha }}-new || true