name: CI
on: [push, pull_request]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go: [ '1.19', '1.18' ]
    name: Go ${{ matrix.go }} test
    steps:
      - name: Checkout repository
        uses: actions/checkout@v3
      - name: Cache Go modules
        uses: actions/cache@v3
        with:
          path: |
            ~/go/pkg/mod
            ~/.cache/go-build
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-
      - name: Install Go stable version
        uses: actions/setup-go@v3
        with:
          go-version: ${{ matrix.go }}
          check-latest: true
      - name: Test
        run: go test -v -race ./...
      - name: Upload code coverage to codecov
        if: matrix.go == '1.19'
        uses: codecov/codecov-action@v3
        with:
          file: ./coverage.out

