|
| 1 | +# File managed by web3-bot. DO NOT EDIT. |
| 2 | +# See https://github.com/protocol/.github/ for details. |
| 3 | + |
| 4 | +on: [push, pull_request] |
| 5 | +name: Go Checks |
| 6 | + |
| 7 | +jobs: |
| 8 | + unit: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + name: All |
| 11 | + env: |
| 12 | + RUNGOGENERATE: false |
| 13 | + steps: |
| 14 | + - uses: actions/checkout@v2 |
| 15 | + with: |
| 16 | + submodules: recursive |
| 17 | + - uses: actions/setup-go@v2 |
| 18 | + with: |
| 19 | + go-version: "1.17.x" |
| 20 | + - name: Run repo-specific setup |
| 21 | + uses: ./.github/actions/go-check-setup |
| 22 | + if: hashFiles('./.github/actions/go-check-setup') != '' |
| 23 | + - name: Read config |
| 24 | + if: hashFiles('./.github/workflows/go-check-config.json') != '' |
| 25 | + run: | |
| 26 | + if jq -re .gogenerate ./.github/workflows/go-check-config.json; then |
| 27 | + echo "RUNGOGENERATE=true" >> $GITHUB_ENV |
| 28 | + fi |
| 29 | + - name: Install staticcheck |
| 30 | + run: go install honnef.co/go/tools/cmd/staticcheck@df71e5d0e0ed317ebf43e6e59cf919430fa4b8f2 # 2021.1.1 (v0.2.1) |
| 31 | + - name: Check that go.mod is tidy |
| 32 | + |
| 33 | + with: |
| 34 | + run: | |
| 35 | + go mod tidy |
| 36 | + if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then |
| 37 | + echo "go.sum was added by go mod tidy" |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | + git diff --exit-code -- go.sum go.mod |
| 41 | + - name: gofmt |
| 42 | + if: ${{ success() || failure() }} # run this step even if the previous one failed |
| 43 | + run: | |
| 44 | + out=$(gofmt -s -l .) |
| 45 | + if [[ -n "$out" ]]; then |
| 46 | + echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}' |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + - name: go vet |
| 50 | + if: ${{ success() || failure() }} # run this step even if the previous one failed |
| 51 | + |
| 52 | + with: |
| 53 | + run: go vet ./... |
| 54 | + - name: staticcheck |
| 55 | + if: ${{ success() || failure() }} # run this step even if the previous one failed |
| 56 | + |
| 57 | + with: |
| 58 | + run: | |
| 59 | + set -o pipefail |
| 60 | + staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g' |
| 61 | + - name: go generate |
| 62 | + |
| 63 | + if: (success() || failure()) && env.RUNGOGENERATE == 'true' |
| 64 | + with: |
| 65 | + run: | |
| 66 | + git clean -fd # make sure there aren't untracked files / directories |
| 67 | + go generate ./... |
| 68 | + # check if go generate modified or added any files |
| 69 | + if ! $(git add . && git diff-index HEAD --exit-code --quiet); then |
| 70 | + echo "go generated caused changes to the repository:" |
| 71 | + git status --short |
| 72 | + exit 1 |
| 73 | + fi |
| 74 | +
|
0 commit comments