Skip to content

Commit

Permalink
Added code coverage (AST-79401) (#390)
Browse files Browse the repository at this point in the history
* Added code coverage

* try fix jacoco

* fix yml file

* fix jacoco

* change artifact upload to v4

* add sha for v4 artifact upload
  • Loading branch information
Korjen97 authored Jan 12, 2025
1 parent 04f6fa5 commit 1748e57
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
21 changes: 18 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
- name: Checkout LFS objects
run: git lfs checkout


- name: Cache local Maven repository
uses: actions/cache@v4
with:
Expand Down Expand Up @@ -52,15 +51,31 @@ jobs:
echo "cx-mac binary does not exist"; exit 1;
fi
- name: Run tests with Maven
run: mvn -B test --file pom.xml
- name: Install xmllint
run: sudo apt-get install -y libxml2-utils

- name: Run tests with JaCoCo
run: mvn test jacoco:report
env:
CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID}}
CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET}}
CX_BASE_URI: ${{ secrets.CX_BASE_URI }}
CX_TENANT: ${{ secrets.CX_TENANT }}
CX_APIKEY: ${{ secrets.CX_APIKEY }}

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

- name: Build with Maven
run: mvn -B verify -DskipTests -Dgpg.skip --file pom.xml
Expand Down
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,31 @@

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.8</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<includes>
<include>**/src/main/java/**</include>
<!-- Add other patterns as needed -->
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
Expand Down

0 comments on commit 1748e57

Please sign in to comment.