name: Compatibility Test Linux-X64|ARM & macOS-ARM

on: pull_request

jobs:
  build:
    strategy:
      matrix:
        go-version: [1.18.x, 1.19.x, 1.20.x, 1.21.x, 1.22.x, 1.23.x, 1.24.x, 1.25.x]
        os: [ubuntu-latest, ubuntu-24.04-arm, macos-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Clear repository
        run: |
          if [ "${{ runner.os }}" = "Linux" ]; then
            sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
          else
            rm -rf $GITHUB_WORKSPACE && mkdir -p $GITHUB_WORKSPACE
          fi

      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v6
        with:
          go-version: ${{ matrix.go-version }}

      - uses: actions/cache@v4
        with:
          path: ~/go/pkg/mod
          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
          restore-keys: |
            ${{ runner.os }}-go-

      - name: main
        run: go test -race -gcflags="all=-l" ./

      - name: decoder
        run: go test -race -gcflags="all=-l" ./decoder

      - name: encoder
        run: go test -race -gcflags="all=-l" ./encoder

      - name: ast
        run: go test -race -gcflags="all=-l" ./ast
