From 86d84edc0e308156aac0d93a6bedf58480c0512d Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Thu, 10 Oct 2024 16:27:05 +0200 Subject: [PATCH] Fix #2610, Enforce keeping coverage minimums up-to-date in Code Coverage CI workflow --- .github/workflows/code-coverage.yml | 61 ++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 80ee121f6..eadd448f4 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -13,7 +13,9 @@ env: ENABLE_UNIT_TESTS: true OMIT_DEPRECATED: true BUILDTYPE: debug - + ALLOWED_MISSED_BRANCHES: 39 + ALLOWED_MISSED_LINES: 17 + ALLOWED_MISSED_FUNCTIONS: 0 jobs: #Check for duplicate actions. Skips push actions if there is a matching or duplicate pull-request action. @@ -105,17 +107,64 @@ jobs: - name: Confirm Minimum Coverage run: | - missed_branches=39 - missed_lines=19 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]*") + function_nums=$(grep -A 3 "Overall coverage rate" lcov_out.txt | grep functions | grep -oP "[0-9]+[0-9]*") branch_diff=$(echo $branch_nums | awk '{ print $4 - $3 }') + echo "branch_diff=$branch_diff" >> $GITHUB_ENV line_diff=$(echo $line_nums | awk '{ print $4 - $3 }') - if [ $branch_diff -gt $missed_branches ] || [ $line_diff -gt $missed_lines ] + echo "line_diff=$line_diff" >> $GITHUB_ENV + function_diff=$(echo $function_nums | awk '{ print $4 - $3 }') + echo "function_diff=$function_diff" >> $GITHUB_ENV + + if [ $branch_diff -gt ${{ env.ALLOWED_MISSED_BRANCHES }} ] + then + grep -A 3 "Overall coverage rate" lcov_out.txt + echo "::error::$branch_diff uncovered branch$([ $branch_diff -ne 1 ] && echo 'es') reported, but only ${{ env.ALLOWED_MISSED_BRANCHES }} ${{ env.ALLOWED_MISSED_BRANCHES == 1 && 'is' || 'are' }} allowed." + exit -1 + fi + + if [ $line_diff -gt ${{ env.ALLOWED_MISSED_LINES }} ] + then + grep -A 3 "Overall coverage rate" lcov_out.txt + echo "::error::$line_diff uncovered line$([ $line_diff -ne 1 ] && echo 's') reported, but only ${{ env.ALLOWED_MISSED_LINES }} ${{ env.ALLOWED_MISSED_LINES == 1 && 'is' || 'are' }} allowed." + exit -1 + fi + + if [ $function_diff -gt ${{ env.ALLOWED_MISSED_FUNCTIONS }} ] + then + grep -A 3 "Overall coverage rate" lcov_out.txt + echo "::error::$function_diff uncovered function$([ $function_diff -ne 1 ] && echo 's') reported, but only ${{ env.ALLOWED_MISSED_FUNCTIONS }} ${{ env.ALLOWED_MISSED_FUNCTIONS == 1 && 'is' || 'are' }} allowed." + exit -1 + fi + + - name: Enforce Keeping Branch Coverage Minimum Up-To-Date + run: | + if [ $branch_diff -lt ${{ env.ALLOWED_MISSED_BRANCHES }} ] + then + grep -A 3 "Overall coverage rate" lcov_out.txt + echo "::error::$branch_diff uncovered branch$([ $branch_diff -ne 1 ] && echo 'es') reported, but ${{ env.ALLOWED_MISSED_BRANCHES }} ${{ env.ALLOWED_MISSED_BRANCHES == 1 && 'is' || 'are' }} allowed." + echo "::error::Please update (lower) the 'ALLOWED_MISSED_BRANCHES' variable to $branch_diff in order to match the new coverage level." + exit -1 + fi + + - name: Enforce Keeping Line Coverage Minimum Up-To-Date + run: | + if [ $line_diff -lt ${{ env.ALLOWED_MISSED_LINES }} ] + then + grep -A 3 "Overall coverage rate" lcov_out.txt + echo "::error::$line_diff uncovered line$([ $line_diff -ne 1 ] && echo 's') reported, but ${{ env.ALLOWED_MISSED_LINES }} ${{ env.ALLOWED_MISSED_LINES == 1 && 'is' || 'are' }} allowed." + echo "::error::Please update (lower) the 'ALLOWED_MISSED_LINES' variable to $line_diff in order to match the new coverage level." + exit -1 + fi + + - name: Enforce Keeping Function Coverage Minimum Up-To-Date + run: | + if [ $function_diff -lt ${{ env.ALLOWED_MISSED_FUNCTIONS }} ] 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 "::error::$function_diff uncovered function$([ $function_diff -ne 1 ] && echo 's') reported, but ${{ env.ALLOWED_MISSED_FUNCTIONS }} ${{ env.ALLOWED_MISSED_FUNCTIONS == 1 && 'is' || 'are' }} allowed." + echo "::error::Please update (lower) the 'ALLOWED_MISSED_FUNCTIONS' variable to $function_diff in order to match the new coverage level." exit -1 fi