github.com/jwijenbergh/purego@v0.0.0-20240126093400-70ff3a61df13/.github/workflows/test.yml (about)

     1  name: Test
     2  
     3  on: [push, pull_request]
     4  
     5  jobs:
     6    test:
     7      strategy:
     8        matrix:
     9          os: [ubuntu-latest, macos-latest, windows-latest]
    10          go: ['1.18.x', '1.19.x', '1.20.x', '1.21.x']
    11      name: Test with Go ${{ matrix.go }} on ${{ matrix.os }}
    12      runs-on: ${{ matrix.os }}
    13      defaults:
    14        run:
    15          shell: bash
    16      steps:
    17        - name: Git
    18          run: |
    19            # See actions/checkout#135
    20            git config --global core.autocrlf false
    21            git config --global core.eol lf
    22  
    23        - name: Checkout
    24          uses: actions/checkout@v3
    25  
    26        - name: Setup Go
    27          uses: actions/setup-go@v4
    28          with:
    29            go-version: ${{ matrix.go }}
    30  
    31        - name: Set up the prerequisites
    32          if: runner.os == 'Linux'
    33          run: |
    34            sudo apt-get update
    35            sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu qemu-user
    36  
    37        - name: go vet
    38          if: runner.os != 'Windows' && runner.os != 'macOS'
    39          run: |
    40            go vet -v ./...
    41  
    42        - name: go build
    43          run: |
    44            go build -v ./...
    45            # Compile without optimization to check potential stack overflow.
    46            # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
    47            # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120.
    48            go build "-gcflags=all=-N -l" -v ./...
    49  
    50            # Check cross-compiling Windows binaries.
    51            env GOOS=windows GOARCH=386 go build -v ./...
    52            env GOOS=windows GOARCH=amd64 go build -v ./...
    53            env GOOS=windows GOARCH=arm go build -v ./...
    54            env GOOS=windows GOARCH=arm64 go build -v ./...
    55  
    56            # Check cross-compiling macOS binaries.
    57            env GOOS=darwin GOARCH=amd64 go build -v ./...
    58            env GOOS=darwin GOARCH=arm64 go build -v ./...
    59  
    60            # Check cross-compiling Linux binaries.
    61            env GOOS=linux GOARCH=amd64 go build -v ./...
    62            env GOOS=linux GOARCH=arm64 go build -v ./...
    63  
    64            # Check cross-compiling FreeBSD binaries.
    65            # gcflags -std is necessary to make fakecgo the Cgo for
    66            # FreeBSD to add the symbols that libc.so depends on.
    67            env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/jwijenbergh/purego/internal/fakecgo=-std" -v ./...
    68            env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/jwijenbergh/purego/internal/fakecgo=-std" -v ./...
    69  
    70        - name: go mod vendor
    71          if: runner.os != 'Linux'
    72          run: |
    73            mkdir /tmp/vendoring
    74            cd /tmp/vendoring
    75            go mod init foo
    76            echo 'package main' > main.go
    77            echo 'import (' >> main.go
    78            echo '  _ "github.com/jwijenbergh/purego"' >> main.go
    79            echo ')' >> main.go
    80            echo 'func main() {}' >> main.go
    81            go mod edit -replace github.com/jwijenbergh/purego=$GITHUB_WORKSPACE
    82            go mod tidy
    83            go mod vendor
    84            go build -v .
    85  
    86        - name: go test
    87          run: |
    88            env CGO_ENABLED=0 go test -shuffle=on -v -count=10 ./...
    89            env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
    90  
    91        - name: go test (Linux arm64)
    92          if: runner.os == 'Linux'
    93          run: |
    94            go env -w CC=aarch64-linux-gnu-gcc
    95            go env -w CXX=aarch64-linux-gnu-g++
    96            env GOOS=linux GOARCH=arm64 CGO_ENABLED=0 go test -c -o=purego-test-nocgo .
    97            env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-nocgo -test.shuffle=on -test.v -test.count=10
    98            env GOOS=linux GOARCH=arm64 CGO_ENABLED=1 go test -c -o=purego-test-cgo .
    99            env QEMU_LD_PREFIX=/usr/aarch64-linux-gnu qemu-aarch64 ./purego-test-cgo -test.shuffle=on -test.v -test.count=10
   100            go env -u CC
   101            go env -u CXX
   102  
   103        # TODO: add Windows 386 tests
   104  
   105        - name: go test race
   106          if: ${{ !startsWith(matrix.go, '1.18.') && !startsWith(matrix.go, '1.19.') }}
   107          run: |
   108            go test -race -shuffle=on -v -count=10 ./...
   109  
   110    freebsd:
   111      strategy:
   112        matrix:
   113          go: ['1.18.10', '1.19.12', '1.20.7', '1.21.0']
   114      name: Test with Go ${{ matrix.go }} on FreeBSD
   115      runs-on: ubuntu-22.04
   116      defaults:
   117        run:
   118          shell: bash
   119      steps:
   120        - uses: actions/checkout@v3
   121        - name: Run in freebsd
   122          uses: vmactions/freebsd-vm@v1
   123          with:
   124            usesh: true
   125            prepare: |
   126              fetch https://go.dev/dl/go${{matrix.go}}.freebsd-amd64.tar.gz
   127              rm -fr /usr/local/go && tar -C /usr/local -xf go${{matrix.go}}.freebsd-amd64.tar.gz
   128              ln -s /usr/local/go/bin/go /usr/local/bin
   129            run: |
   130              # FreeBSD tests run within QEMU on Ubuntu.
   131              # vmactions/freebsd-vm only supports a single "step" where it
   132              # brings down the VM at the end of the step, so all
   133              # the commands to run need to be put into this single block.
   134  
   135              echo "Running tests on $(uname -a) at $PWD"
   136  
   137              # verify Go is available
   138              go version
   139  
   140              echo "=> go build"
   141              go build -v ./...
   142              # Compile without optimization to check potential stack overflow.
   143              # The option '-gcflags=all=-N -l' is often used at Visual Studio Code.
   144              # See also https://go.googlesource.com/vscode-go/+/HEAD/docs/debugging.md#launch and the issue hajimehoshi/ebiten#2120.
   145              go build "-gcflags=all=-N -l" -v ./...
   146  
   147              # Check cross-compiling Windows binaries.
   148              env GOOS=windows GOARCH=386 go build -v ./...
   149              env GOOS=windows GOARCH=amd64 go build -v ./...
   150              env GOOS=windows GOARCH=arm go build -v ./...
   151              env GOOS=windows GOARCH=arm64 go build -v ./...
   152  
   153              # Check cross-compiling macOS binaries.
   154              env GOOS=darwin GOARCH=amd64 go build -v ./...
   155              env GOOS=darwin GOARCH=arm64 go build -v ./...
   156  
   157              # Check cross-compiling Linux binaries.
   158              env GOOS=linux GOARCH=amd64 go build -v ./...
   159              env GOOS=linux GOARCH=arm64 go build -v ./...
   160  
   161              # Check cross-compiling FreeBSD binaries.
   162              env GOOS=freebsd GOARCH=amd64 go build -gcflags="github.com/jwijenbergh/purego/internal/fakecgo=-std" -v ./...
   163              env GOOS=freebsd GOARCH=arm64 go build -gcflags="github.com/jwijenbergh/purego/internal/fakecgo=-std" -v ./...
   164  
   165              echo "=> go mod vendor"
   166              mkdir /tmp/vendoring
   167              cd /tmp/vendoring
   168              go mod init foo
   169              echo 'package main' > main.go
   170              echo 'import (' >> main.go
   171              echo '  _ "github.com/jwijenbergh/purego"' >> main.go
   172              echo ')' >> main.go
   173              echo 'func main() {}' >> main.go
   174              go mod edit -replace github.com/jwijenbergh/purego=$GITHUB_WORKSPACE
   175              go mod tidy
   176              go mod vendor
   177              go build -v .
   178  
   179              cd $GITHUB_WORKSPACE
   180              echo "=> go test CGO_ENABLED=0"
   181              env CGO_ENABLED=0 go test -gcflags="github.com/jwijenbergh/purego/internal/fakecgo=-std" -shuffle=on -v -count=10 ./...
   182  
   183              echo "=> go test CGO_ENABLED=1"
   184              env CGO_ENABLED=1 go test -shuffle=on -v -count=10 ./...
   185  
   186              if [ -z "$(echo ${{matrix.go}} | grep '^1.1')" ]; then
   187                echo "=> go test race"
   188                go test -race -shuffle=on -v -count=10 ./...
   189              fi