Skip to content

Commit

Permalink
fix(ci): collect coverage for both unit and integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Dec 2, 2023
1 parent 762699b commit ddb0cb6
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit ddb0cb6

Please sign in to comment.