From 4722261ce3265b5d554f770f9fdf17d8b123ddbb Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Fri, 22 Sep 2023 22:21:30 +1000 Subject: [PATCH] Fix #2444, Enforce keeping code coverage minimums up-to-date --- .github/workflows/code-coverage.yml | 39 +++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 45153fd92..e0aa65820 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -36,6 +36,9 @@ jobs: if: ${{ needs.check-for-duplicates.outputs.should_skip != 'true' }} runs-on: ubuntu-20.04 timeout-minutes: 15 + env: + MISSED_BRANCHES_ALLOWED: 51 + MISSED_LINES_ALLOWED: 17 steps: - name: Install coverage tools @@ -104,17 +107,43 @@ jobs: - name: Confirm Minimum Coverage run: | - missed_branches=52 - missed_lines=18 branch_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep branches | grep -oP "[0-9]+[0-9]*") line_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep lines | grep -oP "[0-9]+[0-9]*") branch_diff=$(echo $branch_nums | awk '{ print $4 - $3 }') line_diff=$(echo $line_nums | awk '{ print $4 - $3 }') - if [ $branch_diff -gt $missed_branches ] || [ $line_diff -gt $missed_lines ] + if [ $branch_diff -gt $MISSED_BRANCHES_ALLOWED ] || [ $line_diff -gt $MISSED_LINES_ALLOWED ] then grep -A 3 "Overall coverage rate" lcov_out.txt - echo "$branch_diff branches missed, $missed_branches allowed" - echo "$line_diff lines missed, $missed_lines allowed" + echo "$branch_diff branches missed, $MISSED_BRANCHES_ALLOWED allowed" + echo "$line_diff lines missed, $MISSED_LINES_ALLOWED allowed" exit -1 fi + + - name: Check that Minimum Coverage Limits are Correctly Calibrated + run: | + branch_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep branches | grep -oP "[0-9]+[0-9]*") + line_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep lines | grep -oP "[0-9]+[0-9]*") + + branch_diff=$(echo $branch_nums | awk '{ print $4 - $3 }') + line_diff=$(echo $line_nums | awk '{ print $4 - $3 }') + if [ $branch_diff -lt $MISSED_BRANCHES_ALLOWED ] || [ $line_diff -lt $MISSED_LINES_ALLOWED ] + then + grep -A 3 "Overall coverage rate" lcov_out.txt + echo "" + if [ $branch_diff -lt $MISSED_BRANCHES_ALLOWED ] + then + echo "$branch_diff branches were missed, which is *less* than the expected/allowed amount: $MISSED_BRANCHES_ALLOWED" + echo "Please update (lower) the MISSED_BRANCHES_ALLOWED variable in this workflow file to match the new coverage level." + echo "" + fi + + if [ $line_diff -lt $MISSED_LINES_ALLOWED ] + then + echo "$line_diff lines were missed, which is *less* than the expected/allowed amount: $MISSED_LINES_ALLOWED" + echo "Please update (lower) the MISSED_LINES_ALLOWED variable in this workflow file to match the new coverage level." + echo "" + fi + + exit -1 + fi \ No newline at end of file