fix: deduplicate coverage blocks in CI workflow#76
Merged
Conversation
Fix incorrect coverage percentages in PR comments caused by fgrosse/go-coverage-report#61. The action counts duplicate coverage blocks multiple times instead of merging them. When using -coverpkg=./internal/..., Go creates coverage entries for each code block for each test package (13 entries per block). The action was summing these duplicates, showing ~20% coverage for files that actually have 100% coverage. The fix adds an awk step to merge duplicate blocks before uploading the coverage artifact, keeping only the maximum count for each block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix incorrect coverage percentages in PR comments caused by a known bug in
fgrosse/go-coverage-report(#61).Problem
When using
-coverpkg=./internal/..., Go creates duplicate coverage entries for each code block (one per test package). The action counts these duplicates multiple times instead of merging them, resulting in grossly incorrect percentages.Example from PR #75:
The "1274 statements" was actually 100 unique statements × ~13 test packages.
Fix
Add an awk step to merge duplicate coverage blocks before uploading the artifact. For each code block, we keep only the maximum execution count across all duplicates.
Test plan
go tool cover -funcshows correct 100% coverage after deduplication