Skip to content

Commit

Permalink
github actions: Overhaul
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
maruel committed Jan 4, 2022
1 parent 3fa27ec commit 19b8520
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 66 deletions.
129 changes: 64 additions & 65 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
gover: ["1.17"]
runs-on: "${{matrix.os}}"
name: "go${{matrix.gover}}.x on ${{matrix.os}}"
env:
PYTHONDONTWRITEBYTECODE: x
steps:
- uses: actions/setup-go@v2
with:
Expand All @@ -51,23 +53,70 @@ jobs:
path: ~/go
key: "${{runner.os}}-gopkg-${{hashFiles('go.sum', '.github/workflows/*.yml')}}"

# Fetch the tools before checking out, so they don't modify go.mod/go.sum.
# Run tests first because it's important.
- name: 'Check: go test -cover'
run: go test -timeout=60s -covermode=count -coverprofile coverage.txt ./...
# Don't send code coverage if anything failed to reduce spam.
- uses: codecov/codecov-action@v2
- name: 'Cleanup'
if: always()
run: rm coverage.txt

# Don't run go test -race if anything failed, to speed up the results.
- name: 'Check: go test -race'
run: go test -timeout=60s -race ./...
- name: 'Check: go test -bench=.'
run: go test -timeout=60s -bench=. -benchtime=100ms -cpu=1 -run NONE ./...

- name: "Check: tree is clean"
if: always()
run: |
# Nothing should have changed in the tree up to that point and no
# unsuspected file was created.
TOUCHED=$(git status --porcelain)
if ! test -z "$TOUCHED"; then
echo "Oops, something touched these files, please cleanup:"
echo "$TOUCHED"
git diff
false
fi
- name: "Check: go generate doesn't modify files"
if: always()
run: |
go generate ./...
TOUCHED=$(git status --porcelain)
if ! test -z "$TOUCHED"; then
echo "go generate created these files, please fix:"
echo "$TOUCHED"
false
fi
- name: "Check: go mod tidy doesn't modify files"
if: always()
run: |
go mod tidy
TOUCHED=$(git status --porcelain)
if ! test -z "$TOUCHED"; then
echo "go mod tidy was not clean, please update:"
git diff
false
fi
# Fetch the tools.
- name: 'go get necessary tools'
run: >
cd ..;
go get -u -v
github.com/gordonklaus/ineffassign
github.com/securego/gosec/cmd/gosec
golang.org/x/lint/golint
golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
honnef.co/go/tools/cmd/staticcheck
if: always()
run: |
go install github.com/gordonklaus/ineffassign@latest
go install github.com/securego/gosec/cmd/gosec@latest
go install golang.org/x/lint/golint@latest
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: 'go get necessary tools (ubuntu)'
if: always() && matrix.os == 'ubuntu-latest'
run: >
cd ..;
go get -u -v
github.com/client9/misspell/cmd/misspell
github.com/google/addlicense
run: |
go install github.com/client9/misspell/cmd/misspell@latest
go install github.com/google/addlicense@latest
# Now run proper checks.
- name: 'Check: go vet'
Expand All @@ -85,7 +134,7 @@ jobs:
run: golint -set_exit_status ./...
- name: 'Check: inefficient variable assignment'
if: always()
run: ineffassign .
run: ineffassign ./...
- name: 'Check: staticcheck'
if: always()
run: staticcheck ./...
Expand Down Expand Up @@ -134,56 +183,6 @@ jobs:
false
fi
# Run tests last since it's potentially the slowest step.
- name: 'Check: go test -cover'
run: go test -timeout=60s -covermode=count -coverprofile coverage.txt ./...
# Don't send code coverage if anything failed to reduce spam.
- uses: codecov/codecov-action@v2
- name: 'Cleanup'
run: rm coverage.txt
# Don't run go test -race if anything failed, to speed up the results.
- name: 'Check: go test -race'
run: go test -timeout=60s -race ./...
- name: 'Check: go test -bench .'
run: go test -timeout=60s -bench . -benchtime=100ms -cpu=1 ./...

- name: "Check: tree is clean"
run: |
# Nothing should have changed in the tree up to that point and no
# unsuspected file was created.
TOUCHED=$(git status --porcelain --ignored)
if ! test -z "$TOUCHED"; then
echo "Oops, something touched these files, please cleanup:"
echo "$TOUCHED"
git diff
false
fi
- name: "Check: go generate doesn't modify files"
run: |
go generate ./...
# TODO(maruel): Due to https://github.com/golang/go/issues/40276, ignore
# go.mod/go.sum modifications. Remove once a new Go toolchain fixes
# this.
git checkout HEAD -- go.mod go.sum
# Also test for untracked files.
TOUCHED=$(git status --porcelain --ignored)
if ! test -z "$TOUCHED"; then
echo "go generate created these files, please fix:"
echo "$TOUCHED"
false
fi
- name: "Check: go mod tidy doesn't modify files"
run: |
go mod tidy
TOUCHED=$(git status --porcelain --ignored)
if ! test -z "$TOUCHED"; then
echo "go mod tidy was not clean, please update:"
git diff
false
fi
- name: 'Send comments'
if: failure() && github.event_name == 'pull_request'
run: |
Expand Down
2 changes: 1 addition & 1 deletion stack/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.

//go:generate go get golang.org/x/tools/cmd/stringer
//go:generate go install golang.org/x/tools/cmd/stringer@latest
//go:generate stringer -type state
//go:generate stringer -type Location

Expand Down

0 comments on commit 19b8520

Please sign in to comment.