From 0e4e1a73d10891796e4e478d3b09e49efb3981de Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Fri, 1 Dec 2023 23:07:37 -0500 Subject: [PATCH] fix(ci): collect coverage for both unit and integration tests --- .github/workflows/coverage.yml | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3246553e8..5318d11e1 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -8,7 +8,10 @@ on: jobs: coverage: - runs-on: ubuntu-latest + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -19,12 +22,23 @@ jobs: - name: Test run: | - mkdir covdatafiles - GOCOVERDIR=$PWD/covdatafiles \ - go test -failfast -race -coverpkg=./... -covermode=atomic -coverprofile=coverage.txt ./... -timeout 5m + # We collect coverage data from two sources, + # 1) unit tests 2) integration tests + # + # https://go.dev/testing/coverage/ + # https://dustinspecker.com/posts/go-combined-unit-integration-code-coverage/ + # https://github.com/golang/go/issues/51430#issuecomment-1344711300 + mkdir -p coverage/{unit,integration} - # Convert coverage data to legacy format - go tool covdata textfmt -i=covdatafiles -o=covdata.txt + # Collect integration tests coverage + GOCOVERDIR=$PWD/coverage/integration go test -failfast -race -timeout 5m ./... + + # Collect unit tests coverage + go test -failfast -race -timeout 5m -cover ./... -args -test.gocoverdir=$PWD/coverage/unit + + # Convert coverage data to legacy textfmt format to upload + go tool covdata textfmt -i=coverage/unit -o=unit.txt + go tool covdata textfmt -i=coverage/integration -o=integration.txt - uses: codecov/codecov-action@v3 with: - files: coverage.txt,covdata.txt + files: unit.txt,integration.txt