Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit 9420050

Browse files
ci: add JaCoCo code coverage reporting workflow
- Uses JaCoCo 0.8.12 agent to instrument tests and collect coverage data - Generates HTML, XML, and CSV coverage reports - Publishes coverage summary in GitHub Actions step summary - Uploads coverage report as build artifact (30-day retention) - Includes optional Codecov upload for external tracking - Runs on JDK 17, covers all test suites including CommunityDetectorTest - Added coverage badge to README
1 parent af41306 commit 9420050

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

.github/workflows/coverage.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Code Coverage
2+
3+
on:
4+
push:
5+
branches: [main, master]
6+
pull_request:
7+
branches: [main, master]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
coverage:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Set up JDK 17
21+
uses: actions/setup-java@v4
22+
with:
23+
java-version: 17
24+
distribution: temurin
25+
26+
- name: Download test dependencies
27+
run: |
28+
mkdir -p Gvisual/lib/test
29+
# JUnit 4 + Hamcrest
30+
curl -sL -o Gvisual/lib/test/junit-4.13.2.jar \
31+
https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar
32+
curl -sL -o Gvisual/lib/test/hamcrest-core-1.3.jar \
33+
https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
34+
# JaCoCo agent + CLI for coverage instrumentation and reporting
35+
curl -sL -o /tmp/jacoco.zip \
36+
https://repo1.maven.org/maven2/org/jacoco/jacoco/0.8.12/jacoco-0.8.12.zip
37+
unzip -o /tmp/jacoco.zip -d /tmp/jacoco
38+
cp /tmp/jacoco/lib/jacocoagent.jar Gvisual/lib/test/jacocoagent.jar
39+
cp /tmp/jacoco/lib/jacococli.jar Gvisual/lib/test/jacococli.jar
40+
41+
- name: Compile source
42+
working-directory: Gvisual
43+
run: |
44+
mkdir -p build/classes
45+
find src -name '*.java' > sources.txt
46+
javac -source 8 -target 8 \
47+
-cp "$(find lib -name '*.jar' -not -path 'lib/test/*' | tr '\n' ':')" \
48+
-d build/classes \
49+
@sources.txt
50+
51+
- name: Compile tests
52+
working-directory: Gvisual
53+
run: |
54+
mkdir -p build/test/classes
55+
find test -name '*.java' > test-sources.txt
56+
javac -source 8 -target 8 \
57+
-cp "build/classes:$(find lib -name '*.jar' | tr '\n' ':')" \
58+
-d build/test/classes \
59+
@test-sources.txt
60+
61+
- name: Run tests with JaCoCo coverage
62+
working-directory: Gvisual
63+
run: |
64+
java \
65+
-javaagent:lib/test/jacocoagent.jar=destfile=build/jacoco.exec,includes=gvisual.*:app.* \
66+
-cp "build/classes:build/test/classes:$(find lib -name '*.jar' | tr '\n' ':')" \
67+
org.junit.runner.JUnitCore \
68+
app.UtilMethodsTest \
69+
gvisual.EdgeTest \
70+
gvisual.GraphStatsTest \
71+
gvisual.ShortestPathFinderTest \
72+
gvisual.CommunityDetectorTest
73+
74+
- name: Generate coverage report
75+
working-directory: Gvisual
76+
run: |
77+
mkdir -p build/coverage
78+
# Generate HTML report
79+
java -jar lib/test/jacococli.jar report build/jacoco.exec \
80+
--classfiles build/classes \
81+
--sourcefiles src \
82+
--html build/coverage/html \
83+
--xml build/coverage/coverage.xml \
84+
--csv build/coverage/coverage.csv \
85+
--name "GraphVisual Coverage Report"
86+
87+
- name: Coverage summary
88+
working-directory: Gvisual
89+
run: |
90+
echo "## 📊 Code Coverage Report" >> $GITHUB_STEP_SUMMARY
91+
echo "" >> $GITHUB_STEP_SUMMARY
92+
# Parse CSV for summary (skip header, sum instruction covered/missed)
93+
if [ -f build/coverage/coverage.csv ]; then
94+
echo "| Package | Class | Instruction Coverage |" >> $GITHUB_STEP_SUMMARY
95+
echo "|---------|-------|---------------------|" >> $GITHUB_STEP_SUMMARY
96+
tail -n +2 build/coverage/coverage.csv | while IFS=',' read -r group package class inst_missed inst_covered branch_missed branch_covered line_missed line_covered complexity_missed complexity_covered method_missed method_covered; do
97+
total=$((inst_missed + inst_covered))
98+
if [ "$total" -gt 0 ]; then
99+
pct=$((inst_covered * 100 / total))
100+
echo "| $package | $class | ${pct}% (${inst_covered}/${total}) |" >> $GITHUB_STEP_SUMMARY
101+
fi
102+
done
103+
fi
104+
105+
- name: Upload coverage report
106+
uses: actions/upload-artifact@v4
107+
with:
108+
name: coverage-report
109+
path: Gvisual/build/coverage/
110+
retention-days: 30
111+
112+
- name: Upload coverage to Codecov
113+
uses: codecov/codecov-action@v4
114+
with:
115+
files: Gvisual/build/coverage/coverage.xml
116+
fail_ci_if_error: false
117+
continue-on-error: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Built with Java and [JUNG](http://jung.sourceforge.net/) (Java Universal Network
1212
[![JUNG](https://img.shields.io/badge/JUNG-2.0.1-blue)](http://jung.sourceforge.net/)
1313
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/sauravbhattacharya001/GraphVisual/blob/master/LICENSE)
1414
[![Docker](https://github.com/sauravbhattacharya001/GraphVisual/actions/workflows/docker.yml/badge.svg)](https://github.com/sauravbhattacharya001/GraphVisual/actions/workflows/docker.yml)
15+
[![Coverage](https://github.com/sauravbhattacharya001/GraphVisual/actions/workflows/coverage.yml/badge.svg)](https://github.com/sauravbhattacharya001/GraphVisual/actions/workflows/coverage.yml)
1516
[![GitHub repo size](https://img.shields.io/github/repo-size/sauravbhattacharya001/GraphVisual)](https://github.com/sauravbhattacharya001/GraphVisual)
1617

1718
</div>

0 commit comments

Comments
 (0)