go-check.yml 2.64 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 12
    env:
      RUNGOGENERATE: false
web3-bot's avatar
web3-bot committed
13 14
    steps:
      - uses: actions/checkout@v2
web3-bot's avatar
web3-bot committed
15 16
        with:
          submodules: recursive
web3-bot's avatar
web3-bot committed
17 18
      - uses: actions/setup-go@v2
        with:
web3-bot's avatar
web3-bot committed
19
          go-version: "1.18.x"
web3-bot's avatar
web3-bot committed
20 21 22 23 24 25 26 27 28
      - name: Run repo-specific setup
        uses: ./.github/actions/go-check-setup
        if: hashFiles('./.github/actions/go-check-setup') != ''
      - name: Read config
        if: hashFiles('./.github/workflows/go-check-config.json') != ''
        run: |
          if jq -re .gogenerate ./.github/workflows/go-check-config.json; then
            echo "RUNGOGENERATE=true" >> $GITHUB_ENV
          fi
web3-bot's avatar
web3-bot committed
29
      - name: Install staticcheck
web3-bot's avatar
web3-bot committed
30
        run: go install honnef.co/go/tools/cmd/staticcheck@d7e217c1ff411395475b2971c0824e1e7cc1af98 # 2022.1 (v0.3.0)
web3-bot's avatar
web3-bot committed
31
      - name: Check that go.mod is tidy
web3-bot's avatar
web3-bot committed
32
        uses: protocol/multiple-go-modules@v1.2
web3-bot's avatar
web3-bot committed
33 34 35 36 37 38 39 40
        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
41 42 43 44 45 46 47 48
      - name: gofmt
        if: ${{ success() || failure() }} # run this step even if the previous one failed
        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
49 50
      - name: go vet
        if: ${{ success() || failure() }} # run this step even if the previous one failed
web3-bot's avatar
web3-bot committed
51
        uses: protocol/multiple-go-modules@v1.2
web3-bot's avatar
web3-bot committed
52 53
        with:
          run: go vet ./...
web3-bot's avatar
web3-bot committed
54 55
      - name: staticcheck
        if: ${{ success() || failure() }} # run this step even if the previous one failed
web3-bot's avatar
web3-bot committed
56
        uses: protocol/multiple-go-modules@v1.2
web3-bot's avatar
web3-bot committed
57 58 59 60
        with:
          run: |
            set -o pipefail
            staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
web3-bot's avatar
web3-bot committed
61 62 63 64 65 66 67 68 69 70 71 72 73
      - name: go generate
        uses: protocol/multiple-go-modules@v1.2
        if: (success() || failure()) && env.RUNGOGENERATE == 'true'
        with:
          run: |
            git clean -fd # make sure there aren't untracked files / directories
            go generate ./...
            # 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