Skip to content
Merged
Show file tree
Hide file tree
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: 10 additions & 2 deletions .github/workflows/unit-test-and-coverage-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@ jobs:
INPUT_COV_THRESHOLD: ${{ inputs.cov_threshold }}
run: |
# Read threshold from file, allow manual override
FILE_THRESHOLD=$(cat .coverage-threshold 2>/dev/null || echo "65.0")
# Use fallback 65.0 if file is missing, empty, or unreadable
FILE_THRESHOLD=$(cat .coverage-threshold 2>/dev/null | tr -d '[:space:]')
FILE_THRESHOLD="${FILE_THRESHOLD:-65.0}"
COV_THRESHOLD="${INPUT_COV_THRESHOLD:-$FILE_THRESHOLD}"
# Validate it's a number, otherwise use fallback
if ! [[ "$COV_THRESHOLD" =~ ^[0-9]+\.?[0-9]*$ ]]; then
echo "::warning::Invalid threshold '$COV_THRESHOLD', using 65.0"
COV_THRESHOLD="65.0"
fi
echo "cov_threshold=${COV_THRESHOLD}" >> "$GITHUB_OUTPUT"
echo "build_id=${GITHUB_RUN_ID}" >> "$GITHUB_OUTPUT"
if [[ -n "${INPUT_COV_THRESHOLD}" ]]; then
Expand Down Expand Up @@ -89,7 +96,8 @@ jobs:
# Extract numeric values using simpler patterns
OVERALL=$(grep "Overall Coverage:" coverage_report.txt | sed 's/[^0-9.]*\([0-9.]\+\)%.*/\1/')%
Comment thread
arodage marked this conversation as resolved.
THRESHOLD=$(grep "Threshold:" coverage_report.txt | sed 's/[^0-9.]*\([0-9.]\+\)%.*/\1/')%
Comment thread
arodage marked this conversation as resolved.
STATUS=$(grep "Status:" coverage_report.txt | sed 's/[^A-Z]*\([A-Z]\+\).*/\1/')
# Get last word on the Status line (PASSED or FAILED)
STATUS=$(grep "Status:" coverage_report.txt | awk '{print $NF}')

# Status badge
if [[ "$STATUS" == "PASSED" ]]; then
Expand Down
16 changes: 12 additions & 4 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,13 @@ test:

# Run the comprehensive coverage tests using our script
# Args: COV_THRESHOLD PRINT_TS FAIL_ON_NO_TESTS DEBUG
# If COV_THRESHOLD not provided, read from .coverage-threshold file
# If COV_THRESHOLD not provided or empty, read from .coverage-threshold file
RUN cd /work && \
THRESHOLD="${COV_THRESHOLD:-$(cat .coverage-threshold 2>/dev/null || echo 65.0)}" && \
FILE_THRESH=$(cat .coverage-threshold 2>/dev/null | tr -d '[:space:]') && \
FILE_THRESH="${FILE_THRESH:-65.0}" && \
THRESHOLD="${COV_THRESHOLD:-$FILE_THRESH}" && \
THRESHOLD="${THRESHOLD:-65.0}" && \
echo "Using coverage threshold: ${THRESHOLD}%" && \
./scripts/run_coverage_tests.sh "${THRESHOLD}" "${PRINT_TS}" "${FAIL_ON_NO_TESTS}"

# Save coverage artifacts locally
Expand All @@ -176,9 +180,13 @@ test-debug:

# Run the coverage tests with debug output (keeps temp files for inspection)
# Args: COV_THRESHOLD PRINT_TS FAIL_ON_NO_TESTS DEBUG
# If COV_THRESHOLD not provided, read from .coverage-threshold file
# If COV_THRESHOLD not provided or empty, read from .coverage-threshold file
RUN cd /work && \
THRESHOLD="${COV_THRESHOLD:-$(cat .coverage-threshold 2>/dev/null || echo 65.0)}" && \
FILE_THRESH=$(cat .coverage-threshold 2>/dev/null | tr -d '[:space:]') && \
FILE_THRESH="${FILE_THRESH:-65.0}" && \
THRESHOLD="${COV_THRESHOLD:-$FILE_THRESH}" && \
THRESHOLD="${THRESHOLD:-65.0}" && \
echo "Using coverage threshold: ${THRESHOLD}%" && \
./scripts/run_coverage_tests.sh "${THRESHOLD}" "${PRINT_TS}" "${FAIL_ON_NO_TESTS}" "true"

# Save coverage artifacts locally
Expand Down
6 changes: 5 additions & 1 deletion scripts/run_coverage_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -433,19 +433,23 @@ echo "Calculation method: ${COVERAGE_METHOD}"
COVERAGE_NORMALIZED=$(printf '%.1f' "${OVERALL_COVERAGE}")
THRESHOLD_NORMALIZED=$(printf '%.1f' "${COV_THRESHOLD}")

# Track coverage status separately from test status
COVERAGE_PASSED="true"
if (( $(echo "${COVERAGE_NORMALIZED} >= ${THRESHOLD_NORMALIZED}" | bc -l) )); then
echo -e "${GREEN}✓ Overall coverage PASSED threshold${NC}"
else
echo -e "${RED}✗ Overall coverage FAILED threshold${NC}"
COVERAGE_PASSED="false"
OVERALL_EXIT_CODE=1
fi

# Generate coverage reports for saving
# Note: Status reflects COVERAGE check only, not test failures
echo "## Test Coverage Report" > coverage_report.txt
echo "" >> coverage_report.txt
echo "**Overall Coverage:** ${COVERAGE_NORMALIZED}%" >> coverage_report.txt
echo "**Threshold:** ${THRESHOLD_NORMALIZED}% (applies to overall coverage only)" >> coverage_report.txt
echo "**Status:** $(if [[ ${OVERALL_EXIT_CODE} -eq 0 ]]; then echo "PASSED"; else echo "FAILED"; fi)" >> coverage_report.txt
echo "**Status:** $(if [[ "${COVERAGE_PASSED}" == "true" ]]; then echo "PASSED"; else echo "FAILED"; fi)" >> coverage_report.txt
echo "" >> coverage_report.txt

# FIXED: Use safer array check that works with set -u
Expand Down
Loading