Skip to content

Commit

Permalink
Adding code coverage check to UT ci job
Browse files Browse the repository at this point in the history
  • Loading branch information
Tonix517 committed Feb 27, 2025
1 parent aac0572 commit 0c3560b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ jobs:
scripts/unit_test.sh
env:
CGO_CFLAGS: "-O -D__BLST_PORTABLE__" # Set the CGO flags to use the portable version of BLST

- name: Check Code Coverage
run: |
scripts/check_coverage_unit_test.sh
21 changes: 21 additions & 0 deletions scripts/check_coverage_unit_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# file name of code coverage report and it has to exist.
COVER_FILE=coverage.out
if [ ! -f $COVER_FILE ]; then
echo "$COVER_FILE not found! Please run scripts/unit_test.sh first."
exit 1
fi

# percentage threshold of code coverage required
COVERAGE_THRESHOLD=5.0

# print current test coverage from report
current_test_coverage=$(go tool cover -func=$COVER_FILE | grep -e "total" | awk '{print $3}')
echo "Current test coverage is $current_test_coverage"

go tool cover -func=$COVER_FILE | grep -e "total" | \
awk -v coverageThreshold=$COVERAGE_THRESHOLD '{if (($3 - 0.0) < coverageThreshold) \
{print "Coverage is less than", coverageThreshold, "%. Checking Failed"; exit 1} \
else \
{print "Coverage is greater than or equal to", coverageThreshold, "%. Checking Passed."; exit 0}}'

0 comments on commit 0c3560b

Please sign in to comment.