From 485bc2d3192aa6ccad45660ce03ff95c7af05e92 Mon Sep 17 00:00:00 2001 From: Luca Comellini Date: Wed, 28 Feb 2024 12:55:18 -0800 Subject: [PATCH] Add Codecov Problem: We don't have a history of our code coverage and we want to see how it changes over time and with every PR. We also want to have a badge that shows the overall coverage. Solution: Use Codecov to upload coverage and get diffs in every PR that changes code. Also add a badge in the README to show the coverage. --- .codecov.yml | 7 +++++++ .github/workflows/ci.yml | 5 +++++ Makefile | 8 ++++---- README.md | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .codecov.yml diff --git a/.codecov.yml b/.codecov.yml new file mode 100644 index 0000000000..cec39aedfb --- /dev/null +++ b/.codecov.yml @@ -0,0 +1,7 @@ +coverage: + status: + project: + default: + informational: true +comment: + require_changes: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35d6bd344e..075f297030 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -67,6 +67,11 @@ jobs: - name: Run Tests run: make unit-test + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@54bcd8715eee62d40e33596ef5e8f0f48dbbccab # v4.1.0 + with: + token: ${{ secrets.CODECOV_TOKEN }} + - name: Upload Coverage Report uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: diff --git a/Makefile b/Makefile index 87303395e1..d3d1cc4f1b 100644 --- a/Makefile +++ b/Makefile @@ -140,10 +140,10 @@ lint: ## Run golangci-lint against code .PHONY: unit-test unit-test: ## Run unit tests for the go code # We have to run the tests in the cmd package using `go test` because of a bug with the CLI library cobra. See https://github.com/spf13/cobra/issues/2104. - go test ./cmd/... -race -coverprofile cmd-cover.out - go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --race --keep-going --fail-on-pending --trace --cover --coverprofile=cover.out -r internal - go tool cover -html=cover.out -o cover.html - go tool cover -html=cmd-cover.out -o cmd-cover.html + go test ./cmd/... -race -shuffle=on -coverprofile=cmd-coverage.out -covermode=atomic + go run github.com/onsi/ginkgo/v2/ginkgo --randomize-all --randomize-suites --race --keep-going --fail-on-pending --trace --covermode=atomic --coverprofile=coverage.out -r internal + go tool cover -html=coverage.out -o cover.html + go tool cover -html=cmd-coverage.out -o cmd-cover.html .PHONY: njs-unit-test njs-unit-test: ## Run unit tests for the njs httpmatches module diff --git a/README.md b/README.md index 18d0919eb0..eab96bc481 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Continuous Integration](https://github.com/nginxinc/nginx-gateway-fabric/actions/workflows/ci.yml/badge.svg)](https://github.com/nginxinc/nginx-gateway-fabric/actions/workflows/ci.yml) [![Conformance Testing](https://github.com/nginxinc/nginx-gateway-fabric/actions/workflows/conformance.yml/badge.svg)](https://github.com/nginxinc/nginx-gateway-fabric/actions/workflows/conformance.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/nginxinc/nginx-gateway-fabric)](https://goreportcard.com/report/github.com/nginxinc/nginx-gateway-fabric) +[![codecov](https://codecov.io/gh/nginxinc/nginx-gateway-fabric/graph/badge.svg?token=32ULC8F13Z)](https://codecov.io/gh/nginxinc/nginx-gateway-fabric) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/nginxinc/nginx-gateway-fabric?logo=github&sort=semver)](https://github.com/nginxinc/nginx-gateway-fabric/releases/latest) [![Slack](https://img.shields.io/badge/slack-%23nginx--gateway--fabric-green?logo=slack)](https://nginxcommunity.slack.com/channels/nginx-gateway-fabric) [![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)