Skip to content

Commit 697cbc3

Browse files
committed
Align GitHub Actions setup on Hibernate Search
1 parent f0273cb commit 697cbc3

File tree

2 files changed

+100
-39
lines changed

2 files changed

+100
-39
lines changed

.github/workflows/ci-report.yml

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

.github/workflows/build.yml renamed to .github/workflows/ci.yml

Lines changed: 32 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# See https://docs.github.com/en/actions
1010
# for more information about GitHub actions.
1111

12-
name: GitHub Actions Build
12+
name: GH Actions CI
1313

1414
on:
1515
push:
@@ -24,9 +24,7 @@ on:
2424
- '!dependabot/**'
2525
tags:
2626
- '**'
27-
# WARNING: Using pull_request_target to access secrets, but we check out the merge commit.
28-
# See checkout action for details.
29-
pull_request_target:
27+
pull_request:
3028
types: [opened, synchronize, reopened, ready_for_review]
3129
branches:
3230
# Pattern order matters: the last matching inclusion/exclusion wins
@@ -43,14 +41,14 @@ on:
4341

4442
concurrency:
4543
group: "workflow = ${{ github.workflow }}, ref = ${{ github.event.ref }}, pr = ${{ github.event.pull_request.id }}"
46-
cancel-in-progress: ${{ github.event_name == 'pull_request_target' || github.repository != 'hibernate/hibernate-validator' }}
44+
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.repository != 'hibernate/hibernate-validator' }}
4745

4846
defaults:
4947
run:
5048
shell: bash
5149

5250
env:
53-
MAVEN_ARGS: "-e -B --settings .github/mvn-settings.xml --fail-at-end"
51+
MAVEN_ARGS: "-e -B --settings .github/mvn-settings.xml --fail-at-end -Pci-build --no-transfer-progress"
5452
TESTCONTAINERS_REUSE_ENABLE: true
5553

5654
jobs:
@@ -68,7 +66,7 @@ jobs:
6866
version: 17
6967
},
7068
maven: {
71-
args: '-Pci-build --no-transfer-progress'
69+
args: ''
7270
}
7371
}
7472
- {
@@ -78,27 +76,16 @@ jobs:
7876
version: 17
7977
},
8078
maven: {
81-
args: '-Pci-build --no-transfer-progress'
79+
args: ''
8280
}
8381
}
8482
steps:
8583
- name: Support longpaths on Windows
8684
if: "startsWith(matrix.os.runs-on, 'windows')"
8785
run: git config --global core.longpaths true
88-
- name: Check out commit already pushed to branch
89-
if: "! github.event.pull_request.number"
90-
uses: actions/checkout@v4
91-
- name: Check out PR head
92-
uses: actions/checkout@v4
93-
if: github.event.pull_request.number
86+
- uses: actions/checkout@v4
9487
with:
95-
# WARNING: This is potentially dangerous since we're checking out unreviewed code,
96-
# and since we're using the pull_request_target event we can use secrets.
97-
# Thus, we must be extra careful to never expose secrets to steps that execute this code,
98-
# and to strictly limit our set of secrets to those that only pose minor security threats.
99-
# This means in particular we won't expose Develocity credentials to the main maven executions,
100-
# but instead will execute maven a third time just to push build scans to Develocity; (once we have scans enabled)
101-
ref: "refs/pull/${{ github.event.pull_request.number }}/head"
88+
persist-credentials: false
10289
- name: Set up Java ${{ matrix.os.java.version }}
10390
uses: actions/setup-java@v4
10491
with:
@@ -109,38 +96,44 @@ jobs:
10996
uses: actions/cache@v4
11097
with:
11198
path: ~/.m2/repository
112-
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
99+
# use a different key than workflows running in trusted mode
100+
key: ${{ github.event_name == 'push' && 'trusted' || 'untrusted' }}-${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
113101
restore-keys: |
114-
${{ runner.os }}-maven-
102+
${{ github.event_name == 'push' && 'trusted' || 'untrusted' }}-${{ runner.os }}-maven-
115103
- name: Set up Maven
116104
run: ./mvnw -v
117105

118106
- name: Build code and run tests and basic checks
119107
run: |
120108
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} clean install \
121109
-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-initial-${{ matrix.os.name }}
120+
path: ~/.m2/.develocity/build-scan-data
122121

123122
- name: Build code and run tests in container mode
124123
run: |
125124
./mvnw $MAVEN_ARGS ${{ matrix.os.maven.args }} clean verify \
126125
-Pjqassistant -Pskip-checks \
127126
-am -pl :hibernate-validator-tck-runner \
128127
-Dincontainer -Dincontainer-prepared
129-
# Workaround for https://github.com/actions/upload-artifact/issues/240
130-
- name: List build reports to upload (if build failed)
131-
if: ${{ failure() || cancelled() }}
132-
# The weird syntax is because we're setting a multiline environment variable
133-
# See https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#example-of-a-multiline-string
134-
run: |
135-
{
136-
echo 'buildReportPaths<<EOF'
137-
find . -path '**/*-reports'
138-
echo EOF
139-
} >> "$GITHUB_ENV"
140-
- name: Upload build reports (if build failed)
128+
env:
129+
DEVELOCITY_ACCESS_KEY: "${{ secrets.DEVELOCITY_ACCESS_KEY || '' }}"
130+
# Same as above, but for the build scan of the latest Maven run.
131+
- name: Upload GitHub Actions artifact for the Develocity build scan
141132
uses: actions/upload-artifact@v4
142-
if: ${{ failure() || cancelled() }}
133+
if: "${{ github.event_name == 'pull_request' && !cancelled() }}"
143134
with:
144-
name: ${{ format('build-reports-{0}', matrix.os.name ) }}
145-
path: ${{ env.buildReportPaths }}
146-
retention-days: 7
135+
name: build-scan-data-tck-container-${{ matrix.os.name }}
136+
path: ~/.m2/.develocity/build-scan-data
137+
138+
- name: Omit produced artifacts from build cache
139+
run: rm -r ~/.m2/repository/org/hibernate/validator

0 commit comments

Comments
 (0)