-
Notifications
You must be signed in to change notification settings - Fork 0
Exclude mockgen.go files from test coverage tracking #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
|
@copilot can we make workflow use the same script for local generation to make it easier to maintain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds filtering logic to exclude MockGen-generated files from test coverage tracking, both in local development (scripts/run-tests.sh) and CI/CD pipeline (.github/workflows/publish-coverage.yaml). The changes aim to prevent machine-generated mock code from artificially inflating coverage metrics.
Key Changes:
- Added post-test filtering step in local coverage script to exclude
mockgen.gofiles - Added similar filtering step in GitHub Actions coverage workflow before Codecov upload
- Both implementations use
grep -vwith fallback to preserve original file if filtering fails
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| scripts/run-tests.sh | Adds filtering after test execution to exclude mockgen.go from coverage.out before HTML report generation |
| .github/workflows/publish-coverage.yaml | Adds filtering step before Codecov upload to exclude mockgen.go from coverage.txt |
Co-authored-by: HermanPlay <78978614+HermanPlay@users.noreply.github.com>
Done! The workflow now uses the same
This maintains a single source of truth for the coverage logic. Commit: 6c7c46f Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Generated mock files (
**/mockgen.go) were being included in coverage reports, artificially inflating coverage metrics with 542 lines of machine-generated code across 3 files.Changes
Shared test script (
scripts/run-tests.sh):COVERAGE_FILE,GENERATE_HTML)CI/CD pipeline (
.github/workflows/publish-coverage.yaml):scripts/run-tests.shscript with environment variablesImplementation
The script now accepts environment variables for configuration:
Filter pattern applied to coverage files:
The coverage file format remains unchanged and compatible with
go tool cover. All 3 mockgen.go files (package/service/mocks/,package/filestorage/,package/repository/mocks/) are now excluded from tracking.Benefits
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.