Skip to content

Commit

Permalink
Fix nasa#2610, Enforce keeping coverage minimums up-to-date in Code C…
Browse files Browse the repository at this point in the history
…overage CI workflow
  • Loading branch information
thnkslprpt committed Oct 11, 2024
1 parent 78b8fd7 commit 86d84ed
Showing 1 changed file with 55 additions and 6 deletions.
61 changes: 55 additions & 6 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

0 comments on commit 86d84ed

Please sign in to comment.