name: ci

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

# Cancel in-progress runs when a new commit lands on the same branch /
# pr, so we don't waste minutes on stale SHAs.
concurrency:
  group: ci-${{ github.ref }}
  cancel-in-progress: true

jobs:
  test:
    name: test (${{ matrix.os }})
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: false
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
    steps:
      - uses: actions/checkout@v4

      - name: set up go
        uses: actions/setup-go@v5
        with:
          go-version: "1.23"
          cache: true

      - name: go vet
        run: go vet ./...

      - name: gofmt check
        # Windows' bash is mingw; gofmt outputs paths with slashes so the
        # diff check works there too. Skip on windows only if needed.
        if: runner.os != 'Windows'
        run: |
          diff=$(gofmt -l .)
          if [ -n "$diff" ]; then
            echo "gofmt issues:"
            echo "$diff"
            exit 1
          fi

      - name: go test
        run: go test -race ./...
