Skip to content

Commit a5cc3e9

Browse files
committed
implemented report pipeline that runs tests and fails if they don't pass, generate jacoco code coverage report, run PMD Static anaylsis, convert HTML reports to png, and provide clear local development
1 parent a305d16 commit a5cc3e9

File tree

5 files changed

+194
-1
lines changed

5 files changed

+194
-1
lines changed

.github/workflows/ci-reports.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI Reports
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
ci-reports:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Set up JDK 17
16+
uses: actions/setup-java@v4
17+
with:
18+
java-version: '17'
19+
distribution: 'temurin'
20+
21+
- name: Cache Maven dependencies
22+
uses: actions/cache@v4
23+
with:
24+
path: ~/.m2
25+
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
26+
restore-keys: ${{ runner.os }}-m2
27+
28+
- name: Run tests
29+
run: mvn -B clean test
30+
31+
- name: Generate reports
32+
run: mvn -B jacoco:report pmd:pmd pmd:check
33+
34+
- name: Install wkhtmltopdf
35+
run: |
36+
sudo apt-get update
37+
sudo apt-get install -y wkhtmltopdf
38+
39+
- name: Make script executable
40+
run: chmod +x scripts/html_to_png.sh
41+
42+
- name: Convert HTML reports to PNG
43+
run: bash scripts/html_to_png.sh
44+
45+
- name: Upload CI reports
46+
uses: actions/upload-artifact@v4
47+
if: always()
48+
with:
49+
name: ci-reports
50+
path: reports/*

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,26 @@ This repository using GitHub Actions to perform continous integration, to view t
118118

119119
Click on the latest job on the top under "X workflow runs" then Click 'build' under jobs finally click the drop down next to all the action items to read the logs made during their execution.
120120

121+
## CI Reports (JaCoCo + PMD)
122+
This project generates automated code coverage (JaCoCo) and static analysis (PMD) reports as part of the CI pipeline. To run these reports locally:
123+
124+
```bash
125+
# Run unit tests
126+
mvn clean test
127+
128+
# Generate JaCoCo coverage and PMD analysis reports
129+
mvn jacoco:report pmd:pmd pmd:check
130+
131+
# Convert HTML reports to PNG snapshots
132+
bash scripts/html_to_png.sh
133+
```
134+
135+
The generated PNG reports will be saved to:
136+
- `/reports/jacoco.png` - JaCoCo code coverage report
137+
- `/reports/pmd.png` - PMD static analysis report
138+
139+
These reports are automatically uploaded as GitHub Actions artifacts named "ci-reports" on every push and pull request.
140+
121141
## Tools used
122142
This section includes notes on tools and technologies used in building this project, as well as any additional details if applicable.
123143

config/pmd/ruleset.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="MetaDetect PMD Rules"
3+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0
6+
https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
7+
8+
<description>PMD Rules for MetaDetect Service</description>
9+
10+
<!-- Best Practices -->
11+
<rule ref="category/java/bestpractices.xml">
12+
<!-- Disable rules that may be too noisy for this project -->
13+
<exclude name="JUnitTestContainsTooManyAsserts"/>
14+
<exclude name="JUnitAssertionsShouldIncludeMessage"/>
15+
</rule>
16+
17+
<!-- Code Style -->
18+
<rule ref="category/java/codestyle.xml">
19+
<!-- Disable overly strict naming rules -->
20+
<exclude name="LongVariable"/>
21+
<exclude name="ShortVariable"/>
22+
<exclude name="OnlyOneReturn"/>
23+
<exclude name="AtLeastOneConstructor"/>
24+
<exclude name="LocalVariableCouldBeFinal"/>
25+
<exclude name="MethodArgumentCouldBeFinal"/>
26+
</rule>
27+
28+
<!-- Error Prone -->
29+
<rule ref="category/java/errorprone.xml">
30+
<!-- Exclude rules that may conflict with Spring Boot patterns -->
31+
<exclude name="DataflowAnomalyAnalysis"/>
32+
<exclude name="BeanMembersShouldSerialize"/>
33+
</rule>
34+
35+
<!-- Performance -->
36+
<rule ref="category/java/performance.xml"/>
37+
38+
<!-- Design -->
39+
<rule ref="category/java/design.xml">
40+
<!-- Disable overly strict complexity rules -->
41+
<exclude name="TooManyMethods"/>
42+
<exclude name="LawOfDemeter"/>
43+
<exclude name="LoosePackageCoupling"/>
44+
<exclude name="DataClass"/>
45+
</rule>
46+
47+
</ruleset>

pom.xml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,19 @@
142142
<configuration>
143143
<printFailingErrors>true</printFailingErrors>
144144
<failOnViolation>true</failOnViolation>
145+
<rulesets>
146+
<ruleset>config/pmd/ruleset.xml</ruleset>
147+
</rulesets>
148+
<includeTests>true</includeTests>
149+
<targetJdk>${java.version}</targetJdk>
145150
</configuration>
146151
<executions>
147152
<execution>
153+
<id>pmd-check</id>
148154
<phase>verify</phase>
149-
<goals><goal>check</goal></goals>
155+
<goals>
156+
<goal>check</goal>
157+
</goals>
150158
</execution>
151159
</executions>
152160
</plugin>
@@ -188,4 +196,36 @@
188196
</plugin>
189197
</plugins>
190198
</build>
199+
200+
<reporting>
201+
<plugins>
202+
<!-- JaCoCo HTML report generation -->
203+
<plugin>
204+
<groupId>org.jacoco</groupId>
205+
<artifactId>jacoco-maven-plugin</artifactId>
206+
<version>0.8.12</version>
207+
<reportSets>
208+
<reportSet>
209+
<reports>
210+
<report>report</report>
211+
</reports>
212+
</reportSet>
213+
</reportSets>
214+
</plugin>
215+
216+
<!-- PMD HTML report generation -->
217+
<plugin>
218+
<groupId>org.apache.maven.plugins</groupId>
219+
<artifactId>maven-pmd-plugin</artifactId>
220+
<version>3.21.2</version>
221+
<configuration>
222+
<rulesets>
223+
<ruleset>config/pmd/ruleset.xml</ruleset>
224+
</rulesets>
225+
<includeTests>true</includeTests>
226+
<targetJdk>${java.version}</targetJdk>
227+
</configuration>
228+
</plugin>
229+
</plugins>
230+
</reporting>
191231
</project>

scripts/html_to_png.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Converting HTML reports to PNG..."
6+
7+
# Ensure reports directory exists
8+
mkdir -p reports
9+
10+
# Check for JaCoCo HTML report
11+
JACOCO_HTML="target/site/jacoco/index.html"
12+
if [ ! -f "$JACOCO_HTML" ]; then
13+
echo "ERROR: JaCoCo HTML report not found at $JACOCO_HTML"
14+
exit 1
15+
fi
16+
17+
# Check for PMD HTML report (try both possible locations)
18+
PMD_HTML=""
19+
if [ -f "target/site/pmd.html" ]; then
20+
PMD_HTML="target/site/pmd.html"
21+
elif [ -f "target/site/pmd/index.html" ]; then
22+
PMD_HTML="target/site/pmd/index.html"
23+
else
24+
echo "ERROR: PMD HTML report not found at target/site/pmd.html or target/site/pmd/index.html"
25+
exit 1
26+
fi
27+
28+
echo "Converting JaCoCo report: $JACOCO_HTML -> reports/jacoco.png"
29+
wkhtmltoimage --width 1600 --quality 90 "$JACOCO_HTML" reports/jacoco.png
30+
31+
echo "Converting PMD report: $PMD_HTML -> reports/pmd.png"
32+
wkhtmltoimage --width 1600 --quality 90 "$PMD_HTML" reports/pmd.png
33+
34+
echo "HTML to PNG conversion completed successfully"
35+
echo "Generated files:"
36+
ls -la reports/

0 commit comments

Comments
 (0)