name: Push Check Linux-Qemu

on: push

jobs:
  build:
    strategy:
      matrix:
        go-version: [1.15.x, 1.19.x]
        os: [arm]
    runs-on: ${{ matrix.os }}
    steps:
      - name: Clear repository
        run: sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE

      - uses: actions/checkout@v2

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

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

      - name: Compatibility Test - qemu
        run: |
          printf ' #!/bin/bash\n if [ ! -x "/usr/bin/qemu-x86_64" ];then\n sudo apt-get update\n sudo apt-get -y install make gcc g++ libglib2.0-dev libpixman-1-dev libfdt-dev python3-pip ninja-build\n sudo pip3 install meson\n wget https://download.qemu.org/qemu-6.2.0.tar.xz\n tar -xvf qemu-6.2.0.tar.xz\n cd qemu-6.2.0\n sudo ./configure\n sudo make -j 4\n sudo make install\n cd ..\n cp /usr/local/bin/qemu-x86_64  /usr/bin/qemu-x86_64\n fi\n' > qemu_install.sh
          chmod +x qemu_install.sh
          ./qemu_install.sh
          GOARCH=amd64 go test -gcflags=-d=checkptr=0 -c .
          qemu-x86_64 -cpu max ./sonic.test -test.v