From d14ec9996ed979fa365e2d5dd48110881c438c00 Mon Sep 17 00:00:00 2001 From: Florian Kinder Date: Tue, 3 Feb 2026 22:00:03 +0100 Subject: [PATCH] fix: deduplicate coverage blocks in CI workflow 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. --- .github/workflows/go.yml | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 82aca40..0bd5188 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -32,7 +32,22 @@ jobs: run: go vet ./internal/... - name: Run tests - run: go test -coverprofile=cover.out -coverpkg=./internal/... ./internal/... + run: go test -coverprofile=cover.out.raw -coverpkg=./internal/... ./internal/... + + - name: Deduplicate coverage blocks + # Workaround for fgrosse/go-coverage-report#61: merge duplicate coverage blocks + # When using -coverpkg, Go creates duplicate entries for each test package + run: | + head -1 cover.out.raw > cover.out + tail -n +2 cover.out.raw | awk '{ + key = $1 + stmt = $2 + count = $3 + 0 + if (count > counts[key]) counts[key] = count + stmts[key] = stmt + } END { + for (key in stmts) print key, stmts[key], counts[key] + 0 + }' | sort >> cover.out - name: Archive code coverage results uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v4