-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskfile.yml
More file actions
301 lines (278 loc) · 8.25 KB
/
Copy pathTaskfile.yml
File metadata and controls
301 lines (278 loc) · 8.25 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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
version: '3'
vars:
PROJECT_ROOT:
sh: pwd
GOBIN: '{{.PROJECT_ROOT}}/bin'
GOLANGCI_LINT_LOCAL_BINARY: '{{.GOBIN}}/golangci-lint'
REQUIRED_GOLANGCI_LINT_VERSION:
sh: cat .golangci.version 2>/dev/null || echo "2.12.2"
GOLANGCI_LINT_BINARY:
sh: |
required="$(cat .golangci.version 2>/dev/null || echo "2.12.2")"
for candidate in "$(command -v golangci-lint 2>/dev/null || true)" "{{.GOLANGCI_LINT_LOCAL_BINARY}}"; do
[ -n "$candidate" ] || continue
[ -x "$candidate" ] || continue
version="$("$candidate" version --format short 2>/dev/null || "$candidate" version --short 2>/dev/null || true)"
if [ "$version" = "$required" ]; then
echo "$candidate"
exit 0
fi
done
echo "{{.GOLANGCI_LINT_LOCAL_BINARY}}"
GOLANGCI_LINT_VERSION:
sh: |
{{.GOLANGCI_LINT_BINARY}} version --format short 2>/dev/null ||
{{.GOLANGCI_LINT_BINARY}} version --short 2>/dev/null ||
echo "not-installed"
env:
GOBIN: '{{.GOBIN}}'
tasks:
default:
desc: Run lint and test
cmds:
- task: lint
- task: test
help:
desc: Show this help message
cmds:
- echo "GoZod - TypeScript Zod v4-inspired validation library for Go"
- echo "Available targets:"
- task --list
silent: true
clean:
desc: Clean build artifacts and caches
cmds:
- echo "Cleaning build artifacts..."
- rm -rf {{.GOBIN}}
- go clean -cache -testcache || true
deps:
desc: Download Go module dependencies
cmds:
- echo "Downloading dependencies..."
- go mod download
- go mod tidy
deps:update:
desc: Update dependencies for the root module and any nested modules
cmds:
- |
set -e
echo "Updating dependencies..."
MODULES=". $(find . -mindepth 2 -name go.mod \
-not -path '*/vendor/*' -not -path '*/.*' \
-exec dirname {} \; | sort)"
for dir in $MODULES; do
echo "==> $dir"
(
cd "$dir"
replaced=$(awk '
/^replace[[:space:]]+[^(]/ { print $2 }
/^replace[[:space:]]*\(/ { f=1; next }
f && /^\)/ { f=0; next }
f && /=>/ { print $1 }
' go.mod)
deps=$(awk '
/^require[[:space:]]+[^(]/ { print $2 }
/^require[[:space:]]*\(/ { f=1; next }
f && /^\)/ { f=0; next }
f && !/\/\/ indirect/ && NF >= 2 { print $1 }
' go.mod | while read -r dep; do
echo "$replaced" | grep -qxF "$dep" || echo "$dep"
done | tr '\n' ' ')
if [ -n "$deps" ]; then
go get -u $deps
fi
go mod tidy
)
done
if [ -f go.work ]; then
echo "==> go work sync"
go work sync
fi
test:
desc: Run all tests
cmds:
- echo "Running all tests..."
- |
go test -race -count=1 ./... &
pid=$!
(
while kill -0 "$pid" 2>/dev/null; do
echo "[test] go test still running..."
sleep 30
done
) &
heartbeat=$!
if wait "$pid"; then
status=0
else
status=$?
fi
kill "$heartbeat" 2>/dev/null || true
wait "$heartbeat" 2>/dev/null || true
exit "$status"
test:race:
desc: Run race-enabled tests for the lightweight utility packages
cmds:
- echo "Running race tests for lightweight packages..."
- |
go test -race -count=1 ./core ./pkg/cloneutil ./pkg/regex ./pkg/slicex ./pkg/structx &
pid=$!
(
while kill -0 "$pid" 2>/dev/null; do
echo "[test:race] go test still running..."
sleep 30
done
) &
heartbeat=$!
if wait "$pid"; then
status=0
else
status=$?
fi
kill "$heartbeat" 2>/dev/null || true
wait "$heartbeat" 2>/dev/null || true
exit "$status"
lint:
desc: Run all linters
deps:
- golangci-lint
- tidy-lint
contractcheck:
desc: Run compile-time schema contract checks
cmds:
- go test -tags=contractcheck ./types
docs:integrity:
desc: Run documentation integrity checks
cmds:
- go test . -run 'TestDocumentationDoesNotUseStalePublicLanguage|TestDocumentationJSONSchemaRegistryExampleCompiles|Example(PrettifyError|String_parseContext|ToJSONSchema.*)'
- go test ./examples/code_generation -run '^ExampleUser_Schema$'
bench:smoke:
desc: Compile and smoke-run benchmarks without enforcing performance numbers
cmds:
- go test -run '^$' -bench=. -benchtime=1x ./...
install-golangci-lint:
desc: Install golangci-lint with the required version
cmds:
- mkdir -p "{{.GOBIN}}"
- |
if [ "{{.GOLANGCI_LINT_VERSION}}" != "{{.REQUIRED_GOLANGCI_LINT_VERSION}}" ]; then
echo "Installing golangci-lint v{{.REQUIRED_GOLANGCI_LINT_VERSION}}..."
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
| sh -s -- -b "{{.GOBIN}}" v{{.REQUIRED_GOLANGCI_LINT_VERSION}}
echo "golangci-lint v{{.REQUIRED_GOLANGCI_LINT_VERSION}} installed successfully"
fi
status:
- test "{{.GOLANGCI_LINT_VERSION}}" = "{{.REQUIRED_GOLANGCI_LINT_VERSION}}"
golangci-lint:
desc: Run golangci-lint
deps:
- install-golangci-lint
cmds:
- '{{.GOLANGCI_LINT_BINARY}} version'
- echo "Running golangci-lint..."
- '{{.GOLANGCI_LINT_BINARY}} run --timeout=30m --concurrency=1 --path-prefix=.'
tidy-lint:
desc: Check if go.mod and go.sum are tidy
cmds:
- echo "Checking go.mod and go.sum are tidy..."
- |
tmpdir="$(mktemp -d)"
trap 'rm -rf "$tmpdir"' EXIT
cp go.mod "$tmpdir/go.mod"
if [ -f go.sum ]; then
cp go.sum "$tmpdir/go.sum"
else
: > "$tmpdir/go.sum"
fi
go mod tidy
status=0
cmp -s go.mod "$tmpdir/go.mod" || status=1
if [ -f go.sum ]; then
cmp -s go.sum "$tmpdir/go.sum" || status=1
else
[ ! -s "$tmpdir/go.sum" ] || status=1
fi
if [ "$status" -ne 0 ]; then
echo "go mod tidy changed go.mod or go.sum"
diff -u "$tmpdir/go.mod" go.mod || true
if [ -f go.sum ] || [ -s "$tmpdir/go.sum" ]; then
diff -u "$tmpdir/go.sum" go.sum || true
fi
exit 1
fi
yamllint:
desc: Run yamllint
cmds:
- yamllint -s .
vuln:
desc: Run govulncheck
cmds:
- |
govulncheck ./... &
pid=$!
(
while kill -0 "$pid" 2>/dev/null; do
echo "[vuln] govulncheck still running..."
sleep 30
done
) &
heartbeat=$!
if wait "$pid"; then
status=0
else
status=$?
fi
kill "$heartbeat" 2>/dev/null || true
wait "$heartbeat" 2>/dev/null || true
exit "$status"
fmt:
desc: Format Go code
deps:
- install-golangci-lint
cmds:
- echo "Formatting Go code..."
- '{{.GOLANGCI_LINT_BINARY}} fmt ./...'
vet:
desc: Run go vet
cmds:
- echo "Running go vet..."
- |
go vet ./... &
pid=$!
(
while kill -0 "$pid" 2>/dev/null; do
echo "[vet] go vet still running..."
sleep 30
done
) &
heartbeat=$!
if wait "$pid"; then
status=0
else
status=$?
fi
kill "$heartbeat" 2>/dev/null || true
wait "$heartbeat" 2>/dev/null || true
exit "$status"
verify:
desc: Run all verification steps (deps, format, vet, lint, contracts, docs, tests, benchmark smoke, vuln)
cmds:
- task: deps
- task: fmt
- task: vet
- task: lint
- task: contractcheck
- task: docs:integrity
- task: test
- task: bench:smoke
- task: vuln
- echo "All verification steps completed successfully ✅"
verify:ci:
desc: Run the same quality gates expected by CI
cmds:
- task: lint
- task: contractcheck
- task: docs:integrity
- task: test
- task: bench:smoke
- task: vuln