gofmt.yml 944 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. name: gofmt
  2. on:
  3. push:
  4. branches:
  5. - master
  6. pull_request:
  7. paths:
  8. - '.github/workflows/gofmt.yml'
  9. - '**.go'
  10. jobs:
  11. gofmt:
  12. name: Run gofmt
  13. runs-on: ubuntu-latest
  14. steps:
  15. - name: Set up Go 1.20
  16. uses: actions/setup-go@v2
  17. with:
  18. go-version: "1.20"
  19. id: go
  20. - name: Check out code into the Go module directory
  21. uses: actions/checkout@v2
  22. - uses: actions/cache@v2
  23. with:
  24. path: ~/go/pkg/mod
  25. key: ${{ runner.os }}-gofmt1.20-${{ hashFiles('**/go.sum') }}
  26. restore-keys: |
  27. ${{ runner.os }}-gofmt1.20-
  28. - name: Install goimports
  29. run: |
  30. go install golang.org/x/tools/cmd/goimports@latest
  31. - name: gofmt
  32. run: |
  33. if [ "$(find . -iname '*.go' | grep -v '\.pb\.go$' | xargs goimports -l)" ]
  34. then
  35. find . -iname '*.go' | grep -v '\.pb\.go$' | xargs goimports -d
  36. exit 1
  37. fi