From f630dcd2a07f4dcf3f6426baf6b45c5ef1123a9f Mon Sep 17 00:00:00 2001 From: Sung Yoon Whang Date: Tue, 30 Jun 2026 15:47:06 -0700 Subject: [PATCH] CI: add coverage step This adds coverage step in the CI by leveraging codecov. Right now the config isn't going to block on any specific numbers yet, but it should at least allow us to collect coverage on every PR so we know when we're not adding appropriate tests. --- .codecov.yml | 16 ++++++++++++++++ .github/workflows/ci.yml | 26 ++++++++++++++++++++++++++ .gitignore | 3 +++ Makefile | 8 +++++++- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000..7818984 --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,16 @@ +coverage: + range: 80..100 + round: down + precision: 2 + + status: + project: + default: + enabled: yes + target: auto + if_not_found: success + if_ci_failed: error +ignore: + - tangopb/ + - tangopb/tangopbmock/ + - example/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 218a623..882145c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,6 +55,31 @@ jobs: echo "=== Test logs ===" find . -name "test.log" -exec echo "--- {} ---" \; -exec cat {} \; || echo "No test logs found" + coverage: + name: Coverage + if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }} + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + with: + persist-credentials: false + + - name: Set up Go + uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5 + with: + go-version-file: go.mod + + - name: Run tests with coverage + run: make cover + + - name: Upload coverage to codecov.io + uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v6 + with: + file: cover.out + verbose: true + dependencies: name: Dependencies if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }} @@ -199,6 +224,7 @@ jobs: runs-on: ubuntu-latest needs: - build-and-test + - coverage - dependencies - lint - workflow-security diff --git a/.gitignore b/.gitignore index f0a0a23..8b8aa74 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,6 @@ tools/gopackagesdriver.sh # Built binaries bin/ + +# Coverage output +cover.out diff --git a/Makefile b/Makefile index 6c88155..4d1a3c5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build test proto gazelle clean clean-proto run-server run-client-get-graph run-client-changed-targets help +.PHONY: build cover test proto gazelle clean clean-proto run-server run-client-get-graph run-client-changed-targets help # Bazel wrapper BAZEL = ./tools/bazel @@ -29,6 +29,12 @@ gazelle: @$(BAZEL) run //:gazelle @echo "BUILD files updated!" +# Run tests with coverage and generate cover.out +cover: ## Run tests with coverage + @echo "Running tests with coverage..." + @go test -race -coverprofile=cover.out -coverpkg=./... ./... + @echo "Coverage report written to cover.out" + # Clean generated files and binaries clean: @echo "Cleaning with Bazel..."