Skip to content

Commit

Permalink
Merge pull request #354 from jenkinsci/other/miryamFoifer/codeCoverag…
Browse files Browse the repository at this point in the history
…eForIntegrationTests

Add code coverage to integration tests(AST-79398)
  • Loading branch information
miryamfoiferCX authored Jan 12, 2025
2 parents bb8047d + 1e35c78 commit 31779b1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
23 changes: 22 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
CX_TENANT: ${{ secrets.CX_TENANT }}
CX_CLIENT_ID: ${{ secrets.CX_CLIENT_ID }}
CX_CLIENT_SECRET: ${{ secrets.CX_CLIENT_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -26,7 +27,27 @@ jobs:
server-id: github
settings-path: ${{ github.workspace }}

- name: Install xmllint
run: sudo apt-get install -y libxml2-utils

- name: Build with Maven
run: mvn -B package --file pom.xml -s $GITHUB_WORKSPACE/settings.xml
env:
GITHUB_TOKEN: ${{ github.token }}
GITHUB_TOKEN: ${{ github.token }}

- name: Run tests with coverage
run: mvn test jacoco:report

- 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 coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: target/site/jacoco
25 changes: 25 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,31 @@
<generateBackupPoms>false</generateBackupPoms>
</configuration>
</plugin>
<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>
</plugins>
</build>
</project>

0 comments on commit 31779b1

Please sign in to comment.