Skip to content

Commit a19c42e

Browse files
authored
Update codecoverage percentage checks (#184)
1 parent 0442c2a commit a19c42e

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

.github/workflows/prCheck.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,29 @@ jobs:
6666
- name: Check Unit Tests
6767
run: mvn test
6868

69+
- name: Install xmllint
70+
if: runner.os == 'Linux'
71+
run: sudo apt-get update && sudo apt-get install -y libxml2-utils
72+
6973
- name: JaCoCo report
7074
run: mvn --batch-mode --errors jacoco:report --file pom.xml
7175

72-
- name: Publish test coverage
73-
uses: codecov/codecov-action@v4
74-
with:
75-
file: target/site/jacoco/jacoco.xml
76-
token: ${{ secrets.CODECOV_TOKEN }}
77-
fail_ci_if_error: true
78-
verbose: true
76+
- name: Extract codeCov percentage
77+
run: |
78+
COVERAGE_FILE="target/site/jacoco/jacoco.xml"
79+
COVERED=$(xmllint --xpath "string(//report/counter[@type='INSTRUCTION']/@covered)" $COVERAGE_FILE)
80+
MISSED=$(xmllint --xpath "string(//report/counter[@type='INSTRUCTION']/@missed)" $COVERAGE_FILE)
81+
TOTAL=$(($COVERED + $MISSED))
82+
PERCENTAGE=$(echo "scale=2; 100 * $COVERED / $TOTAL" | bc)
83+
echo $PERCENTAGE > coverage.txt
84+
echo "::set-output name=coverage::$PERCENTAGE"
85+
- name: Check coverage percentage
86+
run: |
87+
BRANCH_COVERAGE=$(cat coverage.txt)
88+
echo "Branch Coverage: $BRANCH_COVERAGE%"
89+
if (( $(echo "$BRANCH_COVERAGE < 85" | bc -l) )); then
90+
echo "Coverage is less than 85%"
91+
exit 1
92+
else
93+
echo "Coverage is equal to or greater than 85%"
94+
fi

0 commit comments

Comments
 (0)