Skip to content

Commit 19b8520

Browse files
committed
github actions: Overhaul
- Run tests first - Do not run tests when running benchmarks - Use go install instead of go get - Fix ineffassign (Again?) - Add PYTHONDONTWRITEBYTECODE: x because pyc and __pycache__ are always a source of trouble and I copy paste this file a lot. Do not bump 32 bits check to go1.17 yet since it seems it's broken.
1 parent 3fa27ec commit 19b8520

2 files changed

Lines changed: 65 additions & 66 deletions

File tree

.github/workflows/test.yml

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
gover: ["1.17"]
2828
runs-on: "${{matrix.os}}"
2929
name: "go${{matrix.gover}}.x on ${{matrix.os}}"
30+
env:
31+
PYTHONDONTWRITEBYTECODE: x
3032
steps:
3133
- uses: actions/setup-go@v2
3234
with:
@@ -51,23 +53,70 @@ jobs:
5153
path: ~/go
5254
key: "${{runner.os}}-gopkg-${{hashFiles('go.sum', '.github/workflows/*.yml')}}"
5355

54-
# Fetch the tools before checking out, so they don't modify go.mod/go.sum.
56+
# Run tests first because it's important.
57+
- name: 'Check: go test -cover'
58+
run: go test -timeout=60s -covermode=count -coverprofile coverage.txt ./...
59+
# Don't send code coverage if anything failed to reduce spam.
60+
- uses: codecov/codecov-action@v2
61+
- name: 'Cleanup'
62+
if: always()
63+
run: rm coverage.txt
64+
65+
# Don't run go test -race if anything failed, to speed up the results.
66+
- name: 'Check: go test -race'
67+
run: go test -timeout=60s -race ./...
68+
- name: 'Check: go test -bench=.'
69+
run: go test -timeout=60s -bench=. -benchtime=100ms -cpu=1 -run NONE ./...
70+
71+
- name: "Check: tree is clean"
72+
if: always()
73+
run: |
74+
# Nothing should have changed in the tree up to that point and no
75+
# unsuspected file was created.
76+
TOUCHED=$(git status --porcelain)
77+
if ! test -z "$TOUCHED"; then
78+
echo "Oops, something touched these files, please cleanup:"
79+
echo "$TOUCHED"
80+
git diff
81+
false
82+
fi
83+
84+
- name: "Check: go generate doesn't modify files"
85+
if: always()
86+
run: |
87+
go generate ./...
88+
TOUCHED=$(git status --porcelain)
89+
if ! test -z "$TOUCHED"; then
90+
echo "go generate created these files, please fix:"
91+
echo "$TOUCHED"
92+
false
93+
fi
94+
95+
- name: "Check: go mod tidy doesn't modify files"
96+
if: always()
97+
run: |
98+
go mod tidy
99+
TOUCHED=$(git status --porcelain)
100+
if ! test -z "$TOUCHED"; then
101+
echo "go mod tidy was not clean, please update:"
102+
git diff
103+
false
104+
fi
105+
106+
# Fetch the tools.
55107
- name: 'go get necessary tools'
56-
run: >
57-
cd ..;
58-
go get -u -v
59-
github.com/gordonklaus/ineffassign
60-
github.com/securego/gosec/cmd/gosec
61-
golang.org/x/lint/golint
62-
golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
63-
honnef.co/go/tools/cmd/staticcheck
108+
if: always()
109+
run: |
110+
go install github.com/gordonklaus/ineffassign@latest
111+
go install github.com/securego/gosec/cmd/gosec@latest
112+
go install golang.org/x/lint/golint@latest
113+
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
114+
go install honnef.co/go/tools/cmd/staticcheck@latest
64115
- name: 'go get necessary tools (ubuntu)'
65116
if: always() && matrix.os == 'ubuntu-latest'
66-
run: >
67-
cd ..;
68-
go get -u -v
69-
github.com/client9/misspell/cmd/misspell
70-
github.com/google/addlicense
117+
run: |
118+
go install github.com/client9/misspell/cmd/misspell@latest
119+
go install github.com/google/addlicense@latest
71120
72121
# Now run proper checks.
73122
- name: 'Check: go vet'
@@ -85,7 +134,7 @@ jobs:
85134
run: golint -set_exit_status ./...
86135
- name: 'Check: inefficient variable assignment'
87136
if: always()
88-
run: ineffassign .
137+
run: ineffassign ./...
89138
- name: 'Check: staticcheck'
90139
if: always()
91140
run: staticcheck ./...
@@ -134,56 +183,6 @@ jobs:
134183
false
135184
fi
136185
137-
# Run tests last since it's potentially the slowest step.
138-
- name: 'Check: go test -cover'
139-
run: go test -timeout=60s -covermode=count -coverprofile coverage.txt ./...
140-
# Don't send code coverage if anything failed to reduce spam.
141-
- uses: codecov/codecov-action@v2
142-
- name: 'Cleanup'
143-
run: rm coverage.txt
144-
# Don't run go test -race if anything failed, to speed up the results.
145-
- name: 'Check: go test -race'
146-
run: go test -timeout=60s -race ./...
147-
- name: 'Check: go test -bench .'
148-
run: go test -timeout=60s -bench . -benchtime=100ms -cpu=1 ./...
149-
150-
- name: "Check: tree is clean"
151-
run: |
152-
# Nothing should have changed in the tree up to that point and no
153-
# unsuspected file was created.
154-
TOUCHED=$(git status --porcelain --ignored)
155-
if ! test -z "$TOUCHED"; then
156-
echo "Oops, something touched these files, please cleanup:"
157-
echo "$TOUCHED"
158-
git diff
159-
false
160-
fi
161-
162-
- name: "Check: go generate doesn't modify files"
163-
run: |
164-
go generate ./...
165-
# TODO(maruel): Due to https://github.com/golang/go/issues/40276, ignore
166-
# go.mod/go.sum modifications. Remove once a new Go toolchain fixes
167-
# this.
168-
git checkout HEAD -- go.mod go.sum
169-
# Also test for untracked files.
170-
TOUCHED=$(git status --porcelain --ignored)
171-
if ! test -z "$TOUCHED"; then
172-
echo "go generate created these files, please fix:"
173-
echo "$TOUCHED"
174-
false
175-
fi
176-
177-
- name: "Check: go mod tidy doesn't modify files"
178-
run: |
179-
go mod tidy
180-
TOUCHED=$(git status --porcelain --ignored)
181-
if ! test -z "$TOUCHED"; then
182-
echo "go mod tidy was not clean, please update:"
183-
git diff
184-
false
185-
fi
186-
187186
- name: 'Send comments'
188187
if: failure() && github.event_name == 'pull_request'
189188
run: |

stack/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed under the Apache License, Version 2.0
33
// that can be found in the LICENSE file.
44

5-
//go:generate go get golang.org/x/tools/cmd/stringer
5+
//go:generate go install golang.org/x/tools/cmd/stringer@latest
66
//go:generate stringer -type state
77
//go:generate stringer -type Location
88

0 commit comments

Comments
 (0)