-
Notifications
You must be signed in to change notification settings - Fork 5
237 lines (207 loc) · 8.8 KB
/
bundle-ci.yml
File metadata and controls
237 lines (207 loc) · 8.8 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
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Bundle CI
on:
pull_request:
paths:
- 'extensions/**'
- 'pom.xml'
- 'checkstyle.xml'
- 'pmd-ruleset.xml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
pull-requests: write
env:
MAVEN_OPTS: >-
-Xmx4g
-Dorg.slf4j.simpleLogger.defaultLogLevel=WARN
jobs:
detect-bundles:
runs-on: ubuntu-latest
outputs:
bundles: ${{ steps.find-bundles.outputs.bundles }}
has_bundles: ${{ steps.find-bundles.outputs.has_bundles }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Detect Changed Bundles
id: find-bundles
run: |
CHANGED_FILES=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }}...HEAD)
BUNDLES=()
for file in $CHANGED_FILES; do
if [[ "$file" == extensions/* ]]; then
dir="$file"
while [[ "$dir" != "extensions" && "$dir" != "." ]]; do
if [[ -f "$dir/pom.xml" ]] && grep -q '<packaging>pom</packaging>' "$dir/pom.xml" 2>/dev/null; then
if grep -q '<modules>' "$dir/pom.xml" 2>/dev/null; then
BUNDLES+=("$dir")
break
fi
fi
dir=$(dirname "$dir")
done
fi
done
UNIQUE_BUNDLES=($(printf '%s\n' "${BUNDLES[@]}" | sort -u))
if [ ${#UNIQUE_BUNDLES[@]} -eq 0 ]; then
echo "bundles=[]" >> $GITHUB_OUTPUT
echo "has_bundles=false" >> $GITHUB_OUTPUT
else
JSON=$(printf '%s\n' "${UNIQUE_BUNDLES[@]}" | jq -R . | jq -sc .)
echo "bundles=$JSON" >> $GITHUB_OUTPUT
echo "has_bundles=true" >> $GITHUB_OUTPUT
fi
build:
needs: detect-bundles
if: needs.detect-bundles.outputs.has_bundles == 'true'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
bundle: ${{ fromJson(needs.detect-bundles.outputs.bundles) }}
name: Build ${{ matrix.bundle }}
steps:
- name: Checkout Code
uses: actions/checkout@v6
- name: Set up Java 21
uses: actions/setup-java@v5
with:
distribution: 'corretto'
java-version: '21'
cache: 'maven'
- name: Build, Verify, and Generate Coverage
run: >
./mvnw clean verify
-Pcontrib-check,report-code-coverage
-f ${{ matrix.bundle }}/pom.xml
--show-version
--no-snapshot-updates
--no-transfer-progress
--fail-fast
- name: Post Coverage Summary on PR
if: always() && github.event_name == 'pull_request'
uses: actions/github-script@v9
with:
script: |
const fs = require('fs');
const path = require('path');
const bundlePath = '${{ matrix.bundle }}';
const bundleName = path.basename(bundlePath);
const globber = await glob.create(`${bundlePath}/**/target/site/jacoco/jacoco.xml`);
const files = await globber.glob();
if (files.length === 0) {
core.info('No JaCoCo XML reports found');
return;
}
let totalInstructions = 0;
let coveredInstructions = 0;
let totalBranches = 0;
let coveredBranches = 0;
let totalLines = 0;
let coveredLines = 0;
const moduleReports = [];
for (const file of files) {
const content = fs.readFileSync(file, 'utf8');
const modulePath = path.relative(bundlePath, path.dirname(path.dirname(path.dirname(file))));
const counterRegex = /<counter type="(\w+)" missed="(\d+)" covered="(\d+)"\/>/g;
let match;
let moduleInstr = { missed: 0, covered: 0 };
let moduleBranch = { missed: 0, covered: 0 };
let moduleLine = { missed: 0, covered: 0 };
while ((match = counterRegex.exec(content)) !== null) {
const [, type, missed, covered] = match;
if (type === 'INSTRUCTION') {
moduleInstr.missed += parseInt(missed);
moduleInstr.covered += parseInt(covered);
} else if (type === 'BRANCH') {
moduleBranch.missed += parseInt(missed);
moduleBranch.covered += parseInt(covered);
} else if (type === 'LINE') {
moduleLine.missed += parseInt(missed);
moduleLine.covered += parseInt(covered);
}
}
totalInstructions += moduleInstr.missed + moduleInstr.covered;
coveredInstructions += moduleInstr.covered;
totalBranches += moduleBranch.missed + moduleBranch.covered;
coveredBranches += moduleBranch.covered;
totalLines += moduleLine.missed + moduleLine.covered;
coveredLines += moduleLine.covered;
const lineTotal = moduleLine.missed + moduleLine.covered;
const linePct = lineTotal > 0 ? ((moduleLine.covered / lineTotal) * 100).toFixed(1) : 'N/A';
moduleReports.push({ module: modulePath, linePct, lineTotal, lineCovered: moduleLine.covered });
}
const overallLinePct = totalLines > 0 ? ((coveredLines / totalLines) * 100).toFixed(1) : 'N/A';
const overallBranchPct = totalBranches > 0 ? ((coveredBranches / totalBranches) * 100).toFixed(1) : 'N/A';
const overallInstrPct = totalInstructions > 0 ? ((coveredInstructions / totalInstructions) * 100).toFixed(1) : 'N/A';
const passFail = parseFloat(overallLinePct) >= 80.0 ? ':white_check_mark:' : ':x:';
let body = `## Code Coverage: \`${bundleName}\` ${passFail}\n\n`;
body += `| Metric | Coverage |\n`;
body += `|--------|----------|\n`;
body += `| **Line** | **${overallLinePct}%** (${coveredLines}/${totalLines}) |\n`;
body += `| Branch | ${overallBranchPct}% (${coveredBranches}/${totalBranches}) |\n`;
body += `| Instruction | ${overallInstrPct}% (${coveredInstructions}/${totalInstructions}) |\n\n`;
if (moduleReports.length > 1) {
body += `<details><summary>Module Breakdown</summary>\n\n`;
body += `| Module | Line Coverage |\n`;
body += `|--------|---------------|\n`;
for (const m of moduleReports) {
body += `| ${m.module} | ${m.linePct}% (${m.lineCovered}/${m.lineTotal}) |\n`;
}
body += `\n</details>\n\n`;
}
body += `> Threshold: 80% line coverage required`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const marker = `Code Coverage: \`${bundleName}\``;
const existing = comments.find(c => c.body && c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}
- name: Upload Coverage to Codecov
if: always()
uses: codecov/codecov-action@v6
with:
flags: ${{ hashFiles(format('{0}/pom.xml', matrix.bundle)) }}
directory: ${{ matrix.bundle }}
token: ${{ secrets.CODECOV_TOKEN }}
continue-on-error: true
- name: Upload Test Reports
uses: actions/upload-artifact@v7
with:
name: surefire-reports-${{ hashFiles(format('{0}/pom.xml', matrix.bundle)) }}
path: |
${{ matrix.bundle }}/**/target/surefire-reports/*.txt
${{ matrix.bundle }}/**/target/surefire-reports/*.xml
retention-days: 7
if: failure()