name: Test
on:
  push:
    paths-ignore:
      - "docs/**"
      - "README.md"
      - ".github/ISSUE_TEMPLATE/**"
    branches:
      - Alpha
    tags:
      - "v*"
  pull_request:
    branches:
      - Alpha

jobs:
  test:
    strategy:
      matrix:
        os:
          - 'ubuntu-latest' # amd64 linux
          - 'windows-latest' # amd64 windows
          - 'macos-latest' # arm64 macos
          - 'ubuntu-24.04-arm' # arm64 linux
          - 'macos-15-intel' # amd64 macos
        go-version:
          - '1.26'
          - '1.25'
          - '1.24'
          - '1.23'
          - '1.22'
          - '1.21'
          - '1.20'
      fail-fast: false
    runs-on: ${{ matrix.os }}
    defaults:
      run:
        shell: bash
    env:
      CGO_ENABLED: 0
      GOTOOLCHAIN: local
      # Fix mingw trying to be smart and converting paths https://github.com/moby/moby/issues/24029#issuecomment-250412919
      MSYS_NO_PATHCONV: true
    steps:
      - uses: actions/checkout@v5

      - name: Setup Go
        uses: actions/setup-go@v6
        with:
          go-version: ${{ matrix.go-version }}
          check-latest: true # Always check for the latest patch release

      - name: Revert Golang commit for Windows7/8
        if: ${{ runner.os == 'Windows' && matrix.go-version != '1.20' }}
        run: |
          cd $(go env GOROOT)
          patch --verbose -p 1 < $GITHUB_WORKSPACE/.github/patch/go${{matrix.go-version}}.patch

      - name: Remove inbound test for macOS
        if: ${{ runner.os == 'macOS' }}
        run: |
          rm -rf listener/inbound/*_test.go

      - name: Test
        run: go test ./... -v -count=1

      - name: Test with tag with_gvisor
        run: go test ./... -v -count=1 -tags "with_gvisor"