-
Notifications
You must be signed in to change notification settings - Fork 0
92 lines (75 loc) · 2.76 KB
/
Copy pathcode-quality.yml
File metadata and controls
92 lines (75 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
name: Code Quality
# This workflow checks code quality: formatting, linting, security, and dependency verification
on:
pull_request:
paths:
- '**.go'
- 'go.mod'
- 'go.sum'
- 'Makefile'
- 'openapi.yaml'
- '.spectral.yaml'
- '.github/workflows/code-quality.yml'
concurrency:
group: code-quality-${{ github.head_ref }}
cancel-in-progress: true
jobs:
code-quality:
name: Code Quality Checks
runs-on: ubuntu-24.04
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Set up Node (for Spectral)
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '24'
- name: Lint OpenAPI spec
run: npx --yes @stoplight/spectral-cli@6 lint openapi.yaml
- name: Set up Go
id: setup-go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: '1.26.4'
- name: Cache Go modules
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install dependencies
run: go mod download
- name: Verify go.mod and go.sum
run: |
go mod verify
go mod tidy
git diff --exit-code go.mod go.sum || (echo "Error: go.mod or go.sum are out of sync. Run 'go mod tidy' and commit the changes." && exit 1)
# Pin tool versions for reproducible builds (must match Makefile)
# Cache key includes Go version so tools are rebuilt when Go upgrades
- name: Cache development tools
id: cache-tools
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
with:
path: |
~/go/bin/golangci-lint
~/go/bin/govulncheck
key: ${{ runner.os }}-go${{ steps.setup-go.outputs.go-version }}-lint2.11.4-vuln1.3.0
- name: Install development tools
if: steps.cache-tools.outputs.cache-hit != 'true'
run: |
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.11.4
go install golang.org/x/vuln/cmd/govulncheck@v1.3.0
- name: Format check (make fmt)
run: |
make fmt
git diff --exit-code . || (echo "Error: code is not formatted. Run 'make fmt' and commit the changes." && exit 1)
- name: Run linter
run: golangci-lint run --timeout 10m ./...
- name: Security scan
run: govulncheck ./...
- name: Verify build
run: go build ./...