Skip to content

Commit 0b863db

Browse files
committed
Fix #2444, Enforce keeping code coverage minimums up-to-date
1 parent ed1faf4 commit 0b863db

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

.github/workflows/code-coverage.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
if: ${{ needs.check-for-duplicates.outputs.should_skip != 'true' }}
3737
runs-on: ubuntu-20.04
3838
timeout-minutes: 15
39+
env:
40+
MISSED_BRANCHES_ALLOWED: 47
41+
MISSED_LINES_ALLOWED: 36
3942

4043
steps:
4144
- name: Install coverage tools
@@ -104,17 +107,43 @@ jobs:
104107
105108
- name: Confirm Minimum Coverage
106109
run: |
107-
missed_branches=50
108-
missed_lines=17
109110
branch_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep branches | grep -oP "[0-9]+[0-9]*")
110111
line_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep lines | grep -oP "[0-9]+[0-9]*")
111112
112113
branch_diff=$(echo $branch_nums | awk '{ print $4 - $3 }')
113114
line_diff=$(echo $line_nums | awk '{ print $4 - $3 }')
114-
if [ $branch_diff -gt $missed_branches ] || [ $line_diff -gt $missed_lines ]
115+
if [ $branch_diff -gt $MISSED_BRANCHES_ALLOWED ] || [ $line_diff -gt $MISSED_LINES_ALLOWED ]
115116
then
116117
grep -A 3 "Overall coverage rate" lcov_out.txt
117-
echo "$branch_diff branches missed, $missed_branches allowed"
118-
echo "$line_diff lines missed, $missed_lines allowed"
118+
echo "$branch_diff branches missed, $MISSED_BRANCHES_ALLOWED allowed"
119+
echo "$line_diff lines missed, $MISSED_LINES_ALLOWED allowed"
120+
exit -1
121+
fi
122+
123+
- name: Check that Minimum Coverage Limits are Correctly Calibrated
124+
run: |
125+
branch_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep branches | grep -oP "[0-9]+[0-9]*")
126+
line_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep lines | grep -oP "[0-9]+[0-9]*")
127+
128+
branch_diff=$(echo $branch_nums | awk '{ print $4 - $3 }')
129+
line_diff=$(echo $line_nums | awk '{ print $4 - $3 }')
130+
if [ $branch_diff -lt $MISSED_BRANCHES_ALLOWED ] || [ $line_diff -lt $MISSED_LINES_ALLOWED ]
131+
then
132+
grep -A 3 "Overall coverage rate" lcov_out.txt
133+
echo ""
134+
if [ $branch_diff -lt $MISSED_BRANCHES_ALLOWED ]
135+
then
136+
echo "$branch_diff branches were missed, which is *less* than the expected/allowed amount: $MISSED_BRANCHES_ALLOWED"
137+
echo "Please update (lower) the MISSED_BRANCHES_ALLOWED variable in this workflow file to match the new coverage level."
138+
echo ""
139+
fi
140+
141+
if [ $line_diff -lt $MISSED_LINES_ALLOWED ]
142+
then
143+
echo "$line_diff lines were missed, which is *less* than the expected/allowed amount: $MISSED_LINES_ALLOWED"
144+
echo "Please update (lower) the MISSED_LINES_ALLOWED variable in this workflow file to match the new coverage level."
145+
echo ""
146+
fi
147+
119148
exit -1
120149
fi

0 commit comments

Comments
 (0)