name: Test

on:
  push:
    branches:
      - master
  pull_request:

permissions:
  contents: read

jobs:
  test:
    runs-on: ubuntu-24.04
    strategy:
      matrix:
        go:
          - "1.22"
          - "1.23"
          - "1.24"
    name: test go-${{ matrix.go }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-go@v5
        with:
          go-version: ${{ matrix.go }}
      - name: run test
        run: go test -v -race ./...
  lint:
    runs-on: ubuntu-24.04
    name: lint
    steps:
      - uses: actions/setup-go@v5
        with:
          go-version: "1.22"
          cache: false
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: golangci-lint
        uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
        with:
          version: v2.1.6
      - name: Check 'go mod tidy' makes no changes
        run: |
          go mod tidy
          if ! git diff --exit-code go.mod go.sum; then
            echo "❌ go.mod or go.sum files are not tidy. Please run 'go mod tidy' and commit the changes."
            exit 1
          fi
