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 services:
15 postgres:
16 image: postgres
17 ports:
18 - 5432:5432
19 env:
20 POSTGRES_PASSWORD: postgres
21 options: >-
22 --health-cmd pg_isready
23 --health-interval 10s
24 --health-timeout 5s
25 --health-retries 5
26 runs-on: ${{ matrix.os }}
27 steps:
28 - uses: actions/checkout@v5
29
30 - name: Set up Go
31 uses: actions/setup-go@v6
32 with:
33 go-version: ^1
34
35 - name: Test
36 run: |
37 # We collect coverage data from two sources,
38 # 1) unit tests 2) integration tests
39 #
40 # https://go.dev/testing/coverage/
41 # https://dustinspecker.com/posts/go-combined-unit-integration-code-coverage/
42 # https://github.com/golang/go/issues/51430#issuecomment-1344711300
43 mkdir -p coverage/unit
44 mkdir -p coverage/int
45 mkdir -p coverage/int2
46
47 # Collect unit tests coverage
48 go test -failfast -race -timeout 5m -skip=^TestScript -cover ./... -args -test.gocoverdir=$PWD/coverage/unit
49
50 # Collect integration tests coverage
51 GOCOVERDIR=$PWD/coverage/int go test -failfast -race -timeout 5m -run=^TestScript ./...
52 SOFT_SERVE_DB_DRIVER=postgres \
53 SOFT_SERVE_DB_DATA_SOURCE=postgres://postgres:postgres@localhost/postgres?sslmode=disable \
54 GOCOVERDIR=$PWD/coverage/int2 go test -failfast -race -timeout 5m -run=^TestScript ./...
55
56 # Convert coverage data to legacy textfmt format to upload
57 go tool covdata textfmt -i=coverage/unit,coverage/int,coverage/int2 -o=coverage.txt
58 - uses: codecov/codecov-action@v5
59 with:
60 file: ./coverage.txt