Skip to content

Commit 81d572b

Browse files
committed
HV-2059 Update GH actions build to upload/publish build scans
1 parent 032a394 commit 81d572b

File tree

2 files changed

+91
-18
lines changed

2 files changed

+91
-18
lines changed

.github/workflows/ci-report.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright Red Hat Inc. and Hibernate Authors
3+
4+
name: GH Actions CI reporting
5+
6+
on:
7+
workflow_run:
8+
workflows: [ "GH Actions CI" ]
9+
types: [ completed ]
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
env:
16+
MAVEN_ARGS: "-e -B --settings .github/mvn-settings.xml --fail-at-end -Pci-build --no-transfer-progress"
17+
18+
jobs:
19+
publish-build-scans:
20+
name: Publish Develocity build scans
21+
if: github.repository == 'hibernate/hibernate-validator' && github.event.workflow_run.conclusion != 'cancelled'
22+
runs-on: ubuntu-latest
23+
steps:
24+
# Checkout target branch which has trusted code
25+
- name: Check out target branch
26+
uses: actions/checkout@v4
27+
with:
28+
persist-credentials: false
29+
ref: ${{ github.ref }}
30+
- name: Set up Java 21
31+
uses: actions/setup-java@v4
32+
with:
33+
java-version: 21
34+
distribution: temurin
35+
# https://github.com/actions/cache/blob/main/examples.md#java---maven
36+
- name: Cache local Maven repository
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/.m2/repository
40+
# use a different key than workflows running untrusted code
41+
key: trusted-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
42+
restore-keys: |
43+
trusted-${{ runner.os }}-maven-
44+
- name: Set up Maven
45+
run: ./mvnw -v
46+
- name: Download GitHub Actions artifacts for the Develocity build scans
47+
id: downloadBuildScan
48+
uses: actions/download-artifact@v4
49+
with:
50+
pattern: build-scan-data-*
51+
github-token: ${{ github.token }}
52+
repository: ${{ github.repository }}
53+
run-id: ${{ github.event.workflow_run.id }}
54+
path: /tmp/downloaded-build-scan-data/
55+
# Don't fail the build if there are no matching artifacts
56+
continue-on-error: true
57+
- name: Publish Develocity build scans for previous builds
58+
if: ${{ steps.downloadBuildScan.outcome != 'failure'}}
59+
run: |
60+
shopt -s nullglob # Don't run the loop below if there are no artifacts
61+
status=0
62+
mkdir -p ~/.m2/.develocity/
63+
for build_scan_data_directory in /tmp/downloaded-build-scan-data/*
64+
do
65+
rm -rf ~/.m2/.develocity/build-scan-data
66+
mv "$build_scan_data_directory" ~/.m2/.develocity/build-scan-data \
67+
&& ./mvnw $MAVEN_ARGS develocity:build-scan-publish-previous || status=1
68+
done
69+
exit $status
70+
env:
71+
DEVELOCITY_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY_PR }}

.github/workflows/ci.yml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -103,35 +103,37 @@ jobs:
103103
- name: Set up Maven
104104
run: ./mvnw -v
105105

106-
- name: Build code and run tests and basic checks
106+
- name: Build code and run tests and basic checks (Standalone)
107107
run: |
108108
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} clean install \
109109
-Pjqassistant -Pdist -Prelocation
110+
env:
111+
DEVELOCITY_ACCESS_KEY: "${{ secrets.DEVELOCITY_ACCESS_KEY || '' }}"
112+
# For jobs running on 'pull_request', upload build scan data.
113+
# The actual publishing must be done in a separate job (see ci-report.yml).
114+
# We don't write to the remote cache as that would be unsafe.
115+
- name: Upload GitHub Actions artifact for the Develocity build scan
116+
uses: actions/upload-artifact@v4
117+
if: "${{ github.event_name == 'pull_request' && !cancelled() }}"
118+
with:
119+
name: build-scan-data-standalone-${{ matrix.os.name }}
120+
path: ~/.m2/.develocity/build-scan-data
110121

111-
- name: Build code and run tests in container mode
122+
- name: Run TCK tests in container mode
112123
run: |
113124
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} clean verify \
114125
-Pjqassistant -Pskip-checks \
115126
-am -pl :hibernate-validator-tck-runner \
116127
-Dincontainer -Dincontainer-prepared
117-
# Workaround for https://github.com/actions/upload-artifact/issues/240
118-
- name: List build reports to upload (if build failed)
119-
if: ${{ failure() || cancelled() }}
120-
# The weird syntax is because we're setting a multiline environment variable
121-
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
122-
run: |
123-
{
124-
echo 'buildReportPaths<<EOF'
125-
find . -path '**/*-reports'
126-
echo EOF
127-
} >> "$GITHUB_ENV"
128-
- name: Upload build reports (if build failed)
128+
env:
129+
DEVELOCITY_ACCESS_KEY: "${{ secrets.DEVELOCITY_ACCESS_KEY || '' }}"
130+
131+
- name: Upload GitHub Actions artifact for the Develocity build scan
129132
uses: actions/upload-artifact@v4
130-
if: ${{ failure() || cancelled() }}
133+
if: "${{ github.event_name == 'pull_request' && !cancelled() }}"
131134
with:
132-
name: ${{ format('build-reports-{0}', matrix.os.name ) }}
133-
path: ${{ env.buildReportPaths }}
134-
retention-days: 7
135+
name: build-scan-data-incontainer-${{ matrix.os.name }}
136+
path: ~/.m2/.develocity/build-scan-data
135137

136138
- name: Omit produced artifacts from build cache
137139
run: rm -r ~/.m2/repository/org/hibernate/validator

0 commit comments

Comments
 (0)