6464 }
6565 console.log(`Posting report for PR #${prNumber}`);
6666
67+ const { parseJacocoXml, pct, zeroCov } = require('./.github/scripts/parse-jacoco.js');
68+
6769 const versions = ['java11', 'java17', 'java21', 'java25', 'jcstress'];
6870 const zeroTest = { total: 0, passed: 0, failed: 0, errors: 0, skipped: 0 };
69- const zeroCov = { covered: 0, missed: 0 };
7071
7172 // --- Read current test stats from artifacts ---
7273 const current = {};
@@ -90,44 +91,12 @@ jobs:
9091 const baseClasses = (baseline.coverage || {}).classes || {};
9192
9293 // --- Parse JaCoCo XML for coverage ---
93- let covLine = null, covBranch = null, covMethod = null;
94- const classCounters = {};
9594 const jacocoFile = path.join('coverage', 'jacocoTestReport.xml');
96- if (fs.existsSync(jacocoFile)) {
97- const xml = fs.readFileSync(jacocoFile, 'utf8');
98- const stripped = xml.replace(/<package[\s\S]*?<\/package>/g, '');
99- const re = /<counter type="(\w+)" missed="(\d+)" covered="(\d+)"\/>/g;
100- let m;
101- while ((m = re.exec(stripped)) !== null) {
102- const entry = { covered: parseInt(m[3]), missed: parseInt(m[2]) };
103- if (m[1] === 'LINE') covLine = entry;
104- else if (m[1] === 'BRANCH') covBranch = entry;
105- else if (m[1] === 'METHOD') covMethod = entry;
106- }
107-
108- const pkgRe = /<package\s+name="([^"]+)">([\s\S]*?)<\/package>/g;
109- let pkgMatch;
110- while ((pkgMatch = pkgRe.exec(xml)) !== null) {
111- const pkgName = pkgMatch[1].replace(/\//g, '.');
112- const pkgBody = pkgMatch[2];
113- const classRe = /<class\s+name="([^"]+)"[^>]*>([\s\S]*?)<\/class>/g;
114- let classMatch;
115- while ((classMatch = classRe.exec(pkgBody)) !== null) {
116- const className = classMatch[1].replace(/\//g, '.');
117- const classBody = classMatch[2];
118- const counters = { line: { ...zeroCov }, branch: { ...zeroCov }, method: { ...zeroCov } };
119- const cntRe = /<counter type="(\w+)" missed="(\d+)" covered="(\d+)"\/>/g;
120- let cntMatch;
121- while ((cntMatch = cntRe.exec(classBody)) !== null) {
122- const entry = { covered: parseInt(cntMatch[3]), missed: parseInt(cntMatch[2]) };
123- if (cntMatch[1] === 'LINE') counters.line = entry;
124- else if (cntMatch[1] === 'BRANCH') counters.branch = entry;
125- else if (cntMatch[1] === 'METHOD') counters.method = entry;
126- }
127- classCounters[className] = counters;
128- }
129- }
130- }
95+ const parsed = parseJacocoXml(jacocoFile);
96+ const covLine = parsed?.overall?.line || null;
97+ const covBranch = parsed?.overall?.branch || null;
98+ const covMethod = parsed?.overall?.method || null;
99+ const classCounters = parsed?.classes || {};
131100
132101 // --- Helpers ---
133102 function delta(curr, prev, positiveIsGood) {
@@ -143,11 +112,6 @@ jobs:
143112 return `${curr} (${delta(curr, prev, positiveIsGood)})`;
144113 }
145114
146- function pct(covered, missed) {
147- const total = covered + missed;
148- return total === 0 ? 0 : (covered / total * 100);
149- }
150-
151115 function fmtPct(value) {
152116 return value.toFixed(1) + '%';
153117 }
0 commit comments