Skip to content

fix: exclude examples directory from code coverage reports#43

Merged
miclle merged 3 commits intofox-gonic:mainfrom
miclle:fix/exclude-examples-from-coverage
Dec 8, 2025
Merged

fix: exclude examples directory from code coverage reports#43
miclle merged 3 commits intofox-gonic:mainfrom
miclle:fix/exclude-examples-from-coverage

Conversation

@miclle
Copy link
Copy Markdown
Member

@miclle miclle commented Dec 8, 2025

Summary

This PR fixes the code coverage reporting by properly excluding the examples/ directory from coverage calculations. Previously, the coverage badge showed 49% (Codecov) and 57.3% (local) due to including untested example code. After this fix, coverage accurately reflects ~90.6%.

Problem

  • go test -coverprofile=coverage.txt ./... was including all files in the examples/ directory (191 lines of untested code)
  • These example files had 0% coverage, dragging down the overall coverage from 90.6% to 57.3%
  • While .codecov.yml configured to ignore examples, the coverage file already contained the data

Changes

1. Makefile (Makefile:47-48)

Added post-test filtering to remove examples from coverage.txt:
```bash
@echo "Filtering coverage to exclude examples..."
@grep -v "examples/" coverage.txt > coverage_filtered.txt && mv coverage_filtered.txt coverage.txt || true
```

2. GitHub Workflow (.github/workflows/go.yml:71-79)

Added dedicated filtering step before Codecov upload:
```yaml

  • name: Filter coverage to exclude examples
    if: matrix.os == 'ubuntu-latest'
    run: |
    if [ -f coverage.txt ]; then
    grep -v "examples/" coverage.txt > coverage_filtered.txt || true
    if [ -s coverage_filtered.txt ]; then
    mv coverage_filtered.txt coverage.txt
    fi
    fi
    ```

3. Gitignore (.gitignore:24-26)

Added patterns to ignore temporary coverage files:
```gitignore
coverage*.txt
coverage*.html
coverage*.out
```

Impact

Metric Before After
Total Coverage 57.3% 90.6%
coverage.txt lines 571 380
Examples data 191 lines (0% coverage) 0 lines ✅

Test Plan

  • Local test: make test → Coverage shows 90.6%
  • Verify examples excluded: grep -c "examples/" coverage.txt → 0
  • CI will run and upload correct coverage to Codecov

Verification

After merge, the Codecov badge should update from 49% to approximately 90%.

- Add .codecov.yml configuration file
  - Set coverage precision and range (70-100%)
  - Configure project and patch coverage thresholds
  - Enable coverage comments on PRs
  - Ignore test files and examples

- Update GitHub Actions workflow
  - Add codecov/codecov-action@v5 step
  - Upload coverage.txt after tests
  - Only upload from ubuntu-latest to avoid duplicates
  - Use CODECOV_TOKEN secret for authentication

This enables automatic coverage reporting on PRs and commits,
making it easier to track test coverage changes.
This commit addresses the discrepancy between local coverage (57.3%) and
actual code coverage (90.6%) by properly excluding the examples directory
from coverage reports.

Changes:
- Makefile: Add post-test filtering to remove examples/ from coverage.txt
- GitHub Workflow: Add dedicated filtering step before Codecov upload
- .gitignore: Add patterns to ignore temporary coverage files
  (coverage*.txt, coverage*.html, coverage*.out)

Impact:
- Coverage reports now accurately reflect actual code coverage (~90%)
  instead of including untested example code
- Aligns with existing .codecov.yml ignore configuration
- Temporary coverage files no longer tracked in git
@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.87%. Comparing base (d58c31a) to head (233d542).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main      #43       +/-   ##
===========================================
+ Coverage   49.30%   87.87%   +38.57%     
===========================================
  Files          23       16        -7     
  Lines        1294      726      -568     
===========================================
  Hits          638      638               
+ Misses        638       70      -568     
  Partials       18       18               
Flag Coverage Δ
unittests 87.87% <ø> (+38.57%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 7 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@miclle miclle merged commit 433a040 into fox-gonic:main Dec 8, 2025
10 checks passed
@miclle miclle deleted the fix/exclude-examples-from-coverage branch December 8, 2025 04:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant