-
Notifications
You must be signed in to change notification settings - Fork 0
273 lines (231 loc) · 7.57 KB
/
Copy pathpre-commit.yml
File metadata and controls
273 lines (231 loc) · 7.57 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
name: Pre-commit
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GO_VERSION: '1.25'
jobs:
pre-commit:
name: Pre-commit Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: Cache Python dependencies
uses: actions/cache@v5
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Cache Go modules
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-v2-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-v2-
- name: Cache pre-commit
uses: actions/cache@v5
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pre-commit-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
go mod download
go mod tidy
- name: Run pre-commit
# The maintained composite action embeds actions/cache@v4 and cannot
# select the Go toolchain required by the pinned golangci-lint release.
# Run the tool installed above directly so this release gate is both
# reproducible and on a supported Actions runtime.
env:
GOTOOLCHAIN: auto
run: pre-commit run --show-diff-on-failure --color=always --all-files
security-scan:
name: Security Scan
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: Cache Go modules
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-v2-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-v2-
- name: Install dependencies
run: |
go mod download
go mod tidy
- name: Run Gosec Security Scanner
run: |
go install github.com/securego/gosec/v2/cmd/gosec@latest
# Enforce the scanner's SARIF findings explicitly. This preserves a
# strict gate even when GoSec exits non-zero after a successful scan.
gosec -no-fail -concurrency=1 -exclude=G301,G306,G304,G204,G104,G302 -exclude-dir=examples -exclude-dir=cmd/examples -fmt sarif -out gosec-results.sarif ./...
findings=$(jq '[.runs[].results[]?] | length' gosec-results.sarif)
if [ "$findings" -ne 0 ]; then
jq -r '.runs[].results[]? | [.ruleId, .level, .message.text, .locations[0].physicalLocation.artifactLocation.uri, (.locations[0].physicalLocation.region.startLine // 0)] | @tsv' gosec-results.sarif
exit 1
fi
- name: Upload Gosec SARIF file
if: always()
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: gosec-results.sarif
category: gosec
continue-on-error: true
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
exit-code: '0' # Don't fail on vulnerabilities
skip-dirs: 'examples,cmd/examples'
- name: Upload Trivy SARIF file
uses: github/codeql-action/upload-sarif@v4
with:
sarif_file: trivy-results.sarif
category: trivy
continue-on-error: true
- name: Run detect-secrets
run: |
pip install detect-secrets
# Create baseline if it doesn't exist
if [ ! -f .secrets.baseline ]; then
detect-secrets scan --all-files --baseline .secrets.baseline || true
fi
# Run scan and audit
detect-secrets scan --all-files --baseline .secrets.baseline --update || true
if [ -f .secrets.baseline ]; then
detect-secrets audit .secrets.baseline --report --fail-on-unaudited || echo "Secrets audit completed"
fi
continue-on-error: true
dependency-check:
name: Dependency Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: Cache Go modules
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-v2-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-v2-
- name: Install dependencies
run: |
go mod download
go mod tidy
- name: Check for vulnerabilities
run: |
go install golang.org/x/vuln/cmd/govulncheck@latest
govulncheck ./...
- name: Check for outdated dependencies
run: |
go list -u -m all
- name: Verify dependencies
run: |
go mod verify
code-quality:
name: Code Quality
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: Cache Go modules
uses: actions/cache@v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-v2-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-v2-
- name: Install dependencies
run: |
go mod download
go mod tidy
- name: Install quality tools
run: |
go install github.com/fzipp/gocyclo/cmd/gocyclo@latest
go install github.com/gordonklaus/ineffassign@latest
go install github.com/client9/misspell/cmd/misspell@latest
- name: Check cyclomatic complexity
run: |
gocyclo -over 15 ./pkg/... || echo "High complexity detected"
- name: Check for inefficient assignments
run: |
ineffassign ./pkg/... || echo "Inefficient assignments detected"
- name: Check for misspellings
run: |
misspell -error ./pkg/... ./docs/... ./README.md || echo "Misspellings detected"
- name: Generate quality report
run: |
echo "## Code Quality Report" > quality-report.md
echo "" >> quality-report.md
echo "### Cyclomatic Complexity" >> quality-report.md
gocyclo -avg ./pkg/... >> quality-report.md || true
echo "" >> quality-report.md
echo "### Inefficient Assignments" >> quality-report.md
ineffassign ./pkg/... >> quality-report.md || true
echo "" >> quality-report.md
echo "### Misspellings" >> quality-report.md
misspell ./pkg/... ./docs/... ./README.md >> quality-report.md || true
- name: Upload quality report
uses: actions/upload-artifact@v6
with:
name: code-quality-report
path: quality-report.md
retention-days: 7