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
8 changes: 0 additions & 8 deletions .github/workflows/_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion docs/GITHUB_WORKFLOWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/TESTING_UNIT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
65 changes: 45 additions & 20 deletions scripts/check-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: <counter type="INSTRUCTION" missed="X" covered="Y"/>
# The report is a single line; the last INSTRUCTION counter is the report-level total
INSTRUCTIONS=$(grep -o '<counter type="INSTRUCTION"[^>]*>' "$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 "<counter type=\"$1\"[^>]*>" "$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."
Expand Down
Loading