From 14c8e30251c80b18a978c595aeb2e358a52c1fae Mon Sep 17 00:00:00 2001 From: tamimi Date: Sun, 15 Feb 2026 11:12:50 +0400 Subject: [PATCH] ci: add test coverage reporting to CI pipeline Add coverage summary and artifact upload to CI workflow, and enhance Makefile test-coverage target with atomic covermode and a new test-coverage-view target that opens the HTML report in a browser. Co-Authored-By: Claude Opus 4.6 --- .github/workflows/ci.yml | 22 +++++++++++++++++++--- Makefile | 15 +++++++++++---- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cdc0e5a..09b05d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,17 +28,33 @@ jobs: - name: Download dependencies run: go mod download - - name: Run tests + - name: Run tests with coverage shell: bash - run: go test -v -race -coverprofile=coverage.out ./... + run: go test -coverprofile=coverage.out -covermode=atomic ./... - - name: Upload coverage + - name: Generate coverage report + if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.22' + run: | + go tool cover -func=coverage.out + go tool cover -html=coverage.out -o coverage.html + + - name: Upload coverage to Codecov if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.22' uses: codecov/codecov-action@v4 with: files: coverage.out fail_ci_if_error: false + - name: Upload coverage artifacts + if: matrix.os == 'ubuntu-latest' && matrix.go-version == '1.22' + uses: actions/upload-artifact@v4 + with: + name: coverage-report + path: | + coverage.out + coverage.html + retention-days: 14 + lint: name: Lint runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 86bf0d5..fc1d847 100644 --- a/Makefile +++ b/Makefile @@ -82,13 +82,19 @@ test: @echo "$(BLUE)Running tests...$(NC)" $(GO) test -v -race ./... -# Run tests with coverage -.PHONY: test-coverage +# Test coverage +.PHONY: test-coverage test-coverage-view + test-coverage: @echo "$(BLUE)Running tests with coverage...$(NC)" - $(GO) test -v -race -coverprofile=coverage.out ./... + $(GO) test -coverprofile=coverage.out -covermode=atomic ./... $(GO) tool cover -html=coverage.out -o coverage.html - @echo "$(GREEN)✓ Coverage report: coverage.html$(NC)" + @echo "$(GREEN)✓ Coverage report generated$(NC)" + $(GO) tool cover -func=coverage.out + +test-coverage-view: test-coverage + @echo "$(BLUE)Opening coverage report...$(NC)" + open coverage.html # Run integration tests (opt-in, requires credentials) .PHONY: test-integration @@ -221,6 +227,7 @@ help: @echo "$(BLUE)Test:$(NC)" @echo " test Run tests" @echo " test-coverage Run tests with coverage report" + @echo " test-coverage-view Run tests with coverage and open report in browser" @echo " test-integration Run integration tests (requires credentials)" @echo "" @echo "$(BLUE)Quality:$(NC)"