Skip to content

Commit 743b871

Browse files
test coverage
1 parent 6459f1c commit 743b871

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Java CI with Code Coverage
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
build-and-test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v2
15+
16+
- name: Set up JDK 11
17+
uses: actions/setup-java@v2
18+
with:
19+
java-version: 11
20+
21+
- name: Build with Maven
22+
run: mvn clean package
23+
24+
- name: Run Tests with JaCoCo
25+
run: mvn jacoco:prepare-agent jacoco:report
26+
27+
- name: Publish JaCoCo Report
28+
uses: dawidd6/action-jacoco-publish@v1
29+
30+
- name: Fail if Coverage Below Threshold
31+
id: coverage_check
32+
run: |
33+
total_lines=$(xmllint --xpath 'string(//counter[@type="LINE"]/@covered)' target/site/jacoco/jacoco.xml)
34+
total_lines=${total_lines:-0}
35+
total_missed=$(xmllint --xpath 'string(//counter[@type="LINE"]/@missed)' target/site/jacoco/jacoco.xml)
36+
total_missed=${total_missed:-0}
37+
total_percentage=$(awk "BEGIN { pc=100*${total_lines}/${total_lines} } { printf \"%f\", pc }")
38+
echo "::set-output name=coverage_percentage::$total_percentage"
39+
if (( $(bc <<< "$total_percentage < 70.0") )); then
40+
echo "Coverage is below 80% - failing the build."
41+
exit 1
42+
fi
43+
44+
- name: Upload Code Coverage Report
45+
uses: actions/upload-artifact@v2
46+
with:
47+
name: code-coverage-report
48+
path: target/site/jacoco

0 commit comments

Comments
 (0)