name: Go Test

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  run-tests:
    strategy:
      matrix:
        version: [
          "~1.21",
          "~1.22",
          "~1.23",
          "~1.24"
        ]
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4

    - name: Set up Go
      uses: actions/setup-go@v5
      with:
        go-version: ${{ matrix.version }}

    - name: Linter
      run: make lint-prepare && make lint

    - name: Test
      run: make test

  generate-report:
    needs:
      - run-tests
    runs-on: ubuntu-latest
    strategy:
      matrix:
        version: [
          "~1.24"
        ]
    steps:
      - uses: actions/checkout@v4
      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.version }}

      - name: Test
        run: go test -v ./... -gcflags=all=-l -coverprofile=coverage.txt -covermode=atomic -race

      - name: Upload coverage to Codecov
        uses: codecov/codecov-action@v3
