-
Notifications
You must be signed in to change notification settings - Fork 467
689 lines (650 loc) · 24.8 KB
/
maven-cicd-pipeline.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
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
name: Maven CICD Pipeline
on:
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Tags'
required: false
push:
branches:
- master
- release-*
pull_request:
merge_group:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }}
cancel-in-progress: true
env:
JVM_TEST_MAVEN_OPTS: "-e -B --no-transfer-progress -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn"
DOCKER_PLATFORMS: "linux/amd64,linux/arm64"
REGISTRY: ghcr.io
IMAGE_NAME: dotcms/dotcms_test
jobs:
#
# Detect Code that has changed and create outputs to uses as conditionals
#
changes:
name: Check Changed Files
runs-on: ubuntu-latest
permissions:
pull-requests: read
outputs:
backend: ${{ steps.filter-rewrite.outputs.backend }}
frontend: ${{ steps.filter-rewrite.outputs.frontend }}
build: ${{ steps.filter-rewrite.outputs.build }}
jvm_unit_test: ${{ steps.filter-rewrite.outputs.jvm_unit_test }}
cli: ${{ steps.filter-rewrite.outputs.cli }}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cleanup-runner
- uses: dorny/[email protected]
id: filter
with:
filters: .github/filters.yaml
list-files: 'escape'
- name: Rewrite Filter
id: filter-rewrite
run: |
frontend=${{ steps.filter.outputs.frontend }}
cli=${{ steps.filter.outputs.cli }}
backend=${{ steps.filter.outputs.backend }}
build=${{ steps.filter.outputs.build }}
jvm_unit_test=${{ steps.filter.outputs.jvm_unit_test }}
is_backend=false
backend_files=( ${{ steps.filter.outputs.backend_files }} )
for backend_file in "${backend_files[@]}"
do
echo "Evaluating ${backend_file}"
if [[ ! ${backend_file} =~ ^dotCMS/src/main/webapp/html/.*\.(js|css)$ ]]; then
echo "Backend file ${backend_file} is not a frontend file... aborting search"
is_backend=true
break
fi
done
backend=${is_backend}
[[ "${backend}" == 'true' ]] && build=true && jvm_unit_test=true
echo "frontend=${frontend}"
echo "cli=${cli}"
echo "backend=${backend}"
echo "build=${build}"
echo "jvm_unit_test=${jvm_unit_test}"
echo "frontend=${frontend}" >> $GITHUB_OUTPUT
echo "cli=${cli}" >> $GITHUB_OUTPUT
echo "backend=${backend}" >> $GITHUB_OUTPUT
echo "build=${build}" >> $GITHUB_OUTPUT
echo "jvm_unit_test=${jvm_unit_test}" >> $GITHUB_OUTPUT
#
# Initial JDK 11 Build
# Basic build and install all with maven without running tests.
# Provides local maven repo for subsequent steps
#
build-jdk11:
name: "Initial JDK 11 Build"
runs-on: ubuntu-20.04
needs: changes
if: ${{ needs.changes.outputs.build == 'true' }}
outputs:
docker-tag: ${{ fromJSON(steps.meta.outputs.json).tags[0] }}
env:
DOCKER_BUILD_CONTEXT: /home/runner/work/_temp/core-build
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cleanup-runner
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'temurin'
# Docker setup
- name: Set up QEMU
uses: docker/[email protected]
with:
image: tonistiigi/binfmt:latest
platforms: ${{ env.DOCKER_PLATFORMS }}
- id: docker-setup-buildx
name: Docker Setup Buildx
uses: docker/[email protected]
with:
version: latest
platforms: ${{ env.DOCKER_PLATFORMS }}
driver-opts: |
image=moby/buildkit:v0.12.2
- name: Docker Hub login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
- id: docker-login
name: Login to GHCR
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha,enable=true,priority=100,prefix=sha-,suffix=,format=short
type=raw,value=run-${{ github.run_id }}
- name: Debug docker metadata
run: |
echo "${{ fromJSON(steps.meta.outputs.json) }}"
shell: bash
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
shell: bash
- name: Cache Maven Repository
id: cache-maven
uses: actions/cache@v3
with:
path: ~/.m2/repository
key: mavencore-${{ steps.get-date.outputs.date }}-${{ github.run_id }}
restore-keys: |
mavencore-${{ steps.get-date.outputs.date }}
- name: Cache Node Binary
id: cache-node-binary
uses: actions/cache@v3
with:
path: |
core-web/installs
key: node-binary-${{ hashFiles('core-web/.nvmrc') }}
- name: Cache NPM
id: cache-npm
uses: actions/cache@v3
with:
path: |
~/.npm
# if specific cache does not exist then can base upon latest version
key: npm-${{ hashFiles('core-web/package-lock.json') }}
restore-keys: npm-
- name: Maven Build No Test
shell: bash
env:
NODE_CACHE_HIT: ${{ steps.cache-node-modules.outputs.cache-hit }}
run: |
echo "Creating $DOCKER_BUILD_CONTEXT"
mkdir -p $DOCKER_BUILD_CONTEXT
./mvnw -Dprod=true $JVM_TEST_MAVEN_OPTS -Ddocker.buildArchiveOnly=$DOCKER_BUILD_CONTEXT -Dskip.npm.install=${NODE_CACHE_HIT} --show-version -DskipTests=true -DskipITs=true clean install --file pom.xml
- name: Setup Context
id: setup-docker-context
run: |
mkdir -p $DOCKER_BUILD_CONTEXT/context
tar -xvf $DOCKER_BUILD_CONTEXT/docker-build.tar -C $DOCKER_BUILD_CONTEXT/context
- name: Build base image
uses: docker/build-push-action@v5
with:
context: ${{ env.DOCKER_BUILD_CONTEXT }}/context
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms : ${{ env.DOCKER_PLATFORMS }}
pull: true
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Upload build reports
uses: actions/upload-artifact@v3
if: ${{ always() }}
with:
name: "build-reports-Initial JDK 11 Build" #Should not be picked up for JunitReports
path: |
target/build-report.json
LICENSE
retention-days: 2
#
# Run all JVM Unit Tests in parallel with other tests
#
linux-jvm-tests:
name: JVM Unit Tests - JDK ${{matrix.java.name}}
runs-on: ubuntu-20.04
if: ${{ needs.changes.outputs.jvm_unit_test == 'true' }}
needs: [changes,build-jdk11]
timeout-minutes: 240
env:
MAVEN_OPTS: -Xmx2048m
strategy:
fail-fast: false
matrix:
java:
- {
name: "11",
java-version: 11,
distribution: 'temurin',
maven_args: ""
}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cleanup-runner
- name: Set up JDK ${{ matrix.java.name }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java.java-version }}
distribution: ${{ matrix.java.distribution }}
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
shell: bash
- name: Restore Maven Repository
id: cache-maven
uses: actions/cache/restore@v3
with:
path: ~/.m2/repository
key: mavencore-${{ steps.get-date.outputs.date }}-${{ github.run_id }}
- name: Build
# exclude core web we aare testing that separately
run: eval ./mvnw -Dprod $JVM_TEST_MAVEN_OPTS test -pl \!:dotcms-core-web ${{ matrix.java.maven_args}}
- name: Prepare reports archive (if maven failed)
if: failure()
shell: bash
run: find . -name '*-reports' -type d | tar -czf test-reports.tgz -T -
- name: Upload reports Archive (if maven failed)
uses: actions/upload-artifact@v3
if: failure()
with:
name: test-reports-linux-jvm${{matrix.java.name}}
path: 'test-reports.tgz'
- name: core-maven-unit-tests
uses: actions/upload-artifact@v3
if: always()
with:
name: "build-reports-test-JVM Tests - JDK ${{matrix.java.name}}"
path: |
**/target/*-reports/TEST-*.xml
target/build-report.json
LICENSE
retention-days: 2
#
# Run Frontend Tests
#
linux-frontend-tests:
name: Frontend Unit Tests
runs-on: ubuntu-20.04
if: ${{ needs.changes.outputs.frontend == 'true' }}
needs: [changes,build-jdk11]
timeout-minutes: 240
env:
MAVEN_OPTS: -Xmx2048m
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cleanup-runner
- name: Set up JDK 11
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
shell: bash
- name: Restore Maven Repository
id: cache-maven
uses: actions/cache/restore@v3
with:
path: ~/.m2/repository
key: mavencore-${{ steps.get-date.outputs.date }}-${{ github.run_id }}
- name: Restore Node Binary
id: cache-node-binary
uses: actions/cache/restore@v3
with:
path: |
core-web/installs
key: node-binary-${{ hashFiles('core-web/.nvmrc') }}
- name: Restore Node
id: cache-npm
uses: actions/cache/restore@v3
with:
path: |
~/.npm
key: npm-${{ hashFiles('core-web/package-lock.json') }}
restore-keys: npm-
#- name: Restore Node Modules
# id: cache-node-modules
# uses: actions/cache/restore@v3
# with:
# path: core-web/node_modules
# # only pull for exact version of package-lock
# key: node-modules-${{ hashFiles('core-web/package-lock.json') }}
- name: Build # expect node cache to exist from
shell: bash
env:
NODE_CACHE_HIT: ${{ steps.cache-node-modules.outputs.cache-hit }}
run: eval ./mvnw -Dprod -Dskip.npm.install=${NODE_CACHE_HIT} $JVM_TEST_MAVEN_OPTS -pl :dotcms-core-web test
- name: Prepare failure archive (if maven failed)
if: failure()
shell: bash
run: find . -name 'surefire-reports' -type d | tar -czf test-reports.tgz -T -
- name: Upload failure Archive (if maven failed)
uses: actions/upload-artifact@v3
if: failure()
with:
name: test-reports-frontend
path: 'test-reports.tgz'
- name: frontend-unit-tests
uses: actions/upload-artifact@v3
if: always()
with:
name: "build-reports-test-Frontend unit tests"
path: |
**/target/*-reports/**/TEST-*.xml
target/build-report.json
LICENSE
retention-days: 2
#
# Run Legacy Integration test suite batches
#
linux-integration-tests:
name: JVM IT Tests - JDK ${{matrix.java.name}} ${{matrix.suites.name}}
runs-on: ubuntu-20.04
# Skip master in forks
if: ${{ needs.changes.outputs.backend == 'true' }}
needs: [build-jdk11,changes]
timeout-minutes: 240
env:
MAVEN_OPTS: -Xmx2048m
strategy:
fail-fast: false
matrix:
java:
- {
name: "11",
java-version: 11,
distribution: 'temurin',
maven_args: ""
}
suites:
- {
name: "MainSuite 1a",
pathName: "mainsuite1a",
maven_args: '"-Dit.test=MainSuite1a" -Dit.test.forkcount=1'
}
- {
name: "MainSuite 1b",
pathName: "mainsuite1b",
maven_args: '"-Dit.test=MainSuite1b" -Dit.test.forkcount=1'
}
- {
name: "MainSuite 2a",
pathName: "mainsuite2a",
maven_args: '"-Dit.test=MainSuite2a" -Dit.test.forkcount=1'
}
- {
name: "MainSuite 2b",
pathName: "mainsuite2b",
maven_args: '"-Dit.test=MainSuite2b" -Dit.test.forkcount=1'
}
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cleanup-runner
- name: Set up IT Tests ${{ matrix.java.name }} ${{ matrix.suites.name }}
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java.java-version }}
distribution: ${{ matrix.java.distribution }}
#- name: Download Maven Repo
# uses: actions/download-artifact@v3
# with:
# name: maven-repo
# path: .
#- name: Extract Maven Repo
# shell: bash
# run: tar -xzf maven-repo.tgz -C ~
- name: Get Date
id: get-date
run: |
echo "date=$(/bin/date -u "+%Y-%m")" >> $GITHUB_OUTPUT
sudo touch /usr/bin/docker-compose
echo 'docker compose --compatibility "$@"' | sudo tee /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
docker-compose version
shell: bash
- name: Restore Maven Repository
id: cache-maven
uses: actions/cache/restore@v3
with:
path: ~/.m2/repository
key: mavencore-${{ steps.get-date.outputs.date }}-${{ github.run_id }}
- name: Build
env:
DOT_DOTCMS_LICENSE: ${{ secrets.DOTCMS_LICENSE }}
run: eval ./mvnw -Dprod $JVM_TEST_MAVEN_OPTS verify -pl :dotcms-integration ${{ matrix.suites.maven_args}} ${{ matrix.java.maven_args}}
- name: Prepare reports archive (if maven failed)
if: failure()
shell: bash
run: find . -name '*-reports' -type d | tar -czf test-reports.tgz -T -
- name: Upload failure Archive (if maven failed)
uses: actions/upload-artifact@v3
if: failure()
with:
name: test-reports-linux-jvm${{matrix.java.name}}-${{matrix.suites.pathName}}
path: 'test-reports.tgz'
- name: failsafe-it-tests # Uploads will be merged with same name
uses: actions/upload-artifact@v3
if: always()
with:
name: "build-reports-test-IT Tests - JDK ${{matrix.java.name}} - ${{matrix.suites.name}}"
path: |
**/target/*-reports/TEST-*.xml
target/build-report.json
LICENSE
retention-days: 2
linux-postman-tests:
name: Run Postman Tests - ${{matrix.collection_group}}
runs-on: ubuntu-latest
needs: [build-jdk11, changes]
if: ${{ needs.changes.outputs.backend == 'true' }}
strategy:
fail-fast: false
matrix:
collection_group: [ 'category-container', 'content', 'experiment', 'graphql', 'page', 'pp', 'template', 'workflow', 'default' ]
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/cleanup-runner
- run: sudo npm install --location=global [email protected] [email protected]
- id: docker-login
name: Login to GHCR
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
- id: resolve-postman-collections
uses: ./.github/actions/resolve-postman-collections
with:
current: ${{ matrix.collection_group }}
- name: Prepare license
id: prepare-license
run: |
postman_dir=${{ github.workspace }}/dotcms-postman
docker_volumes_dir=${postman_dir}/target/docker-volumes
[[ -d ${docker_volumes_dir} ]] && rm -rf ${docker_volumes_dir}
dotcms_volumes_dir=${docker_volumes_dir}/dotcms
license_dir=${dotcms_volumes_dir}/license
mkdir -p ${license_dir}
license_file=${license_dir}/license.dat
touch ${license_file}
echo "${{ secrets.DOTCMS_LICENSE }}" > ${license_file}
chmod -R 777 ${license_dir}
- id: run-postman-tests
name: Run Postman Tests
timeout-minutes: 90
run: |
./mvnw -Dpostman-tests -Dprod $JVM_TEST_MAVEN_OPTS verify \
-pl :dotcms-postman \
-Dpostman.collections="${{ steps.resolve-postman-collections.outputs.collections_to_run }}"
pec=$?
[[ pec -eq 0 ]] || exit pec
env:
DOTCMS_IMAGE: ${{ needs.build-jdk11.outputs.docker-tag }}
- name: Prepare reports archive (if maven failed)
if: failure()
shell: bash
run: |
find . -name '*-reports' -type d
tree ./dotcms-postman
find . -name '*-reports' -type d | tar -czf test-reports.tgz -T -
- name: Upload failure Archive (if maven failed)
uses: actions/upload-artifact@v3
if: failure()
with:
name: test-reports-postman-${{ matrix.collection_group }}
path: 'test-reports.tgz'
- name: failsafe-postman-tests # Uploads will be merged with same name
uses: actions/upload-artifact@v3
if: always()
with:
name: "build-reports-test-postman - ${{ matrix.collection_group }}"
path: |
**/dotcms-postman/target/postman-reports/TEST-*.xml
target/build-report.json
LICENSE
retention-days: 2
clean-up:
name: Clean up
runs-on: ubuntu-latest
needs: [ build-jdk11, linux-postman-tests ]
if: (success() || failure()) && (github.repository == 'dotCMS/core' || !endsWith(github.ref, '/master'))
steps:
- uses: actions/checkout@v4
- id: cleanup-package
name: Clean up CICD packages
uses: ./.github/actions/cleanup-gh-packages
with:
delete_tags: ${{ needs.build-jdk11.outputs.docker-tag }}
access_token: ${{ secrets.GHCR_TOKEN }}
#
# Collate reports and build status
#
prepare-report-data:
name: Prepare Report Data
runs-on: ubuntu-20.04
needs: [ build-jdk11,linux-jvm-tests,linux-integration-tests,linux-frontend-tests,linux-postman-tests ]
if: always()
outputs:
aggregate_status: ${{ steps.prepare-workflow-data.outputs.aggregate_status }}
steps:
- name: Download build reports
uses: actions/download-artifact@v3
with:
path: /tmp/build-step-reports
- name: Prepare workflow data
id: prepare-workflow-data
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
AGGREGATE_STATUS="SUCCESS"
jobs_status="${{ toJson(needs) }}"
echo "job status=${jobs_status}"
while IFS=" " read -r key result; do
key=$(echo $key | tr -d ' {')
result=$(echo $result | tr -d ',')
echo "Job: $key, Result: $result"
if [[ $result == "cancelled" ]]; then
AGGREGATE_STATUS="CANCELLED"
break
elif [[ $result == "failure" ]]; then
AGGREGATE_STATUS="FAILURE"
fi
done < <(echo "$jobs_status" | awk -F': ' '/result:/ {print $1,$2}')
FIRST_FAIL_STEP=""
FIRST_FAIL_MODULE=""
echo '{' > workflow-data.json
EVENT_TYPE="${{ github.event_name }}"
if [[ "$EVENT_TYPE" == "pull_request" ]]; then
echo "Creating workflow data for pull request ${PR_TITLE}"
BRANCH="${{ github.head_ref }}"
else
PR_TITLE="N/A"
BRANCH="${{ github.ref }}"
echo "Creating workflow data for branch ${BRANCH}"
fi
BRANCH="${BRANCH##*/}"
PR_TITLE_JQ=$(jq --arg title "$PR_TITLE" -n '$title')
echo '"branch": "'$BRANCH'",' >> workflow-data.json
echo '"run_id": "'${{ github.run_id }}'",' >> workflow-data.json
echo '"trigger_event_name": "'$GITHUB_EVENT_NAME'",' >> workflow-data.json
echo '"source_repository": "'$GITHUB_REPOSITORY'",' >> workflow-data.json
echo '"merge_sha": "'${{ github.sha }}'",' >> workflow-data.json
echo '"base_sha": "'${{ github.event.pull_request.base.sha }}'",' >> workflow-data.json
echo '"base_branch": "'${{ github.event.pull_request.base.sha }}'",' >> workflow-data.json
echo '"base_author": "'${{ github.event.pull_request.base.user.login }}'",' >> workflow-data.json
echo '"head_author": "'${{ github.event.pull_request.head.user.login }}'",' >> workflow-data.json
echo '"head_name": "'${{ github.event.pull_request.head.ref }}'",' >> workflow-data.json
echo '"head_sha": "'${{ github.event.pull_request.head.sha }}'",' >> workflow-data.json
echo '"pr_id": "'${{ github.event.pull_request.id }}'",' >> workflow-data.json
echo '"pr_number": "'${{ github.event.pull_request.number }}'",' >> workflow-data.json
echo "\"pr_title\": $PR_TITLE_JQ," >> workflow-data.json
echo '"pr_author": "'${{ github.event.pull_request.user.login }}'",' >> workflow-data.json
echo '"pr_merge_state": "'${{ github.event.pull_request.mergeable_state }}'",' >> workflow-data.json
echo '"build_reports": [' >> workflow-data.json
total_reports=$(find /tmp/build-step-reports/build-reports-*/target -name build-report.json 2>/dev/null | wc -l)
report_index=0
if [ "$total_reports" -eq "0" ]; then
echo "No build report files found."
else
for build_report in "/tmp/build-step-reports/build-reports-"*/target/build-report.json; do
((report_index=report_index+1))
step_name=$(basename "$(dirname "$(dirname "$build_report")")" | sed 's/build-reports-//')
cat "$build_report" | jq ".step_name = \"$step_name\"" >> workflow-data.json
# If the aggregate status is still SUCCESS, check if this module failed
if [[ "$AGGREGATE_STATUS" == "SUCCESS" ]]; then
# Loop over each projectReport
length=$(jq '.projectReports | length' "$build_report")
for (( i=0; i<$length; i++ )); do
status=$(jq -r ".projectReports[$i].status" "$build_report")
if [[ "$status" == "FAILURE" ]]; then
AGGREGATE_STATUS="FAILURE"
FIRST_FAIL_STEP="$step_name"
FIRST_FAIL_MODULE="$(jq -r ".projectReports[$i].name" "$build_report")"
FIRST_FAIL_ERROR="$(jq -r ".projectReports[$i].error" "$build_report")"
fi
done
fi
# If not the last file, append a comma
if (( report_index != total_reports )); then
echo ',' >> workflow-data.json
fi
done
fi
echo '],' >> workflow-data.json
echo '"aggregate_status": "'$AGGREGATE_STATUS'"' >> workflow-data.json
if [[ "$AGGREGATE_STATUS" != "SUCCESS" ]]; then
echo ',' >> workflow-data.json
echo '"first_fail_step": "'$FIRST_FAIL_STEP'",' >> workflow-data.json
echo '"first_fail_module": "'$FIRST_FAIL_MODULE'",' >> workflow-data.json
echo '"first_fail_error": "'$FIRST_FAIL_ERROR'"' >> workflow-data.json
fi
echo '}' >> workflow-data.json
echo "aggregate_status=${AGGREGATE_STATUS}" >> $GITHUB_OUTPUT
- name: Upload workflow data
uses: actions/upload-artifact@v3
with:
name: workflow-data
path: ./workflow-data.json
final-status:
name: Final Status
needs: prepare-report-data
if: always()
runs-on: ubuntu-20.04
steps:
- name: Check Final Status
run: |
if [ "${{ needs.prepare-report-data.outputs.aggregate_status }}" != "SUCCESS" ]; then
echo "One or more jobs failed!"
exit 1
fi