Skip to content

Commit 4159d78

Browse files
committed
code coverage: add JaCoCo report merge
Motivation: To improve test quality tracking, this adds JaCoCo coverage reports to the CI pipeline. Modifications: - CI: Added JaCoCo stage in .gitlab-ci.yml. - Scripts: New generate-jacoco-report.sh for report aggregation. - POM: Configured JaCoCo Maven plugin. Results: - Coverage reports for modules and merged report for the whole project are generated and archived in CI artifacts (.exec/.html). Testing: - Validated reports locally and in CI. Acked-by: Tigran Mkrtchyan Target: master Require-book: no Require-notes: no Committed:
1 parent fe1ef60 commit 4159d78

File tree

5 files changed

+115
-2
lines changed

5 files changed

+115
-2
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,37 @@ jobs:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
13+
1314
- name: Set up JDK 17
1415
uses: actions/setup-java@v4
1516
with:
1617
java-version: "17"
1718
distribution: "temurin"
1819
cache: maven
20+
21+
- name: Cache JaCoCo CLI
22+
id: cache-jacoco
23+
uses: actions/cache@v4
24+
with:
25+
path: ~/jacoco-0.8.14
26+
key: ${{ runner.os }}-jacoco-cli-${{ hashFiles('generate-jacoco-report.sh') }}
27+
restore-keys: |
28+
${{ runner.os }}-jacoco-cli-
29+
1930
- name: Build with Maven
2031
run: mvn --batch-mode --update-snapshots package
2132

33+
- name: Generate JaCoCo Report
34+
run: |
35+
chmod +x ./generate-jacoco-report.sh
36+
./generate-jacoco-report.sh
37+
38+
- name: Upload JaCoCo Report
39+
uses: actions/upload-artifact@v4
40+
with:
41+
name: JaCoCo Coverage Report
42+
path: target/coverage-reports/site
43+
2244
- name: JUnit test report
2345
uses: mikepenz/action-junit-report@v5
2446
if: always()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ with nfs4.1-files and flex-files layout types.
1111
Building from sources
1212
---------------------
1313

14-
To build nfs4j from source code Java11 and Maven3 are required.
14+
To build nfs4j from source code Java17 and Maven4 are required.
1515

1616
To run benchmarks:
1717

benchmarks/jmh-result.json

Whitespace-only changes.

generate-jacoco-report.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
3+
# Define paths
4+
PROJECT_ROOT="${PROJECT_ROOT:-$(pwd)}"
5+
JACOCO_VERSION="0.8.14"
6+
JACOCO_DIR="$HOME/jacoco-$JACOCO_VERSION"
7+
JACOCO_CLI_JAR="$JACOCO_DIR/lib/jacococli.jar"
8+
MERGED_EXEC="$PROJECT_ROOT/target/coverage-reports/merged.exec"
9+
REPORT_DIR="$PROJECT_ROOT/target/coverage-reports/site"
10+
11+
# Ensure the report directory exists
12+
mkdir -p "$REPORT_DIR"
13+
14+
# Debug: Print paths
15+
echo "DEBUG: JACOCO_CLI_JAR: $JACOCO_CLI_JAR"
16+
echo "DEBUG: Checking if $JACOCO_CLI_JAR exists..."
17+
18+
# Check if JaCoCo CLI JAR exists in the cache directory
19+
if [ ! -f "$JACOCO_CLI_JAR" ]; then
20+
echo "JaCoCo CLI JAR not found in cache directory. Downloading..."
21+
mkdir -p "$JACOCO_DIR"
22+
wget -q "https://github.com/jacoco/jacoco/releases/download/v$JACOCO_VERSION/jacoco-$JACOCO_VERSION.zip" -O "/tmp/jacoco-$JACOCO_VERSION.zip"
23+
unzip -q "/tmp/jacoco-$JACOCO_VERSION.zip" -d "$JACOCO_DIR"
24+
rm -f "/tmp/jacoco-$JACOCO_VERSION.zip"
25+
echo "DEBUG: Downloaded JaCoCo CLI to $JACOCO_DIR"
26+
ls -la "$JACOCO_DIR"
27+
else
28+
echo "DEBUG: JaCoCo CLI JAR found at $JACOCO_CLI_JAR"
29+
fi
30+
31+
# Check if JaCoCo CLI JAR exists after download
32+
if [ ! -f "$JACOCO_CLI_JAR" ]; then
33+
echo "Error: JaCoCo CLI JAR not found at $JACOCO_CLI_JAR"
34+
exit 1
35+
fi
36+
37+
# Find all jacoco-ut.exec files dynamically
38+
EXEC_FILES=($(find "$PROJECT_ROOT" -name "jacoco-ut.exec" -type f))
39+
40+
# Check if any execution data files were found
41+
if [ ${#EXEC_FILES[@]} -eq 0 ]; then
42+
echo "Error: No jacoco-ut.exec files found in $PROJECT_ROOT"
43+
exit 1
44+
fi
45+
46+
# Check if all execution data files exist
47+
for exec_file in "${EXEC_FILES[@]}"; do
48+
if [ ! -f "$exec_file" ]; then
49+
echo "Error: Execution data file not found at $exec_file"
50+
exit 1
51+
fi
52+
done
53+
54+
# Merge execution data files
55+
echo "Merging execution data files..."
56+
java -jar "$JACOCO_CLI_JAR" merge "${EXEC_FILES[@]}" --destfile "$MERGED_EXEC"
57+
58+
if [ $? -ne 0 ]; then
59+
echo "Error: Failed to merge execution data files"
60+
exit 1
61+
fi
62+
63+
# Generate the coverage report
64+
echo "Generating coverage report..."
65+
66+
# Build classfiles and sourcefiles arguments dynamically
67+
CLASSFILES_ARGS=()
68+
SOURCEFILES_ARGS=()
69+
70+
for exec_file in "${EXEC_FILES[@]}"; do
71+
# Extract module path (e.g., core, dlm, rquota) from the exec file path
72+
module_path=$(dirname "$(dirname "$(dirname "$exec_file")")")
73+
module_name=$(basename "$module_path")
74+
75+
# Add classfiles and sourcefiles arguments
76+
CLASSFILES_ARGS+=("--classfiles" "$module_path/target/classes")
77+
SOURCEFILES_ARGS+=("--sourcefiles" "$module_path/src/main/java")
78+
done
79+
80+
# Generate the report with dynamic arguments
81+
java -jar "$JACOCO_CLI_JAR" report "$MERGED_EXEC" \
82+
"${CLASSFILES_ARGS[@]}" \
83+
"${SOURCEFILES_ARGS[@]}" \
84+
--html "$REPORT_DIR"
85+
86+
if [ $? -ne 0 ]; then
87+
echo "Error: Failed to generate coverage report"
88+
exit 1
89+
fi
90+
91+
echo "Coverage report generated successfully at ${REPORT_DIR}/index.html"

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
<plugin>
9797
<groupId>org.jacoco</groupId>
9898
<artifactId>jacoco-maven-plugin</artifactId>
99-
<version>0.8.12</version>
99+
<version>0.8.14</version>
100100
<executions>
101101
<!--
102102
Prepares the property pointing to the JaCoCo runtime agent which

0 commit comments

Comments
 (0)