go-check.yml 2.45 KB
Newer Older
web3-bot's avatar
web3-bot committed
1 2 3 4
# File managed by web3-bot. DO NOT EDIT.
# See https://github.com/protocol/.github/ for details.

on: [push, pull_request]
web3-bot's avatar
web3-bot committed
5
name: Go Checks
web3-bot's avatar
web3-bot committed
6 7 8 9

jobs:
  unit:
    runs-on: ubuntu-latest
web3-bot's avatar
web3-bot committed
10
    name: All
web3-bot's avatar
web3-bot committed
11
    steps:
web3-bot's avatar
web3-bot committed
12
      - uses: actions/checkout@v3
web3-bot's avatar
web3-bot committed
13 14
        with:
          submodules: recursive
web3-bot's avatar
web3-bot committed
15 16
      - id: config
        uses: protocol/.github/.github/actions/read-config@master
web3-bot's avatar
web3-bot committed
17
      - uses: actions/setup-go@v3
web3-bot's avatar
web3-bot committed
18
        with:
web3-bot's avatar
web3-bot committed
19
          go-version: 1.20.x
web3-bot's avatar
web3-bot committed
20 21 22
      - name: Run repo-specific setup
        uses: ./.github/actions/go-check-setup
        if: hashFiles('./.github/actions/go-check-setup') != ''
web3-bot's avatar
web3-bot committed
23
      - name: Install staticcheck
web3-bot's avatar
web3-bot committed
24
        run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0)
web3-bot's avatar
web3-bot committed
25
      - name: Check that go.mod is tidy
web3-bot's avatar
web3-bot committed
26
        uses: protocol/multiple-go-modules@v1.2
web3-bot's avatar
web3-bot committed
27 28 29 30 31 32 33 34
        with:
          run: |
            go mod tidy
            if [[ -n $(git ls-files --other --exclude-standard --directory -- go.sum) ]]; then
              echo "go.sum was added by go mod tidy"
              exit 1
            fi
            git diff --exit-code -- go.sum go.mod
web3-bot's avatar
web3-bot committed
35
      - name: gofmt
web3-bot's avatar
web3-bot committed
36
        if: success() || failure() # run this step even if the previous one failed
web3-bot's avatar
web3-bot committed
37 38 39 40 41 42
        run: |
          out=$(gofmt -s -l .)
          if [[ -n "$out" ]]; then
            echo $out | awk '{print "::error file=" $0 ",line=0,col=0::File is not gofmt-ed."}'
            exit 1
          fi
web3-bot's avatar
web3-bot committed
43
      - name: go vet
web3-bot's avatar
web3-bot committed
44
        if: success() || failure() # run this step even if the previous one failed
web3-bot's avatar
web3-bot committed
45
        uses: protocol/multiple-go-modules@v1.2
web3-bot's avatar
web3-bot committed
46 47
        with:
          run: go vet ./...
web3-bot's avatar
web3-bot committed
48
      - name: staticcheck
web3-bot's avatar
web3-bot committed
49
        if: success() || failure() # run this step even if the previous one failed
web3-bot's avatar
web3-bot committed
50
        uses: protocol/multiple-go-modules@v1.2
web3-bot's avatar
web3-bot committed
51 52 53 54
        with:
          run: |
            set -o pipefail
            staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
web3-bot's avatar
web3-bot committed
55 56
      - name: go generate
        uses: protocol/multiple-go-modules@v1.2
web3-bot's avatar
web3-bot committed
57
        if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true
web3-bot's avatar
web3-bot committed
58 59 60
        with:
          run: |
            git clean -fd # make sure there aren't untracked files / directories
web3-bot's avatar
web3-bot committed
61
            go generate -x ./...
web3-bot's avatar
web3-bot committed
62 63 64 65 66 67
            # check if go generate modified or added any files
            if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
              echo "go generated caused changes to the repository:"
              git status --short
              exit 1
            fi