From a4f640c410c8ee5e8c637233cd094c4ffb9cb049 Mon Sep 17 00:00:00 2001 From: Khurram Baig Date: Tue, 18 Aug 2026 20:24:03 +0530 Subject: [PATCH] fix: exclude generated and non-library code from codecov coverage Codecov reports low coverage because it includes auto-generated protobuf code, vendored deps, CLI entry points, and test infrastructure in the denominator. Filter these out so coverage reflects actual library code. Mirrors the approach proven in tektoncd/triggers#2101. - Replace bare `go test ./...` with filtered package list + `-coverpkg` - Strip .pb.go files from profile - Add `disable_search: true` to codecov upload step - Use bare directory names and glob patterns in .codecov.yaml Co-Authored-By: Claude Opus 4.6 --- .codecov.yaml | 43 ++++++++++++++++--------------- .github/workflows/go-coverage.yml | 7 ++++- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/.codecov.yaml b/.codecov.yaml index 27576e7453..137b25cab3 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -1,32 +1,33 @@ coverage: - # Commit status https://docs.codecov.io/docs/commit-status are used - # to block PR based on coverage threshold. status: project: default: target: auto threshold: 5% patch: - # Disable the coverage threshold of the patch, so that PRs are - # only failing because of overall project coverage threshold. - # See https://docs.codecov.io/docs/commit-status#disabling-a-status. default: false ignore: # Auto-generated protobuf code. - - "proto/v1alpha2/results_go_proto/**" - - "proto/v1alpha3/results_go_proto/**" - - "proto/pipeline/v1/pipeline_go_proto/**" - - "pkg/api/server/db/pagination/proto/internal_go_proto/**" - - "pkg/api/server/v1alpha2/lister/proto/pagetoken_go_proto/**" - - "internal/fieldmask/test/**" - - "pkg/test/**" - - "cmd/**" - - "test/**" - - "config/**" - - "hack/**" - - "tools/**" - - "release/**" - - "tekton/**" - - "docs/**" - - "vendor/**" + - "proto" + - "**/*.pb.go" + - "**/fake/**" + # Entry-point binaries. + - "cmd" + # Test infrastructure. + - "test" + - "pkg/test/" + - "pkg/internal/test/" + - "pkg/api/server/test/" + - "internal/fieldmask/test/" + - "pkg/cli/testutils/" + # Non-executable files (doc, go:generate). + - "**/doc.go" + - "**/generate.go" + - "config" + - "hack" + - "tools" + - "release" + - "tekton" + - "docs" + - "vendor" diff --git a/.github/workflows/go-coverage.yml b/.github/workflows/go-coverage.yml index e722e56a8d..d19c8653b7 100644 --- a/.github/workflows/go-coverage.yml +++ b/.github/workflows/go-coverage.yml @@ -43,7 +43,11 @@ jobs: - name: Generate coverage working-directory: ${{ github.workspace }}/src/github.com/tektoncd/results run: | - go test ./... -coverprofile=coverage.out -covermode=atomic || true + PACKAGES=$(go list ./... | grep -vE '/cmd(/|$)|/vendor(/|$)|/hack(/|$)|/test(/|$)|/tools(/|$)|/release(/|$)|/tekton(/|$)|/docs(/|$)|/config(/|$)|/proto(/|$)|/pkg/test(/|$)|/pkg/internal/test(/|$)|/pkg/api/server/test(/|$)|/pkg/cli/testutils(/|$)|/internal/fieldmask/test(/|$)|_go_proto(/|$)') + COVERPKG=$(echo $PACKAGES | tr ' ' ',') + go test -coverprofile=coverage_raw.out -covermode=atomic -coverpkg="$COVERPKG" $PACKAGES + grep -vE '\.pb\.go' coverage_raw.out > coverage.out + rm -f coverage_raw.out echo "Generated coverage profile" - name: Upload coverage to Codecov @@ -54,3 +58,4 @@ jobs: flags: unit-tests use_oidc: true fail_ci_if_error: false + disable_search: true