name: Tests

on:
  push:
    branches:
    - main
  pull_request:
    branches:
    - main

jobs:
  build-and-test:
    strategy:
      matrix:
        # Latest two supported releases.
        go-version: ['1.24', '1.25']
        os: [ubuntu-22.04, ubuntu-24.04, ubuntu-24.04-arm, macos-14, macos-15, windows-2022, windows-2025]
    runs-on: ${{ matrix.os }}

    steps:
    - name: Check out code
      uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0

    - name: Install Go
      uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v5.0.2
      with:
        go-version: ${{ matrix.go-version }}

    - name: Check formatting
      if: ${{ matrix.go-version == '1.25' && matrix.os == 'ubuntu-24.04' }}
      run: diff -u <(echo -n) <(gofmt -d .)

    - name: Check Go modules
      if: ${{ matrix.go-version == '1.25' && matrix.os == 'ubuntu-24.04' }}
      run: |
        go mod tidy -diff

    - name: Test (native)
      run: go test -v ./...

    - name: Build (cross-compile)
      if: matrix.os == 'ubuntu-24.04'
      run: |
        GOOS=darwin go build ./...
        GOOS=dragonfly go build ./...
        GOOS=freebsd go build ./...
        GOOS=linux go build ./...
        GOOS=netbsd go build ./...
        GOOS=openbsd go build ./...
        GOOS=solaris go build ./...
        GOOS=windows go build ./...
