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