-
Notifications
You must be signed in to change notification settings - Fork 0
244 lines (231 loc) · 8.95 KB
/
Copy pathci.yml
File metadata and controls
244 lines (231 loc) · 8.95 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
# Canonical CI workflow for hawk-eco Go repos.
# Source of truth: .shared-templates/workflows/go-ci.yml.tmpl
#
# Two deployment models:
#
# 1. NOW — render this template inline into each repo's
# .github/workflows/ci.yml. Every repo has identical content.
#
# 2. LATER — once GrayCodeAI/.github exists as a central repo, move this
# file to GrayCodeAI/.github/.github/workflows/go-ci.yml with
# `on: workflow_call:`. Each repo's ci.yml becomes a 5-line caller:
#
# name: CI
# on: { push: { branches: [main] }, pull_request: }
# jobs:
# ci:
# uses: GrayCodeAI/.github/.github/workflows/go-ci.yml@main
name: CI
on:
push:
branches: [main, dev]
pull_request:
branches: [main, dev]
permissions:
contents: read
concurrency:
group: ci-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
GO_VERSION: "1.26.4"
GOPRIVATE: "github.com/GrayCodeAI/*"
GONOSUMDB: "github.com/GrayCodeAI/*"
GONOSUMCHECK: "1"
jobs:
# -------------------------------------------------------------------------
# Format + vet — fastest, fail fast.
# -------------------------------------------------------------------------
fmt-vet:
name: fmt + vet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Clone tok (workspace dep)
run: git clone --depth=1 https://github.com/GrayCodeAI/tok.git ../tok
- name: Boundary guard
run: bash ./scripts/check-ecosystem-boundaries.sh
- name: gofumpt diff
run: |
go install mvdan.cc/gofumpt@v0.10.0
out=$(gofumpt -l .)
if [ -n "$out" ]; then
echo "::error::gofumpt would reformat the following files:"
echo "$out"
exit 1
fi
- name: go vet
run: go vet ./...
# -------------------------------------------------------------------------
# Lint — golangci-lint covers most static checks.
# -------------------------------------------------------------------------
lint:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Clone tok (workspace dep)
run: git clone --depth=1 https://github.com/GrayCodeAI/tok.git ../tok
- name: Boundary guard
run: bash ./scripts/check-ecosystem-boundaries.sh
- uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v7.0.0
with:
version: v2.1.0
install-mode: goinstall
verify: false
args: --timeout=5m
# -------------------------------------------------------------------------
# Tests with race detector + coverage upload.
# -------------------------------------------------------------------------
test:
name: test (race + cover)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Clone tok (workspace dep)
run: git clone --depth=1 https://github.com/GrayCodeAI/tok.git ../tok
- name: Boundary guard
run: bash ./scripts/check-ecosystem-boundaries.sh
- name: Tidy check
run: |
go mod tidy
if ! git diff --quiet; then
echo "::error::go.mod / go.sum out of date — run 'go mod tidy' and commit"
git diff
exit 1
fi
- name: Test
run: go test ./... -race -count=1 -shuffle=on -coverprofile=coverage.out -covermode=atomic -timeout=180s
- name: Coverage summary
run: go tool cover -func=coverage.out | tail -1
- name: Coverage threshold
run: |
COVERAGE=$(go tool cover -func=coverage.out | tail -1 | grep -oE '[0-9]+\.[0-9]+' || echo "0")
THRESHOLD=49
if [ "$(echo "$COVERAGE < $THRESHOLD" | bc -l)" -eq 1 ]; then
echo "::error::Coverage ${COVERAGE}% is below threshold ${THRESHOLD}%"
exit 1
fi
echo "Coverage ${COVERAGE}% meets threshold ${THRESHOLD}%"
- name: Upload coverage
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: coverage
path: coverage.out
# -------------------------------------------------------------------------
# Security scan — vulnerability database + (optional) gosec.
# -------------------------------------------------------------------------
security:
name: security
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Clone tok (workspace dep)
run: git clone --depth=1 https://github.com/GrayCodeAI/tok.git ../tok
- name: govulncheck
run: |
go install golang.org/x/vuln/cmd/govulncheck@v1.1.4
govulncheck ./...
- name: gosec (advisory)
continue-on-error: true
run: |
go install github.com/securego/gosec/v2/cmd/gosec@v2.22.4
gosec -exclude=G104,G301,G302,G304,G306 ./...
# -------------------------------------------------------------------------
# Dead code detection.
# -------------------------------------------------------------------------
deadcode:
name: deadcode
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Clone tok (workspace dep)
run: git clone --depth=1 https://github.com/GrayCodeAI/tok.git ../tok
- name: deadcode
run: |
go install golang.org/x/tools/cmd/deadcode@v0.30.0
deadcode ./... 2>&1 | head -50
# -------------------------------------------------------------------------
# Duplication detection — jscpd.
# -------------------------------------------------------------------------
jscpd:
name: duplication
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: jscpd
run: |
npx jscpd --min-lines 5 --min-tokens 50 --reporters console --blame . 2>&1 | head -50
# -------------------------------------------------------------------------
# Fuzz — short corpus runs to catch panics in fuzz targets.
# -------------------------------------------------------------------------
fuzz:
name: fuzz (60s)
runs-on: ubuntu-latest
needs: [test]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Clone tok (workspace dep)
run: git clone --depth=1 https://github.com/GrayCodeAI/tok.git ../tok
- name: Run fuzz targets
run: |
go test -fuzz=FuzzContentHash -fuzztime=60s ./engine/... || true
go test -fuzz=FuzzExtractEntities -fuzztime=60s ./engine/... || true
go test -fuzz=FuzzRecallOpts -fuzztime=60s ./engine/... || true
# -------------------------------------------------------------------------
# Cross-platform build matrix — only for repos that produce a binary.
# Repos that are pure libraries can keep this job (it'll just `go build ./...`)
# or remove it locally.
# -------------------------------------------------------------------------
build:
name: build (${{ matrix.goos }}/${{ matrix.goarch }})
runs-on: ubuntu-latest
needs: [fmt-vet, lint, test]
strategy:
fail-fast: false
matrix:
goos: [linux, darwin, windows]
goarch: [amd64, arm64]
exclude:
- goos: windows
goarch: arm64
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Clone tok (workspace dep)
run: git clone --depth=1 https://github.com/GrayCodeAI/tok.git ../tok
- name: Build
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: "0"
run: go build ./...