|
11 | 11 | branches: |
12 | 12 | - main |
13 | 13 |
|
| 14 | +concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 16 | + cancel-in-progress: true |
| 17 | + |
14 | 18 | permissions: |
15 | 19 | contents: read |
16 | 20 |
|
17 | 21 | jobs: |
18 | | - get-go-version: |
19 | | - runs-on: ubuntu-latest |
20 | | - outputs: |
21 | | - go-version: ${{ steps.get-go-version.outputs.go-version }} |
22 | | - steps: |
23 | | - - name: Checkout Repository |
24 | | - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
25 | | - - name: Get Go Version |
26 | | - id: get-go-version |
27 | | - run: | |
28 | | - echo "Found Go $(cat .go-version)" |
29 | | - echo "go-version=$(cat .go-version)" >> $GITHUB_OUTPUT |
30 | 22 | check-mod-tidy: |
31 | | - needs: |
32 | | - - get-go-version |
33 | 23 | runs-on: ubuntu-latest |
34 | | - name: Go Mod Tidy |
| 24 | + name: Go Mod Tidy Check |
35 | 25 | steps: |
36 | 26 | - name: Checkout Repository |
37 | 27 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
38 | 28 | - name: Setup Go |
39 | 29 | uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 |
40 | 30 | with: |
41 | | - go-version: ${{ needs.get-go-version.outputs.go-version }} |
42 | | - - run: go mod tidy |
| 31 | + go-version-file: go.mod |
| 32 | + cache: true |
| 33 | + - name: Run go mod tidy |
| 34 | + run: go mod tidy |
| 35 | + - name: Verify go.mod/go.sum are tidy |
| 36 | + shell: bash |
| 37 | + run: | |
| 38 | + if ! git diff --exit-code; then |
| 39 | + echo "go.mod/go.sum are not tidy." |
| 40 | + echo "Run: go mod tidy" |
| 41 | + exit 1 |
| 42 | + fi |
| 43 | +
|
43 | 44 | check-lint: |
44 | | - needs: |
45 | | - - get-go-version |
46 | 45 | runs-on: ubuntu-latest |
47 | | - name: Lint Check |
| 46 | + name: Go Lint Check |
48 | 47 | steps: |
49 | 48 | - name: Checkout Repository |
50 | 49 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
51 | 50 | - name: Setup Go |
52 | 51 | uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 |
53 | 52 | with: |
54 | | - go-version: ${{ needs.get-go-version.outputs.go-version }} |
55 | | - - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 |
| 53 | + go-version-file: go.mod |
| 54 | + cache: true |
| 55 | + - name: Run golangci-lint |
| 56 | + uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0 |
56 | 57 | with: |
57 | 58 | version: latest |
58 | 59 | only-new-issues: true |
| 60 | + |
59 | 61 | check-fmt: |
60 | | - needs: |
61 | | - - get-go-version |
62 | 62 | runs-on: ubuntu-latest |
63 | | - name: Gofmt Check |
| 63 | + name: Go Format Check |
64 | 64 | steps: |
65 | 65 | - name: Checkout Repository |
66 | 66 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
67 | 67 | - name: Setup Go |
68 | 68 | uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 |
69 | 69 | with: |
70 | | - go-version: ${{ needs.get-go-version.outputs.go-version }} |
71 | | - - run: | |
72 | | - go fmt ./... |
73 | | - echo "==> Checking that code complies with go fmt requirements..." |
74 | | - git diff --exit-code; if [ $$? -eq 1 ]; then \ |
75 | | - echo "Found files that are not fmt'ed."; \ |
76 | | - echo "You can use the command: \`go fmt ./...\` to reformat code."; \ |
77 | | - exit 1; \ |
| 70 | + go-version-file: go.mod |
| 71 | + cache: true |
| 72 | + - name: Run gofmt |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + files="$(gofmt -l .)" |
| 76 | + if [[ -n "$files" ]]; then |
| 77 | + echo "Found files that are not gofmt'ed:" |
| 78 | + echo "$files" |
| 79 | + echo |
| 80 | + echo "Run: gofmt -w ." |
| 81 | + exit 1 |
78 | 82 | fi |
| 83 | +
|
79 | 84 | check-generate: |
80 | | - needs: |
81 | | - - get-go-version |
82 | 85 | runs-on: ubuntu-latest |
83 | | - name: Generate Check |
| 86 | + name: Go Generate Check |
84 | 87 | steps: |
85 | 88 | - name: Checkout Repository |
86 | 89 | uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
87 | 90 | - name: Setup Go |
88 | 91 | uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5 # v6.2.0 |
89 | 92 | with: |
90 | | - go-version: ${{ needs.get-go-version.outputs.go-version }} |
91 | | - - run: | |
| 93 | + go-version-file: go.mod |
| 94 | + cache: true |
| 95 | + - name: Run make generate |
| 96 | + run: | |
92 | 97 | export PATH=$PATH:$(go env GOPATH)/bin |
93 | 98 | make generate |
94 | 99 | uncommitted="$(git status -s)" |
95 | 100 | if [[ -z "$uncommitted" ]]; then |
96 | 101 | echo "OK" |
97 | 102 | else |
98 | | - echo "Docs have been updated, but the compiled docs have not been committed." |
99 | | - echo "Run 'make generate', and commit the result to resolve this error." |
| 103 | + echo "Generated files have changed but are not committed." |
| 104 | + echo "Run: make generate" |
100 | 105 | echo "Generated but uncommitted files:" |
101 | 106 | echo "$uncommitted" |
102 | 107 | exit 1 |
|
0 commit comments