Skip to content

feat: add live JaCoCo coverage badge via cicirello/jacoco-badge-gener… #70

feat: add live JaCoCo coverage badge via cicirello/jacoco-badge-gener…

feat: add live JaCoCo coverage badge via cicirello/jacoco-badge-gener… #70

Workflow file for this run

name: CI
on:
push:
branches:
- main
pull_request:
permissions:
contents: write
jobs:
build:
name: Tests / ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Setup Java
uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: temurin
java-version: "21"
- name: Setup Gradle
uses: gradle/actions/setup-gradle@3f131e8634966bd73d06cc69884922b02e6faf92 # v6.2.0
with:
gradle-version: "8.10.2"
- name: Run tests and checks
run: ./gradlew check jacocoAllReport --stacktrace
- name: Generate Coverage Badge
if: matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: cicirello/jacoco-badge-generator@72266185b7ee48a6fd74eaf0238395cc8b14fef8 # v2.12.1
with:
jacoco-csv-file: build/reports/jacoco/jacocoAllReport/jacocoAllReport.csv
- name: Commit coverage badge
if: matrix.os == 'ubuntu-latest' && github.event_name == 'push' && github.ref == 'refs/heads/main'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add .github/badges/
git diff --staged --quiet || git commit -m "chore: update coverage badge [skip ci]"
git push
- name: Publish coverage summary
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
report="build/reports/jacoco/jacocoAllReport/jacocoAllReport.csv"
awk -F, '
NR > 1 {
branchMissed += $6
branchCovered += $7
lineMissed += $8
lineCovered += $9
}
END {
lineTotal = lineMissed + lineCovered
branchTotal = branchMissed + branchCovered
lineCoverage = lineTotal == 0 ? 100 : (lineCovered * 100 / lineTotal)
branchCoverage = branchTotal == 0 ? 100 : (branchCovered * 100 / branchTotal)
print "### JaCoCo coverage"
print ""
print "| Metric | Coverage |"
print "| --- | ---: |"
printf "| Lines | %.2f%% |\n", lineCoverage
printf "| Branches | %.2f%% |\n", branchCoverage
}
' "$report" >> "$GITHUB_STEP_SUMMARY"
- name: Upload coverage report
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: jacoco-report-${{ github.run_id }}
path: build/reports/jacoco/jacocoAllReport/html