Skip to content

Commit 21a1ec7

Browse files
authored
fix: improve coverage check logic and error reporting (#48)
1 parent ae3809a commit 21a1ec7

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

.github/workflows/reusable-node-ci.yml

+4-8
Original file line numberDiff line numberDiff line change
@@ -233,28 +233,24 @@ jobs:
233233
if: steps.unit_tests.outcome == 'success' && env.coverage_ran == 'true'
234234
id: check_coverage
235235
run: |
236-
THRESHOLD=$(grep -oP '(?<=lines: )\d+' jest.config.js)
237236
TARGET_COVERAGE=${{ inputs.target-coverage }}
238237
echo "coverage_passed=false" >> $GITHUB_ENV
239238
240-
if [ -z "$COVERAGE" ] || [ -z "$TARGET_COVERAGE" ] || [ -z "$THRESHOLD" ]; then
239+
if [ -z "$COVERAGE" ] || [ -z "$TARGET_COVERAGE" ]; then
241240
echo "One of the coverage variables is unset. Please check the test outputs."
242241
exit 1
243242
fi
244243
245-
if [ "$COVERAGE" -ge "$TARGET_COVERAGE" ]; then
244+
if (( $(echo "$COVERAGE >= $TARGET_COVERAGE" | bc -l) )); then
246245
echo "Coverage is above or equal to the target of $TARGET_COVERAGE%. Test passes."
247246
echo "coverage_passed=true" >> $GITHUB_ENV
248-
elif [ "$COVERAGE" -ge "$THRESHOLD" ]; then
249-
echo "Coverage is below $TARGET_COVERAGE% but meets or exceeds the current threshold. Test passes."
250-
echo "coverage_passed=true" >> $GITHUB_ENV
251247
else
252-
echo "Coverage check failed! Coverage is below target ($TARGET_COVERAGE%) and below the current threshold ($THRESHOLD)."
248+
echo "Coverage check failed! Coverage $COVERAGE% is below target $TARGET_COVERAGE%."
253249
if [ "${{ env.IS_UNIT_TESTS_REQUIRED }}" == "true" ]; then
254250
echo "Coverage has decreased below the threshold and tests are required to pass. Failing the build."
255251
exit 1
256252
else
257-
echo "Coverage has decreased below the threshold but tests are NOT required to pass"
253+
echo "Coverage has decreased below the target coverage but tests are NOT required to pass"
258254
exit 0
259255
fi
260256
fi

0 commit comments

Comments
 (0)