From 19b8520ee02c16953e740b75043753613bf5cb7f Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ruel Date: Mon, 3 Jan 2022 20:52:32 -0500 Subject: [PATCH] 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. --- .github/workflows/test.yml | 129 ++++++++++++++++++------------------- stack/context.go | 2 +- 2 files changed, 65 insertions(+), 66 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07671ea..eecfa2d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: @@ -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' @@ -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 ./... @@ -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: | diff --git a/stack/context.go b/stack/context.go index e010da2..8b92e05 100644 --- a/stack/context.go +++ b/stack/context.go @@ -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