Skip to content

Commit 1748e57

Browse files
authored
Added code coverage (AST-79401) (#390)
* Added code coverage * try fix jacoco * fix yml file * fix jacoco * change artifact upload to v4 * add sha for v4 artifact upload
1 parent 04f6fa5 commit 1748e57

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
- name: Checkout LFS objects
2222
run: git lfs checkout
2323

24-
2524
- name: Cache local Maven repository
2625
uses: actions/cache@v4
2726
with:
@@ -52,15 +51,31 @@ jobs:
5251
echo "cx-mac binary does not exist"; exit 1;
5352
fi
5453
55-
- name: Run tests with Maven
56-
run: mvn -B test --file pom.xml
54+
- name: Install xmllint
55+
run: sudo apt-get install -y libxml2-utils
56+
57+
- name: Run tests with JaCoCo
58+
run: mvn test jacoco:report
5759
env:
5860
CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID}}
5961
CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET}}
6062
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
6163
CX_TENANT: ${{ secrets.CX_TENANT }}
6264
CX_APIKEY: ${{ secrets.CX_APIKEY }}
6365

66+
- name: Print total coverage percentage
67+
run: |
68+
COVERED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@covered)" target/site/jacoco/jacoco.xml)
69+
MISSED_LINES=$(xmllint --xpath "string(//report/counter[@type='LINE']/@missed)" target/site/jacoco/jacoco.xml)
70+
TOTAL_LINES=$((COVERED_LINES + MISSED_LINES))
71+
COVERAGE_PERCENTAGE=$(echo "scale=2; $COVERED_LINES / $TOTAL_LINES * 100" | bc)
72+
echo "Total coverage percentage: $COVERAGE_PERCENTAGE%"
73+
74+
- name: Upload JaCoCo coverage report
75+
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 #v4
76+
with:
77+
name: jacoco-coverage-report
78+
path: target/site/jacoco
6479

6580
- name: Build with Maven
6681
run: mvn -B verify -DskipTests -Dgpg.skip --file pom.xml

pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,31 @@
6161

6262
<build>
6363
<plugins>
64+
<plugin>
65+
<groupId>org.jacoco</groupId>
66+
<artifactId>jacoco-maven-plugin</artifactId>
67+
<version>0.8.8</version>
68+
<executions>
69+
<execution>
70+
<goals>
71+
<goal>prepare-agent</goal>
72+
</goals>
73+
</execution>
74+
<execution>
75+
<id>report</id>
76+
<phase>test</phase>
77+
<goals>
78+
<goal>report</goal>
79+
</goals>
80+
<configuration>
81+
<includes>
82+
<include>**/src/main/java/**</include>
83+
<!-- Add other patterns as needed -->
84+
</includes>
85+
</configuration>
86+
</execution>
87+
</executions>
88+
</plugin>
6489
<plugin>
6590
<groupId>com.github.spotbugs</groupId>
6691
<artifactId>spotbugs-maven-plugin</artifactId>

0 commit comments

Comments
 (0)