From a430c47102a37c1f8b45b2e17babcf37adc45e6d Mon Sep 17 00:00:00 2001 From: Alix Deschamps Date: Wed, 29 Apr 2026 16:57:18 +0200 Subject: [PATCH] feat: add jacoco coverage and report --- .github/workflows/main.yml | 42 ++++++++++++++++++++++++++++++++++++++ lombok.config | 3 +++ pom.xml | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 lombok.config diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6652cd296..e3950e7f9 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -9,6 +9,9 @@ on: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read + pull-requests: write steps: - uses: actions/checkout@v3 @@ -20,3 +23,42 @@ jobs: cache: maven - name: Build & test run: mvn --batch-mode verify --file pom.xml + + - name: Generate JaCoCo coverage summary + if: github.event_name == 'pull_request' + run: | + python3 - <<'PYEOF' > coverage-summary.md + import glob, xml.etree.ElementTree as ET + + def pct(covered, missed): + total = covered + missed + return f"{100 * covered / total:.1f}%" if total else "—" + + rows = [] + tot_c = tot_m = 0 + for path in sorted(glob.glob("**/target/site/jacoco/jacoco.xml", recursive=True)): + root = ET.parse(path).getroot() + name = root.get("name") + counters = {c.get("type"): (int(c.get("covered")), int(c.get("missed"))) + for c in root.findall("counter")} + c, m = counters.get("INSTRUCTION", (0, 0)) + rows.append((name, c, m)) + tot_c += c + tot_m += m + + print("## Coverage JaCoCo par module") + print() + print("| Module | Coverage |") + print("|---|---:|") + for name, c, m in rows: + print(f"| `{name}` | {pct(c, m)} |") + print(f"| **Total** | **{pct(tot_c, tot_m)}** |") + PYEOF + cat coverage-summary.md + + - name: Post coverage comment + if: github.event_name == 'pull_request' + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: jacoco-coverage + path: coverage-summary.md diff --git a/lombok.config b/lombok.config new file mode 100644 index 000000000..6a3804179 --- /dev/null +++ b/lombok.config @@ -0,0 +1,3 @@ +# Make Lombok-generated code visible to tools (JaCoCo will auto-exclude +# methods annotated with @lombok.Generated from coverage reports). +lombok.addLombokGeneratedAnnotation = true diff --git a/pom.xml b/pom.xml index 9d251df54..adac944bf 100644 --- a/pom.xml +++ b/pom.xml @@ -142,4 +142,43 @@ + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.13 + + + + **/*MapperImpl.class + + + + + prepare-agent + + prepare-agent + + + + report + verify + + report + + + + + + + + + org.jacoco + jacoco-maven-plugin + + +