|
6 | 6 | pull_request: |
7 | 7 | branches: [master] |
8 | 8 |
|
| 9 | +# Cancel superseded runs on a branch so a force-push / amend doesn't waste CI. |
| 10 | +concurrency: |
| 11 | + group: ${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
9 | 17 | jobs: |
| 18 | + verify: |
| 19 | + name: Verify |
| 20 | + runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Set up Go |
| 25 | + uses: actions/setup-go@v5 |
| 26 | + with: |
| 27 | + # Keep in sync with go.mod's `go` directive (currently 1.19). Using |
| 28 | + # stable runs the newest toolchain Go will accept while still |
| 29 | + # exercising the minimum language level declared in go.mod. |
| 30 | + go-version: stable |
| 31 | + check-latest: true |
| 32 | + cache: true |
| 33 | + |
| 34 | + - name: Verify go.mod / go.sum are tidy |
| 35 | + run: | |
| 36 | + go mod tidy |
| 37 | + if ! git diff --quiet go.mod go.sum; then |
| 38 | + echo "::error::go.mod or go.sum is not tidy — run 'go mod tidy' locally and commit." |
| 39 | + git diff go.mod go.sum |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Check gofmt |
| 44 | + run: | |
| 45 | + unformatted=$(gofmt -l .) |
| 46 | + if [ -n "$unformatted" ]; then |
| 47 | + echo "::error::The following files are not gofmt'd:" |
| 48 | + echo "$unformatted" |
| 49 | + exit 1 |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: go vet |
| 53 | + run: go vet ./... |
| 54 | + |
| 55 | + - name: go build |
| 56 | + run: go build ./... |
| 57 | + |
| 58 | + - name: go generate produces no diff |
| 59 | + run: | |
| 60 | + go generate ./... |
| 61 | + if ! git diff --quiet; then |
| 62 | + echo "::error::go generate produced changes — regenerate mocks locally and commit." |
| 63 | + git status |
| 64 | + git diff |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | +
|
| 68 | + lint: |
| 69 | + name: Lint |
| 70 | + runs-on: ubuntu-latest |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v4 |
| 73 | + |
| 74 | + - name: Set up Go |
| 75 | + uses: actions/setup-go@v5 |
| 76 | + with: |
| 77 | + go-version: stable |
| 78 | + check-latest: true |
| 79 | + cache: true |
| 80 | + |
| 81 | + - name: golangci-lint |
| 82 | + uses: golangci/golangci-lint-action@v6 |
| 83 | + with: |
| 84 | + # Pin a recent stable release; bump with intent, not passively. |
| 85 | + version: v1.64.5 |
| 86 | + args: --timeout=5m |
| 87 | + |
10 | 88 | test: |
11 | 89 | name: Test Coverage |
12 | 90 | runs-on: ubuntu-latest |
| 91 | + needs: verify |
13 | 92 | steps: |
14 | | - - name: Set up Go 1.x |
15 | | - uses: actions/setup-go@v3 |
16 | | - with: |
17 | | - go-version: ^1.19 |
| 93 | + - uses: actions/checkout@v4 |
18 | 94 |
|
19 | | - - uses: actions/checkout@v3 |
| 95 | + - name: Set up Go |
| 96 | + uses: actions/setup-go@v5 |
| 97 | + with: |
| 98 | + go-version: stable |
| 99 | + check-latest: true |
| 100 | + cache: true |
20 | 101 |
|
21 | 102 | - name: Install goveralls |
22 | 103 | run: go install github.com/mattn/goveralls@latest |
23 | 104 |
|
24 | | - - name: Lint |
25 | | - uses: golangci/golangci-lint-action@v3 |
26 | | - with: |
27 | | - version: v1.50.1 |
28 | | - |
29 | 105 | - name: Unit Test |
30 | 106 | run: make test |
31 | 107 |
|
|
0 commit comments