coverage.yml

 1name: coverage
 2
 3on:
 4  push:
 5    branches:
 6      - "main"
 7  pull_request:
 8
 9jobs:
10  coverage:
11    strategy:
12      matrix:
13        os: [ubuntu-latest] # TODO: add macos & windows
14    runs-on: ${{ matrix.os }}
15    steps:
16      - uses: actions/checkout@v4
17
18      - name: Set up Go
19        uses: actions/setup-go@v5
20        with:
21          go-version: ^1
22
23      - name: Test
24        run: |
25          # We collect coverage data from two sources,
26          # 1) unit tests 2) integration tests
27          #
28          # https://go.dev/testing/coverage/
29          # https://dustinspecker.com/posts/go-combined-unit-integration-code-coverage/
30          # https://github.com/golang/go/issues/51430#issuecomment-1344711300
31          mkdir -p coverage/unit
32          mkdir -p coverage/int
33
34          # Collect unit tests coverage
35          go test -failfast -race -timeout 5m -skip=^TestScript -cover ./... -args -test.gocoverdir=$PWD/coverage/unit
36
37          # Collect integration tests coverage
38          GOCOVERDIR=$PWD/coverage/int go test -failfast -race -timeout 5m -run=^TestScript ./...
39
40          # Convert coverage data to legacy textfmt format to upload
41          go tool covdata textfmt -i=coverage/unit,coverage/int -o=coverage.txt
42      - uses: codecov/codecov-action@v3
43        with:
44          file: ./coverage.txt