diff --git a/.github/workflows/_coverage.yml b/.github/workflows/_coverage.yml index 5e7a164..bf11d01 100644 --- a/.github/workflows/_coverage.yml +++ b/.github/workflows/_coverage.yml @@ -27,14 +27,6 @@ jobs: - name: Run tests and check coverage run: ./scripts/check-coverage.sh - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v7 - with: - files: ./openmapview/build/reports/coverage/test/debug/report.xml - flags: unittests - name: codecov-openmapview - fail_ci_if_error: false - - name: Upload coverage reports if: always() uses: actions/upload-artifact@v7 diff --git a/README.md b/README.md index 22af1d5..3eda837 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ [![CI](https://github.com/afarber/OpenMapView/actions/workflows/ci.yml/badge.svg)](https://github.com/afarber/OpenMapView/actions/workflows/ci.yml) [![Daily Tests](https://github.com/afarber/OpenMapView/actions/workflows/daily.yml/badge.svg)](https://github.com/afarber/OpenMapView/actions/workflows/daily.yml) [![Release](https://github.com/afarber/OpenMapView/actions/workflows/release.yml/badge.svg)](https://github.com/afarber/OpenMapView/actions/workflows/release.yml) -[![codecov](https://codecov.io/gh/afarber/OpenMapView/branch/main/graph/badge.svg)](https://codecov.io/gh/afarber/OpenMapView) [![API Documentation](https://img.shields.io/badge/API-Documentation-blue)](https://afarber.github.io/OpenMapView/) # OpenMapView -A modern, Kotlin-first MapView replacement for Android — powered by [OpenStreetMap](https://www.openstreetmap.org/). +A modern, Kotlin-first MapView replacement for Android - powered by [OpenStreetMap](https://www.openstreetmap.org/). ## Installation diff --git a/docs/GITHUB_WORKFLOWS.md b/docs/GITHUB_WORKFLOWS.md index b0fe694..680b42f 100644 --- a/docs/GITHUB_WORKFLOWS.md +++ b/docs/GITHUB_WORKFLOWS.md @@ -48,7 +48,7 @@ Located in `.github/workflows/`: #### `_coverage.yml` - **Purpose**: Check test coverage meets minimum threshold - **Runs**: `./scripts/check-coverage.sh` (minimum threshold defined in [Contributing Guide](CONTRIBUTING.md#test-coverage)) -- **Artifacts**: Uploads coverage reports to Codecov and as artifacts +- **Artifacts**: Writes a coverage table to the job summary and uploads the reports as artifacts - **Usage**: Called by CI workflow - **Duration**: ~1-2 minutes diff --git a/docs/TESTING_UNIT.md b/docs/TESTING_UNIT.md index e5015b8..1271e7b 100644 --- a/docs/TESTING_UNIT.md +++ b/docs/TESTING_UNIT.md @@ -436,11 +436,11 @@ The test suite currently covers: The `.github/workflows/_coverage.yml` workflow: 1. Runs all unit tests and generates the coverage report (`./scripts/check-coverage.sh`) 2. Checks coverage meets minimum threshold -3. Uploads coverage to Codecov +3. Writes a coverage table (instructions, lines, branches) to the job summary 4. Uploads HTML and XML reports as artifacts Coverage results are available: -- On Codecov: https://codecov.io/gh/afarber/OpenMapView +- In the job summary of the "Check Test Coverage" job - As CI artifacts (HTML report) - In PR status checks (pass/fail) diff --git a/scripts/check-coverage.sh b/scripts/check-coverage.sh index 1c4f354..d639662 100755 --- a/scripts/check-coverage.sh +++ b/scripts/check-coverage.sh @@ -23,33 +23,58 @@ if [ ! -f "$COVERAGE_FILE" ]; then exit 1 fi -# Extract coverage percentage from XML report +# Print "covered total percent" for a counter type, e.g. INSTRUCTION, LINE or BRANCH # Format: -# The report is a single line; the last INSTRUCTION counter is the report-level total -INSTRUCTIONS=$(grep -o ']*>' "$COVERAGE_FILE" | tail -1) -MISSED=$(echo "$INSTRUCTIONS" | sed -n 's/.*missed="\([0-9]*\)".*/\1/p') -COVERED=$(echo "$INSTRUCTIONS" | sed -n 's/.*covered="\([0-9]*\)".*/\1/p') +# The report is a single line; the last counter of each type is the report-level total +counter() { + local line missed covered total + line=$(grep -o "]*>" "$COVERAGE_FILE" | tail -1) + missed=$(echo "$line" | sed -n 's/.*missed="\([0-9]*\)".*/\1/p') + covered=$(echo "$line" | sed -n 's/.*covered="\([0-9]*\)".*/\1/p') + if [ -z "$missed" ] || [ -z "$covered" ]; then + echo "ERROR: Could not extract $1 coverage from report" >&2 + exit 1 + fi + total=$((missed + covered)) + if [ $total -eq 0 ]; then + echo "$covered $total 0" + else + echo "$covered $total $((covered * 100 / total))" + fi +} -if [ -z "$MISSED" ] || [ -z "$COVERED" ]; then - echo "ERROR: Could not extract coverage data from report" - exit 1 -fi - -TOTAL=$((MISSED + COVERED)) -if [ $TOTAL -eq 0 ]; then - COVERAGE=0 -else - COVERAGE=$((COVERED * 100 / TOTAL)) -fi +# Assign first, so that set -e stops the script when a counter is missing +INSTRUCTION_COUNTER=$(counter INSTRUCTION) +LINE_COUNTER=$(counter LINE) +BRANCH_COUNTER=$(counter BRANCH) +read -r COVERED TOTAL COVERAGE <<< "$INSTRUCTION_COUNTER" +read -r LINES_COVERED LINES_TOTAL LINES_PCT <<< "$LINE_COUNTER" +read -r BRANCHES_COVERED BRANCHES_TOTAL BRANCHES_PCT <<< "$BRANCH_COUNTER" echo "" echo "Test Coverage Report:" -echo " Instructions covered: $COVERED / $TOTAL" -echo " Coverage: ${COVERAGE}%" -echo " Minimum required: ${COVERAGE_THRESHOLD}%" +echo " Instructions covered: $COVERED / $TOTAL (${COVERAGE}%)" +echo " Lines covered: $LINES_COVERED / $LINES_TOTAL (${LINES_PCT}%)" +echo " Branches covered: $BRANCHES_COVERED / $BRANCHES_TOTAL (${BRANCHES_PCT}%)" +echo " Minimum required: ${COVERAGE_THRESHOLD}% of instructions" echo "" -if [ $COVERAGE -lt $COVERAGE_THRESHOLD ]; then +# On GitHub Actions, show the numbers on the run's summary page +if [ -n "${GITHUB_STEP_SUMMARY:-}" ]; then + { + echo "### Unit test coverage" + echo "" + echo "| Counter | Covered | Total | Coverage |" + echo "| --- | ---: | ---: | ---: |" + echo "| Instructions | $COVERED | $TOTAL | ${COVERAGE}% |" + echo "| Lines | $LINES_COVERED | $LINES_TOTAL | ${LINES_PCT}% |" + echo "| Branches | $BRANCHES_COVERED | $BRANCHES_TOTAL | ${BRANCHES_PCT}% |" + echo "" + echo "Minimum required: ${COVERAGE_THRESHOLD}% of instructions. The full HTML report is in the coverage-reports artifact." + } >> "$GITHUB_STEP_SUMMARY" +fi + +if [ "$COVERAGE" -lt "$COVERAGE_THRESHOLD" ]; then echo "ERROR: Test coverage ${COVERAGE}% is below minimum threshold of ${COVERAGE_THRESHOLD}%" echo "" echo "Please add more tests to increase coverage."