coverage #7
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Java CI with JaCoCo | |
on: | |
push: | |
branches: | |
- feat/CS-36689-compare-merge-branch | |
jobs: | |
build-and-test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Code Coverage | |
uses: actions/setup-java@v3 | |
with: | |
java-version: "11" | |
distribution: "adopt" | |
- name: Build with Maven | |
run: mvn clean package | |
- name: Run Tests with JaCoCo | |
run: mvn jacoco:prepare-agent test jacoco:report | |
- name: Check Code Coverage | |
run: | | |
total_lines=$(xmllint --xpath 'string(//counter[@type="LINE"]/@covered)' target/site/jacoco/jacoco.xml) | |
total_lines=${total_lines:-0} | |
total_missed=$(xmllint --xpath 'string(//counter[@type="LINE"]/@missed)' target/site/jacoco/jacoco.xml) | |
total_missed=${total_missed:-0} | |
total_percentage=$(awk "BEGIN { pc=100*${total_lines}/(${total_lines}+${total_missed}) } { printf \"%f\", pc }") | |
echo "Total Coverage Percentage: $total_percentage" | |
if (( $(bc <<< "$total_percentage < 60.0") )); then | |
echo "Code Coverage is below 80% - failing the CI build." | |
exit 1 | |
else | |
echo "Code Coverage is satisfactory - CI build passed." | |
fi |