name: test

on:
  push:
    branches:
      - 'master'
    tags:
      - 'v*'
  pull_request:
    branches:
      - 'master'

jobs:
  test:
    runs-on: windows-latest
    env:
      GO111MODULE: on
    strategy:
      fail-fast: false
      matrix:
        go:
          - '1.18'
          - '1.19'
          - '1.20'
    steps:
      -
        name: Checkout
        uses: actions/checkout@v3
      -
        name: Set up Go
        uses: actions/setup-go@v4
        with:
          go-version: ${{ matrix.go }}
      -
        name: Cache Go modules
        uses: actions/cache@v3
        with:
          path: |
            %LocalAppData%\go-build
            ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-${{ matrix.go }}-
      -
        name: Go mod
        run: |
          go mod download
        shell: bash
      -
        name: Test
        run: |
          go test -coverprofile=coverage.txt -covermode=atomic ./...
        shell: bash
      -
        name: Upload coverage
        uses: codecov/codecov-action@v3
        with:
          file: ./coverage.txt
