| 1 | name: Go Check |
| 2 | |
| 3 | on: |
| 4 | workflow_dispatch: |
| 5 | pull_request: |
| 6 | paths-ignore: |
| 7 | - '**/*.md' |
| 8 | push: |
| 9 | branches: |
| 10 | - 'master' |
| 11 | |
| 12 | permissions: |
| 13 | contents: read # to fetch code (actions/checkout) |
| 14 | |
| 15 | concurrency: |
| 16 | group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event_name == 'push' && github.sha || github.ref }} |
| 17 | cancel-in-progress: true |
| 18 | |
| 19 | jobs: |
| 20 | go-check: |
| 21 | if: github.repository == 'ipfs/kubo' || github.event_name == 'workflow_dispatch' |
| 22 | runs-on: ubuntu-latest |
| 23 | timeout-minutes: 10 |
| 24 | steps: |
| 25 | - uses: actions/checkout@v6 |
| 26 | with: |
| 27 | submodules: recursive |
| 28 | - uses: actions/setup-go@v6 |
| 29 | with: |
| 30 | go-version-file: 'go.mod' |
| 31 | - name: Check that go.mod is tidy |
| 32 | uses: protocol/multiple-go-modules@v1.4 |
| 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: go fmt |
| 42 | if: always() # run this step even if the previous one failed |
| 43 | run: | |
| 44 | out=$(go fmt ./...) |
| 45 | if [[ -n "$out" ]]; then |
| 46 | echo "Files are not go-fmt-ed:" |
| 47 | echo "$out" |
| 48 | exit 1 |
| 49 | fi |
| 50 | - name: go fix |
| 51 | if: always() # run this step even if the previous one failed |
| 52 | run: | |
| 53 | go fix ./... |
| 54 | if [[ -n $(git diff --name-only) ]]; then |
| 55 | echo "go fix produced changes. Run 'go fix ./...' locally and commit the result." |
| 56 | git diff |
| 57 | exit 1 |
| 58 | fi |
| 59 | - name: go vet |
| 60 | if: always() # run this step even if the previous one failed |
| 61 | uses: protocol/multiple-go-modules@v1.4 |
| 62 | with: |
| 63 | run: go vet ./... |