From 05a2095d09eeae04e1d08272de75fdace963b0f9 Mon Sep 17 00:00:00 2001 From: David Muir Sharnoff Date: Sun, 21 Aug 2022 19:49:15 -0700 Subject: [PATCH] improve coverage calculation --- .github/workflows/codecov.yml | 11 ++++++++--- Makefile | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 85167084..144d3a0d 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -1,6 +1,6 @@ name: Test and coverage -on: [push] +on: [push, pull_request] jobs: build: @@ -13,6 +13,11 @@ jobs: with: go-version: '1.18' - name: Run coverage - run: go test ./... -race -coverprofile=coverage.txt -covermode=atomic -coverpkg github.com/muir/xop-go + run: make calculate_coverage + - name: Upload coverage to Codecov - run: bash <(curl -s https://codecov.io/bash) + uses: codecov/codecov-action@v2 + with: + verbose: true + flags: go_tests + fail_ci_if_error: true diff --git a/Makefile b/Makefile index 3490f718..2efdf6b6 100644 --- a/Makefile +++ b/Makefile @@ -34,3 +34,21 @@ ${GOBIN}/enumer:; -chmod -w $@ -rm $@.tmp +calculate_coverage: + echo "mode: atomic" > coverage.txt + for d in $$(go list ./...); do \ + go test -race -covermode=atomic -coverprofile=profile.out -coverpkg=github.com/muir/xop-go/... $$d; \ + if [ -f profile.out ]; then \ + grep -v ^mode profile.out >> coverage.txt; \ + rm profile.out; \ + fi; \ + done + + +coverage: calculate_coverage + go tool cover -html=coverage.txt + +golanglint: + # binary will be $(go env GOPATH)/bin/golangci-lint + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.45.2 + golangci-lint --version