-
Notifications
You must be signed in to change notification settings - Fork 1.1k
232 lines (227 loc) · 9.72 KB
/
pull_request.yml
File metadata and controls
232 lines (227 loc) · 9.72 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
name: Pull Request Build
# For pull requests: builds and test
on:
push:
branches:
- '!master'
pull_request:
branches:
- master
- 23.x
- 22.x
- 21.x
- 20.x
- 19.x
permissions:
contents: read
jobs:
buildAndTest:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- gradle-argument: 'assemble && ./gradlew check -x test -x testng -x testngWithJava11 -x testngWithJava17 -x testngWithJava21'
label: 'check'
- gradle-argument: 'testWithJava11 testngWithJava11'
label: 'java11'
test-results-dirs: 'testWithJava11 testngWithJava11'
- gradle-argument: 'testWithJava17 testngWithJava17'
label: 'java17'
test-results-dirs: 'testWithJava17 testngWithJava17'
- gradle-argument: 'testWithJava21 testngWithJava21'
label: 'java21'
test-results-dirs: 'testWithJava21 testngWithJava21'
- gradle-argument: 'test -x testWithJava11 -x testWithJava17 -x testWithJava21 testng jacocoTestReport'
label: 'java25'
test-results-dirs: 'test testng'
- gradle-argument: 'jcstress'
label: 'jcstress'
steps:
- uses: actions/checkout@v6
- uses: gradle/actions/wrapper-validation@v5
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
java-version: '25'
distribution: 'corretto'
- name: build and test
run: |
if [ "${{ matrix.label }}" = "jcstress" ]; then
set -o pipefail
mkdir -p build
./gradlew ${{matrix.gradle-argument}} --info --stacktrace 2>&1 | tee build/jcstress-output.txt
else
./gradlew ${{matrix.gradle-argument}} --info --stacktrace
fi
- name: Upload Coverage HTML Report
uses: actions/upload-artifact@v4
if: always() && matrix.label == 'java25'
with:
name: jacoco-html-report
path: build/reports/jacoco/test/html/
retention-days: 14
- name: Upload Coverage XML Report
uses: actions/upload-artifact@v4
if: always() && matrix.label == 'java25'
with:
name: coverage-report
path: build/reports/jacoco/test/jacocoTestReport.xml
retention-days: 1
- name: Parse Test Results
if: always() && matrix.label != 'check' && matrix.label != 'jcstress'
run: |
total=0; failures=0; errors=0; skipped=0
for dir_name in ${{ matrix.test-results-dirs }}; do
dir="build/test-results/$dir_name"
for f in "$dir"/TEST-*.xml; do
[ -f "$f" ] || continue
t=$(grep -o 'tests="[0-9]*"' "$f" | head -1 | grep -o '[0-9]*')
fl=$(grep -o 'failures="[0-9]*"' "$f" | head -1 | grep -o '[0-9]*')
e=$(grep -o 'errors="[0-9]*"' "$f" | head -1 | grep -o '[0-9]*')
s=$(grep -o 'skipped="[0-9]*"' "$f" | head -1 | grep -o '[0-9]*')
total=$((total + ${t:-0}))
failures=$((failures + ${fl:-0}))
errors=$((errors + ${e:-0}))
skipped=$((skipped + ${s:-0}))
done
done
passed=$((total - failures - errors - skipped))
mkdir -p /tmp/test-stats
echo "{\"total\":$total,\"passed\":$passed,\"failed\":$failures,\"errors\":$errors,\"skipped\":$skipped}" \
> "/tmp/test-stats/${{ matrix.label }}.json"
- name: Parse jcstress Results
if: always() && matrix.label == 'jcstress'
run: |
total=0; passed=0; failed=0; errors=0; skipped=0
if [ -f build/jcstress-output.txt ]; then
line=$(grep 'Results:.*planned.*passed.*failed' build/jcstress-output.txt | tail -1)
if [ -n "$line" ]; then
total=$(echo "$line" | sed 's/.*Results: \([0-9]*\) planned.*/\1/')
passed=$(echo "$line" | sed 's/.*; \([0-9]*\) passed.*/\1/')
failed=$(echo "$line" | sed 's/.*passed, \([0-9]*\) failed.*/\1/')
soft=$(echo "$line" | sed 's/.*failed, \([0-9]*\) soft.*/\1/')
hard=$(echo "$line" | sed 's/.*soft errs, \([0-9]*\) hard.*/\1/')
errors=$((soft + hard))
fi
fi
mkdir -p /tmp/test-stats
echo "{\"total\":$total,\"passed\":$passed,\"failed\":$failed,\"errors\":$errors,\"skipped\":$skipped}" \
> "/tmp/test-stats/${{ matrix.label }}.json"
- name: Upload Test Stats
if: always() && matrix.label != 'check'
uses: actions/upload-artifact@v4
with:
name: test-stats-${{ matrix.label }}
path: /tmp/test-stats/${{ matrix.label }}.json
test-summary:
name: "Per-Class Coverage Gate"
needs: buildAndTest
if: always() && github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Download Coverage Report
uses: actions/download-artifact@v4
continue-on-error: true
with:
name: coverage-report
path: coverage/
- name: Enforce Per-Class Coverage Gate
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
const zeroCov = { covered: 0, missed: 0 };
// --- Read baseline from repo ---
const baselineFile = 'test-baseline.json';
let baseline = { tests: {}, coverage: {} };
if (fs.existsSync(baselineFile)) {
baseline = JSON.parse(fs.readFileSync(baselineFile, 'utf8'));
}
const baseClasses = (baseline.coverage || {}).classes || {};
// --- Parse JaCoCo XML for per-class coverage ---
const classCounters = {};
const jacocoFile = path.join('coverage', 'jacocoTestReport.xml');
if (!fs.existsSync(jacocoFile)) {
console.log('No JaCoCo report found, skipping coverage gate.');
return;
}
const xml = fs.readFileSync(jacocoFile, 'utf8');
const pkgRe = /<package\s+name="([^"]+)">([\s\S]*?)<\/package>/g;
let pkgMatch;
while ((pkgMatch = pkgRe.exec(xml)) !== null) {
const pkgBody = pkgMatch[2];
const classRe = /<class\s+name="([^"]+)"[^>]*>([\s\S]*?)<\/class>/g;
let classMatch;
while ((classMatch = classRe.exec(pkgBody)) !== null) {
const className = classMatch[1].replace(/\//g, '.');
const classBody = classMatch[2];
const counters = { line: { ...zeroCov }, branch: { ...zeroCov }, method: { ...zeroCov } };
const cntRe = /<counter type="(\w+)" missed="(\d+)" covered="(\d+)"\/>/g;
let cntMatch;
while ((cntMatch = cntRe.exec(classBody)) !== null) {
const entry = { covered: parseInt(cntMatch[3]), missed: parseInt(cntMatch[2]) };
if (cntMatch[1] === 'LINE') counters.line = entry;
else if (cntMatch[1] === 'BRANCH') counters.branch = entry;
else if (cntMatch[1] === 'METHOD') counters.method = entry;
}
classCounters[className] = counters;
}
}
function pct(covered, missed) {
const total = covered + missed;
return total === 0 ? 0 : (covered / total * 100);
}
// --- Coverage gate: fail if any class regresses on any metric ---
const regressions = [];
for (const [cls, curr] of Object.entries(classCounters)) {
const totalLines = curr.line.covered + curr.line.missed;
if (totalLines === 0) continue;
const base = baseClasses[cls] || { line: zeroCov, branch: zeroCov, method: zeroCov };
for (const [metric, key] of [['Line', 'line'], ['Branch', 'branch'], ['Method', 'method']]) {
const currPct = pct(curr[key].covered, curr[key].missed);
const basePct = pct(base[key].covered, base[key].missed);
if (currPct < basePct - 0.05) {
regressions.push(` ${cls} ${metric}: ${currPct.toFixed(1)}% (was ${basePct.toFixed(1)}%, delta ${(currPct - basePct).toFixed(1)}%)`);
}
}
}
if (regressions.length > 0) {
core.setFailed(`Per-class coverage regressions detected:\n${regressions.join('\n')}\n\nUpdate test-baseline.json if these changes are intentional.`);
}
javadoc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: gradle/actions/wrapper-validation@v5
- name: Set up JDK 25
uses: actions/setup-java@v5
with:
java-version: '25'
distribution: 'corretto'
- name: Verify Javadoc
run: ./gradlew javadoc --info --stacktrace
allBuildAndTestSuccessful:
if: always()
needs:
- buildAndTest
- test-summary
- javadoc
runs-on: ubuntu-latest
steps:
- name: Verify all jobs passed
run: |
if [ "${{ needs.buildAndTest.result }}" != "success" ]; then
echo "buildAndTest failed with result: ${{ needs.buildAndTest.result }}"
exit 1
fi
if [ "${{ needs.test-summary.result }}" != "success" ] && [ "${{ needs.test-summary.result }}" != "skipped" ]; then
echo "Per-Class Coverage Gate failed with result: ${{ needs.test-summary.result }}"
exit 1
fi
if [ "${{ needs.javadoc.result }}" != "success" ]; then
echo "javadoc failed with result: ${{ needs.javadoc.result }}"
exit 1
fi
echo "All build and test jobs passed successfully."