Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve coverage check logic and error reporting #48

Merged
merged 1 commit into from
Mar 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .github/workflows/reusable-node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,28 +233,24 @@ jobs:
if: steps.unit_tests.outcome == 'success' && env.coverage_ran == 'true'
id: check_coverage
run: |
THRESHOLD=$(grep -oP '(?<=lines: )\d+' jest.config.js)
TARGET_COVERAGE=${{ inputs.target-coverage }}
echo "coverage_passed=false" >> $GITHUB_ENV

if [ -z "$COVERAGE" ] || [ -z "$TARGET_COVERAGE" ] || [ -z "$THRESHOLD" ]; then
if [ -z "$COVERAGE" ] || [ -z "$TARGET_COVERAGE" ]; then
echo "One of the coverage variables is unset. Please check the test outputs."
exit 1
fi

if [ "$COVERAGE" -ge "$TARGET_COVERAGE" ]; then
if (( $(echo "$COVERAGE >= $TARGET_COVERAGE" | bc -l) )); then
echo "Coverage is above or equal to the target of $TARGET_COVERAGE%. Test passes."
echo "coverage_passed=true" >> $GITHUB_ENV
elif [ "$COVERAGE" -ge "$THRESHOLD" ]; then
echo "Coverage is below $TARGET_COVERAGE% but meets or exceeds the current threshold. Test passes."
echo "coverage_passed=true" >> $GITHUB_ENV
else
echo "Coverage check failed! Coverage is below target ($TARGET_COVERAGE%) and below the current threshold ($THRESHOLD)."
echo "Coverage check failed! Coverage $COVERAGE% is below target $TARGET_COVERAGE%."
if [ "${{ env.IS_UNIT_TESTS_REQUIRED }}" == "true" ]; then
echo "Coverage has decreased below the threshold and tests are required to pass. Failing the build."
exit 1
else
echo "Coverage has decreased below the threshold but tests are NOT required to pass"
echo "Coverage has decreased below the target coverage but tests are NOT required to pass"
exit 0
fi
fi
Loading