Repository navigation
301 lines (275 loc) · 11.1 KB
/
Copy pathreuse_java_build_test.yml
File metadata and controls
301 lines (275 loc) · 11.1 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
# Shared Java build + per-module test matrix for eclipse-daanse.
# All inputs are optional; defaults reproduce the previous single-job behaviour.
#
# Two contracts that must not break:
# * the `build` job saves cache key build-${{ runner.os }}-${{ github.sha }}
# (paths ~/.m2/repository/org/eclipse/daanse and **/target) exactly once -
# reuse_java_deploy.yml restores it with fail-on-cache-miss: true.
# * the first job keeps the id `build` and declares no `name:`, so the check
# context stays `<callerJobId> / build` for branch protection.
name: Java Build, Test
on:
workflow_call:
inputs:
java-version:
description: 'JDK version for build and test jobs.'
required: false
type: string
default: '25'
java-distribution:
description: 'JDK distribution passed to actions/setup-java.'
required: false
type: string
default: 'temurin'
runs-on:
description: 'Runner label for all jobs.'
required: false
type: string
default: 'ubuntu-latest'
matrix-mode:
description: >-
reactor (default) = modules that compiled tests into target/test-classes;
single = one job over the whole reactor.
required: false
type: string
default: 'reactor'
test-goal:
description: >-
Must be verify or later: bnd-testing-maven-plugin binds to
integration-test, so `test` would skip every OSGi integration test.
required: false
type: string
default: 'verify'
build-maven-args:
description: 'Extra arguments appended to the build job mvn invocation.'
required: false
type: string
default: ''
test-maven-args:
description: 'Extra arguments appended to each test job mvn invocation.'
required: false
type: string
default: ''
max-parallel:
description: 'Cap on concurrently running test jobs.'
required: false
type: number
default: 256
build-timeout-minutes:
description: 'Timeout for the build job.'
required: false
type: number
default: 60
test-timeout-minutes:
description: 'Timeout for each test job.'
required: false
type: number
default: 60
artifact-retention-days:
description: 'Retention for the per-module test report artifacts (minimum 1).'
required: false
type: number
default: 1
docker-check:
description: >-
Fail fast if the host Docker daemon is unavailable. The old
`services: docker` dind container was a no-op and has been removed.
required: false
type: boolean
default: false
require-tests:
description: 'Fail the Test Results job if no JUnit XML was produced at all.'
required: false
type: boolean
default: true
fail-on-test-failure:
description: 'Fail Test Results when any JUnit XML reports a failure or error.'
required: false
type: boolean
default: true
pr-comment:
description: >-
Post a PR comment with the summary. Needs pull-requests: write on the
caller token; harmless when unavailable.
required: false
type: boolean
default: false
jobs:
# Build once; also computes the test matrix.
build:
runs-on: ${{ inputs.runs-on }}
timeout-minutes: ${{ inputs.build-timeout-minutes }}
permissions:
contents: read
outputs:
# Always a valid non-empty matrix; the sentinel entry is never expanded
# because `test` is gated on has-modules.
matrix: ${{ steps.modules.outputs.matrix }}
has-modules: ${{ steps.modules.outputs.has-modules }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up JDK ${{ inputs.java-version }}
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0
with:
java-version: ${{ inputs.java-version }}
distribution: ${{ inputs.java-distribution }}
cache: maven
# -DskipTests (never -Dmaven.test.skip=true, which would skip test
# compilation and break bnd-maven-plugin:test-jar). The bnd skips keep the
# OSGi resolve/test round in the test job where it belongs.
- name: Build with Maven (no tests)
shell: bash
env:
EXTRA_ARGS: ${{ inputs.build-maven-args }}
run: |
set -euo pipefail
# shellcheck disable=SC2086 # EXTRA_ARGS is intentionally word-split
mvn -B --no-transfer-progress -U install --file pom.xml \
-DskipTests \
-Dbnd.testing.skip=true \
-Dbnd.resolve.skip=true \
${EXTRA_ARGS}
# Saved before anything else can touch target/, and only here.
- name: Save Maven build artifacts to cache
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: |
~/.m2/repository/org/eclipse/daanse
**/target
key: build-${{ runner.os }}-${{ github.sha }}
- name: Determine test module matrix
id: modules
shell: bash
env:
MATRIX_MODE: ${{ inputs.matrix-mode }}
run: |
set -euo pipefail
# A module has tests iff the build compiled some into target/test-classes.
# That single signal is reactor-derived (a directory the build never
# visited has no target/), skips aggregators, and covers the bnd OSGi
# tests, whose *.integration.* classes are compiled here too.
if [ "$MATRIX_MODE" = single ]; then
modules=.
else
modules=$(find . -type f -path '*/target/test-classes/*' -name '*.class' \
| sed 's|/target/test-classes/.*||; s|^\./||' | sort -u)
fi
if [ -z "$modules" ]; then
# A skipped test job does not fail the workflow, so never report a
# green build when test sources plainly exist.
if find . -type d -path '*/src/test/java' -not -path '*/target/*' -print -quit | grep -q .; then
echo "::error::No compiled tests found although this repository has test sources. Refusing a green, untested build."
exit 1
fi
echo "has-modules=false" >> "$GITHUB_OUTPUT"
echo 'matrix={"module":["-none-"]}' >> "$GITHUB_OUTPUT"
echo 'No modules with tests.' >> "$GITHUB_STEP_SUMMARY"
exit 0
fi
echo "has-modules=true" >> "$GITHUB_OUTPUT"
jq -Rsc 'split("\n") | map(select(length > 0)) | {module: .}' <<<"$modules" \
| sed 's/^/matrix=/' >> "$GITHUB_OUTPUT"
printf '* `%s`\n' $modules >> "$GITHUB_STEP_SUMMARY"
# One job per module. No continue-on-error: a red cell must fail the workflow
# so the callers' `needs: build_test` blocks deploy.
test:
name: Test ${{ matrix.module }}
needs: build
if: needs.build.outputs.has-modules == 'true'
runs-on: ${{ inputs.runs-on }}
timeout-minutes: ${{ inputs.test-timeout-minutes }}
permissions:
contents: read
strategy:
fail-fast: false # do NOT cancel siblings; does NOT mask failure
max-parallel: ${{ inputs.max-parallel }}
matrix: ${{ fromJson(needs.build.outputs.matrix) }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up JDK ${{ inputs.java-version }}
uses: actions/setup-java@b6effb05e454b25005698d916606bdc6ffcbf961 # v5.7.0
with:
java-version: ${{ inputs.java-version }}
distribution: ${{ inputs.java-distribution }}
cache: maven
# Restore only - the build job is the single writer of this key.
- name: Restore Maven build artifacts
uses: actions/cache/restore@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: |
~/.m2/repository/org/eclipse/daanse
**/target
key: build-${{ runner.os }}-${{ github.sha }}
fail-on-cache-miss: true
- name: Verify Docker daemon
if: ${{ inputs.docker-check }}
run: docker info
# -pl from the repo root, not `cd <module>`: keeps ${revision} parent
# resolution and maven.multiModuleProjectDirectory identical to the build.
# bnd-baseline (downloads the last release per module) and editorconfig
# (covered elsewhere) are skipped here.
- name: Run tests for ${{ matrix.module }}
shell: bash
env:
MODULE: ${{ matrix.module }}
TEST_GOAL: ${{ inputs.test-goal }}
EXTRA_ARGS: ${{ inputs.test-maven-args }}
run: |
set -euo pipefail
args=(-B --no-transfer-progress -Dbnd.baseline.skip=true -Deditorconfig.skip=true)
if [ "$MODULE" != "." ]; then
args+=(-pl "$MODULE")
fi
# shellcheck disable=SC2086 # EXTRA_ARGS is intentionally word-split
mvn "${args[@]}" ${EXTRA_ARGS} "$TEST_GOAL"
# Both report shapes: surefire-reports and the bnd test-reports/<runName>.
- name: Upload test reports for ${{ matrix.module }}
if: always()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: test-results-${{ strategy.job-index }}
path: |
${{ matrix.module }}/target/surefire-reports/TEST-*.xml
${{ matrix.module }}/target/failsafe-reports/TEST-*.xml
${{ matrix.module }}/target/test-reports/*/TEST-*.xml
if-no-files-found: ignore
retention-days: ${{ inputs.artifact-retention-days }}
# ---------------------------------------------------------------------------
# Publish and gate on the aggregated JUnit results.
# No `permissions:` block: a called workflow may only narrow the caller's
# token, and requesting checks:write would hard-fail callers whose org default
# is read-only.
# ---------------------------------------------------------------------------
test-results:
name: Test Results
needs: [build, test]
if: always()
runs-on: ${{ inputs.runs-on }}
timeout-minutes: 10
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
if: needs.build.outputs.has-modules == 'true'
- name: Download all test reports
if: needs.build.outputs.has-modules == 'true'
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: test-results-*
path: test-results
# Renders the check/summary AND gates: fail_on_failure catches a shard whose
# mvn exit code was masked, require_tests catches a run that produced no XML.
- name: Publish test report
if: needs.build.outputs.has-modules == 'true'
uses: mikepenz/action-junit-report@a9170d5795813c01ab4901ffb045b52bab4ab09d # v6.5.0
with:
report_paths: 'test-results/**/TEST-*.xml'
check_name: 'Test Results'
token: ${{ github.token }}
fail_on_failure: ${{ inputs.fail-on-test-failure }}
require_tests: ${{ inputs.require-tests }}
detailed_summary: true
group_suite: true
include_time_in_summary: true
truncate_stack_traces: false
job_summary: true
comment: ${{ inputs.pr-comment }}
updateComment: true