name: Tests and linters
on: [pull_request]

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
          cache: true

      - name: Install linters
        run: make lint-install

      - name: Run linters
        run: make lint

  tests:
    name: Tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        go_versions: [ '1.20', '1.21' ]
      fail-fast: false
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: '${{ matrix.go_versions }}'
          cache: true

      - name: Run tests
        run: make test

  tests-race:
    name: Tests with -race
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
          cache: true

      - name: Run tests
        run: go test ./... -count=1 -race

  staticcheck:
    name: Staticcheck
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3

      - name: Set up Go
        uses: actions/setup-go@v3
        with:
          go-version: '1.21'
          cache: true

      - name: Install staticcheck
        run: make staticcheck-install

      - name: Run staticcheck
        run: make staticcheck-run