Skip to content

Commit 4d53b43

Browse files
test coverage
1 parent a2fb550 commit 4d53b43

File tree

2 files changed

+66
-47
lines changed

2 files changed

+66
-47
lines changed

.github/workflows/code-coverage.yml

Lines changed: 0 additions & 47 deletions
This file was deleted.

.github/workflows/jacoco.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [ feat/CS-36689-compare-merge-branch ]
6+
paths: [ '**.java', '.github/workflows/jacoco.yml', 'pom.xml' ]
7+
pull_request:
8+
branches: [ feat/CS-36689-compare-merge-branch ]
9+
workflow_dispatch:
10+
11+
jobs:
12+
jacoco-java-maven:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v3
19+
20+
21+
- name: Set up JDK 17
22+
uses: actions/setup-java@v3
23+
with:
24+
distribution: 'adopt'
25+
java-version: '17'
26+
27+
- name: Build with Maven
28+
run: mvn -B package -Pcoverage
29+
30+
- name: Generate JaCoCo badge
31+
id: jacoco
32+
uses: cicirello/jacoco-badge-generator@v2
33+
with:
34+
badges-directory: badges
35+
generate-branches-badge: true
36+
generate-summary: true
37+
38+
- name: Log coverage percentages to workflow output
39+
run: |
40+
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
41+
echo "branches = ${{ steps.jacoco.outputs.branches }}"
42+
43+
- name: Upload JaCoCo coverage report as a workflow artifact
44+
uses: actions/upload-artifact@v3
45+
with:
46+
name: jacoco-report
47+
path: target/site/jacoco/
48+
49+
50+
- name: Comment on PR with coverage percentages
51+
if: ${{ github.event_name == 'pull_request' }}
52+
run: |
53+
REPORT=$(<badges/coverage-summary.json)
54+
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
55+
BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
56+
NEWLINE=$'\n'
57+
BODY="## JaCoCo Test Coverage Summary Statistics${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
58+
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
59+
continue-on-error: true
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
63+
- name: Get the Coverage info
64+
run: |
65+
echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}"
66+
echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}"

0 commit comments

Comments
 (0)