name: Tests

on:
  push:
    branches: [master]
  pull_request:
    branches: [master]

permissions: read-all

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest]
        go-version: [1.21, 1.22]
    steps:
      - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

      - name: Set up Go
        uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v5.1.0
        with:
          go-version: ${{ matrix.go-version }}
          cache: false

      - name: Test
        run: go test -race -coverprofile=coverage.txt -covermode=atomic
       
      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@968872560f81e7bdde9272853e65f2507c0eca7c # v5.0.0
        with:
          token: ${{ secrets.CODECOV_TOKEN }}

      - name: Golangci-lint
        uses: golangci/golangci-lint-action@971e284b6050e8a5849b72094c50ab08da042db8 # v6.1.1

