name: CI

# Default to 'contents: read', which grants actions to read commits.
#
# If any permission is set, any permission not included in the list is
# implicitly set to "none".
#
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions
permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

on: [push, pull_request]

jobs:
  ci:
    name: ${{ matrix.platform }} (${{ matrix.go-version || 'oldest' }})
    timeout-minutes: 10
    strategy:
      fail-fast: false
      matrix:
        go-version:
          - "" # do not specify go-version to fall back on go-version-file (use go.mod); see https://github.com/actions/setup-go/issues/450#issuecomment-3620402646
          - "oldstable"
          - "stable"
        platform: [ubuntu-24.04, windows-latest, macos-latest]
        include:
          - platform: ubuntu-24.04
            test-cmd: go test -exec sudo -v ./...
            ipv6: true
          - platform: windows-latest
            test-cmd: go test -v ./...
            ipv6: false
          - platform: macos-latest
            test-cmd: go test -v ./...
            ipv6: false

    runs-on: ${{ matrix.platform }}
    steps:
      - name: Setup IPv6
        if: matrix.ipv6
        run: sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0 net.ipv6.conf.default.disable_ipv6=0 net.ipv6.conf.all.disable_ipv6=0
      - name: Checkout code
        uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
        with:
          persist-credentials: false
      - name: Install Go ${{ matrix.go-version }}
        uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
        with:
          go-version: ${{ matrix.go-version }}
          go-version-file: "go.mod" # used when go-version is not specified.
      - name: Lint
        uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
        with:
          args: --timeout=5m --verbose
      - name: Build
        run: go build ./...
      - name: Test
        run: ${{ matrix.test-cmd }}
