Debian Codegraph @

.github/workflows/test.yml

raw
1 # Copyright 2020 Marc-Antoine Ruel. All rights reserved.
2 # Use of this source code is governed under the Apache License, Version 2.0
3 # that can be found in the LICENSE file.
4
5 on: [push, pull_request]
6 name: Run tests
7 jobs:
8 # Runs go test both with code coverage sent to codecov, race detector and
9 # benchmarks. At the end do a quick check to ensure the tests to not leave
10 # files in the tree.
11 test:
12 name: "test: go${{matrix.gover}}.x/${{matrix.os}}"
13 runs-on: "${{matrix.os}}"
14 continue-on-error: true
15 defaults:
16 run:
17 shell: bash
18 strategy:
19 fail-fast: false
20 matrix:
21 os: [ubuntu-latest, macos-latest, windows-latest]
22 # Do not forget to bump every 6 months!
23 gover: ["1.24"]
24 env:
25 PYTHONDONTWRITEBYTECODE: x
26 steps:
27 - name: Turn off git core.autocrlf
28 if: matrix.os == 'windows-latest'
29 run: git config --global core.autocrlf false
30 - uses: actions/checkout@v4
31 with:
32 fetch-depth: 2
33 - uses: actions/setup-go@v5
34 with:
35 go-version: "~${{matrix.gover}}.0"
36 - name: 'go install necessary tools'
37 if: always()
38 run: |
39 go install github.com/maruel/pat/cmd/ba@latest
40 - name: 'Check: go test -cover'
41 if: always()
42 run: go test -timeout=120s -covermode=count -coverprofile coverage.txt -bench=. -benchtime=1x ./...
43 # Don't send code coverage if anything failed to reduce spam.
44 - uses: codecov/codecov-action@v4
45 with:
46 token: ${{secrets.CODECOV_TOKEN}}
47 - name: 'Cleanup'
48 if: always()
49 run: rm coverage.txt
50 - name: 'Check: go test -race'
51 run: go test -timeout=120s -race -bench=. -benchtime=1x ./...
52 - name: 'Check: benchmark 📈'
53 run: ba -against HEAD~1
54 - name: 'Check: go test -short (CGO_ENABLED=0)'
55 env:
56 CGO_ENABLED: 0
57 run: go test -timeout=120s -short -bench=. -benchtime=1x ./...
58 - name: 'Check: go test -short (32 bits)'
59 if: matrix.os != 'macos-latest'
60 env:
61 GOARCH: 386
62 run: go test -timeout=120s -short -bench=. -benchtime=1x ./...
63 - name: "Check: tree is clean"
64 if: always()
65 run: |
66 # Nothing should have changed in the tree up to that point and no
67 # unsuspected file was created.
68 TOUCHED=$(git status --porcelain --ignored)
69 if ! test -z "$TOUCHED"; then
70 echo "Oops, something touched these files, please cleanup:"
71 echo "$TOUCHED"
72 git diff
73 false
74 fi
75
76
77 # Run linters. This workflow can be merged with the test_all one if desired
78 # to cut on runtime, at the cost of latency. I dislike waiting for results
79 # so I prefer to run them in parallel.
80 lint:
81 name: "lint: go${{matrix.gover}}.x/${{matrix.os}}"
82 runs-on: "${{matrix.os}}"
83 continue-on-error: true
84 defaults:
85 run:
86 shell: bash
87 strategy:
88 fail-fast: false
89 matrix:
90 # You may want to run only on linux to save on cost. Projects with
91 # OS-specific code benefits from explicitly linting on macOS and
92 # Windows.
93 os: [ubuntu-latest, macos-latest, windows-latest]
94 # Do not forget to bump every 6 months!
95 gover: ["1.23"]
96 env:
97 PYTHONDONTWRITEBYTECODE: x
98 steps:
99 - name: Turn off git core.autocrlf
100 if: matrix.os == 'windows-latest'
101 run: git config --global core.autocrlf false
102 - uses: actions/checkout@v4
103 - uses: actions/setup-go@v5
104 with:
105 go-version: "~${{matrix.gover}}.0"
106 - name: 'go install necessary tools'
107 if: always()
108 run: |
109 go install github.com/gordonklaus/ineffassign@latest
110 go install github.com/securego/gosec/v2/cmd/[email protected]
111 go install golang.org/x/tools/go/analysis/passes/shadow/cmd/[email protected]
112 go install honnef.co/go/tools/cmd/[email protected]
113 - name: 'go install necessary tools (ubuntu)'
114 if: always() && matrix.os == 'ubuntu-latest'
115 run: |
116 go install github.com/client9/misspell/cmd/misspell@latest
117 go install github.com/google/addlicense@latest
118 - name: 'Check: go vet'
119 if: always()
120 run: go vet -unsafeptr=false ./...
121 - name: 'Check: go vet shadow; shadowed variables'
122 if: always()
123 run: |
124 SHADOW_TOOL="$(which shadow)"
125 if [ -f "${SHADOW_TOOL}.exe" ]; then
126 SHADOW_TOOL="${SHADOW_TOOL}.exe"
127 fi
128 go vet -vettool=$SHADOW_TOOL ./...
129 - name: 'Check: inefficient variable assignment'
130 if: always()
131 run: ineffassign ./...
132 - name: 'Check: staticcheck'
133 if: always()
134 run: staticcheck ./...
135 - name: 'Check: gosec'
136 if: always()
137 run: gosec -fmt=golint -quiet ./...
138 # The following checks are not dependent on the OS or go build tags. Only
139 # run them on ubuntu-latest since it's the fastest one.
140 - name: 'Check: no executable was committed (ubuntu)'
141 if: always() && matrix.os == 'ubuntu-latest'
142 run: |
143 if find . -path '*.sh' -prune -o -path ./.git -prune -o -type f -executable -print | grep -e . ; then
144 echo 'Do not commit executables beside shell scripts'
145 false
146 fi
147 - name: 'Check: addlicense; all sources have a license header (ubuntu)'
148 if: always() && matrix.os == 'ubuntu-latest'
149 run: addlicense -check .
150 - name: 'Check: gofmt; code is well formatted (ubuntu)'
151 if: always() && matrix.os == 'ubuntu-latest'
152 run: |
153 FILES=$(gofmt -s -l .)
154 if ! test -z "$FILES"; then
155 echo 'Please run `gofmt -s -w` on the following files:' >> _gofmt.txt
156 echo "" >> _gofmt.txt
157 for FILE in ${FILES}; do
158 echo "- ${FILE}" >> _gofmt.txt
159 done
160 cat _gofmt.txt
161 echo "## âš  gofmt Failed" >> ../_comments.txt
162 echo "" >> ../_comments.txt
163 cat _gofmt.txt >> ../_comments.txt
164 echo "" >> ../_comments.txt
165 false
166 fi
167 - name: "Check: misspelling; code doesn't contain misspelling (ubuntu)"
168 if: always() && matrix.os == 'ubuntu-latest'
169 run: |
170 ERR=$(misspell .)
171 if ! test -z "$ERR"; then
172 echo "$ERR"
173 echo "## âš  misspell Failed" >> ../_comments.txt
174 echo "" >> ../_comments.txt
175 echo "$ERR" >> ../_comments.txt
176 echo "" >> ../_comments.txt
177 false
178 fi
179 - name: 'Send comments'
180 if: failure()
181 run: |
182 if [ -f ../_comments.txt ]; then
183 URL="${{github.event.issue.pull_request.url}}"
184 if test -z "$URL"; then
185 URL="${{github.api_url}}/repos/${{github.repository}}/commits/${{github.sha}}/comments"
186 fi
187 echo "Sending $(cat ../_comments.txt|wc -l) lines of comments to ${URL}"
188 curl -sS --request POST \
189 --header "Authorization: Bearer ${{secrets.GITHUB_TOKEN}}" \
190 --header "Content-Type: application/json" \
191 --data "$(cat ../_comments.txt | jq -R --slurp '{body: .}')" \
192 "${URL}" > /dev/null
193 rm ../_comments.txt
194 fi
195 - name: "Check: go generate doesn't modify files"
196 if: always()
197 run: |
198 go generate ./...
199 # Also test for untracked files. go generate should not generate ignored
200 # files either.
201 TOUCHED=$(git status --porcelain --ignored)
202 if ! test -z "$TOUCHED"; then
203 echo "go generate created these files, please fix:"
204 echo "$TOUCHED"
205 false
206 fi
207 - name: "Check: go mod tidy doesn't modify files"
208 if: always()
209 run: |
210 go mod tidy
211 TOUCHED=$(git status --porcelain --ignored)
212 if ! test -z "$TOUCHED"; then
213 echo "go mod tidy was not clean, please update:"
214 git diff
215 false
216 fi
217
218
219 # Ensure tests pass on oldest supported Go version.
220 # Do while inside GOPATH, which tests different parts
221 # of the code. This is panicparse specific and will be removed after 2022.
222 old:
223 name: "test: go${{matrix.gover}}/${{matrix.os}}"
224 runs-on: "${{matrix.os}}"
225 continue-on-error: true
226 defaults:
227 run:
228 shell: bash
229 strategy:
230 fail-fast: false
231 matrix:
232 os: [ubuntu-latest]
233 # TODO: switch to an older Go version once tests are made compatible
234 gover: ['1.23']
235 env:
236 PYTHONDONTWRITEBYTECODE: x
237 steps:
238 - name: Turn off git core.autocrlf
239 if: matrix.os == 'windows-latest'
240 run: git config --global core.autocrlf false
241 - uses: actions/checkout@v4
242 - uses: actions/setup-go@v5
243 with:
244 go-version: "=${{matrix.gover}}"
245 - name: 'Check: go test'
246 run: go test -timeout=120s -bench=. -benchtime=1x ./...
247
248
249 codeql:
250 name: "codeql: go${{matrix.gover}}.x/${{matrix.os}}"
251 runs-on: "${{matrix.os}}"
252 continue-on-error: true
253 strategy:
254 fail-fast: false
255 matrix:
256 os: [ubuntu-latest]
257 # Do not forget to bump every 6 months!
258 gover: ["1.23"]
259 permissions:
260 security-events: write
261 steps:
262 - uses: actions/checkout@v4
263 - uses: actions/setup-go@v5
264 with:
265 go-version: "~${{matrix.gover}}.0"
266 - name: Initialize CodeQL
267 uses: github/codeql-action/init@v3
268 with:
269 languages: go
270 - name: Autobuild
271 uses: github/codeql-action/autobuild@v3
272 - name: Perform CodeQL Analysis
273 uses: github/codeql-action/analyze@v3