run-coverage-badge.ps1¶
Merges one or more JaCoCo execution files, writes the coverage report to target/site/jacoco/ and produces coverage-badge.json (the shields.io endpoint format the README badge reads).
Usage¶
.\run-coverage-badge.ps1 # target/jacoco.exec
.\run-coverage-badge.ps1 -ExecFiles coverage/unit/jacoco.exec,coverage/integration/jacoco.exec,coverage/e2e/jacoco.exec
.\run-coverage-badge.ps1 -BadgePath site/coverage-badge.json
What It Does¶
- Downloads the JaCoCo command-line tool once (
org.jacoco:org.jacoco.cli:nodepsintotarget/) and compiles the sources iftarget/classesis missing. - Merges the execution files (
jacoco merge) when more than one is given — this is how the CI shards (unit, integration, end-to-end) are combined into one number. - Generates the CSV, HTML and XML report (
jacoco report). - Sums
LINE_COVERED/LINE_MISSEDfrom the CSV and writes the badge JSON with the colour thresholds below.
| Coverage | Color |
|---|---|
| ≥ 80% | brightgreen |
| ≥ 60% | green |
| ≥ 40% | yellow |
| < 40% | red |
Where It Runs¶
run-on-develop-push.ps1calls it after the sequential local run (singletarget/jacoco.exec).- The Develop workflow's final
Build & Testjob calls it with the three shard files downloaded as artifacts, then uploadscoverage-badge.jsonas thecoverage-badgeartifact that the release publishes with the documentation site.
Exit Code¶
0— badge written1— no execution file found, or the JaCoCo CLI, compile, merge or report step failed
Prerequisites¶
- PowerShell 7+, Java 21, Maven