-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
448 lines (390 loc) · 13.4 KB
/
Copy pathTaskfile.yaml
File metadata and controls
448 lines (390 loc) · 13.4 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# Copyright 2025 The meowg1k Authors
# SPDX-License-Identifier: Apache-2.0
version: "3"
vars:
PROJECT_NAME: meowg1k
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo "v0.1.0"
LDFLAGS: >
-s -w
-X github.com/retran/meowg1k/internal/version.Version={{.VERSION}}
-X github.com/retran/meowg1k/internal/version.BuildDate=$(date -u '+%Y-%m-%d_%H:%M:%S')
-X github.com/retran/meowg1k/internal/version.GitCommit=$(git rev-parse --short HEAD 2>/dev/null || echo 'unknown')
GOFLAGS: -trimpath -buildvcs=false
COVERAGE_THRESHOLD: 65.0
# Colors
GREEN: \033[0;32m
BLUE: \033[0;34m
NC: \033[0m
tasks:
deps:install:
desc: Download and tidy Go modules
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Downloading dependencies...\n"
- go mod download
- go mod tidy
- |
printf "{{.GREEN}}[DONE]{{.NC}} Dependencies installed.\n"
check:all:
desc: Run all checks (lint, test, security)
cmds:
- task: check:lint
- task: check:test
- task: check:security
check:lint:
desc: Run golangci-lint
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running linters...\n"
- golangci-lint run --timeout=5m
check:test:
desc: Run tests with coverage
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running tests...\n"
- go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
- task: internal:coverage-check
check:security:
desc: Run security checks (gosec, govulncheck)
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running security scans...\n"
- go run github.com/securego/gosec/v2/cmd/gosec@latest ./...
- go run golang.org/x/vuln/cmd/govulncheck@latest ./...
fix:fmt:
desc: Format code (gofumpt, goimports)
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Formatting code...\n"
- golangci-lint fmt
- go fmt ./...
fix:lint:
desc: Auto-fix lint issues
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Fixing lint issues...\n"
- golangci-lint run --fix --timeout=5m
build:
desc: Build the binary
deps: [clean]
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Building {{.PROJECT_NAME}}...\n"
- mkdir -p bin
- CGO_ENABLED=0 GOFLAGS="{{.GOFLAGS}}" go build -ldflags "{{.LDFLAGS}}" -o "bin/meow" ./cmd/meow
- |
printf "{{.GREEN}}[DONE]{{.NC}} Binary built at bin/meow\n"
install:
desc: Install binary to GOBIN
cmds:
- |
BIN_DIR="$(go env GOBIN)"; [ -z "$BIN_DIR" ] && BIN_DIR="$(go env GOPATH)/bin"
printf "{{.BLUE}}[INFO]{{.NC}} Installing to $BIN_DIR...\n"
CGO_ENABLED=0 GOFLAGS="{{.GOFLAGS}}" go build -ldflags "{{.LDFLAGS}}" -o "$BIN_DIR/meow" ./cmd/meow
release:
desc: Release via GoReleaser
cmds:
- goreleaser release --clean
release:snapshot:
desc: Build snapshot release
cmds:
- goreleaser release --snapshot --clean
clean:
desc: Clean artifacts
cmds:
- rm -rf bin coverage.out coverage.html dist
# ============================================================
# Development Tasks
# ============================================================
dev:setup:
desc: Install all development dependencies
cmds:
- task: deps:install
- task: tools:install
- task: hooks:install
- |
printf "{{.GREEN}}[DONE]{{.NC}} Development environment setup complete.\n"
dev:run:
desc: Run meow with sample configuration
deps: [build]
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running meow...\n"
- ./bin/meow --help
dev:watch:
desc: Auto-rebuild on file changes (requires entr)
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Watching for changes... (Press Ctrl+C to stop)\n"
find . -name '*.go' | entr -c task build
dev:debug:
desc: Build with debug flags and run with dlv debugger
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Building debug binary...\n"
- go build -gcflags="all=-N -l" -o bin/meow-debug ./cmd/meow
- |
printf "{{.GREEN}}[INFO]{{.NC}} Starting debugger (use 'help' for commands)...\n"
- dlv exec ./bin/meow-debug
dev:profile:
desc: Run with CPU and memory profiling enabled
deps: [build]
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running with profiling...\n"
mkdir -p profiles
- ./bin/meow --cpuprofile=profiles/cpu.prof --memprofile=profiles/mem.prof
- |
printf "{{.GREEN}}[DONE]{{.NC}} Profiles saved to profiles/\n"
# ============================================================
# Testing Tasks
# ============================================================
test:unit:
desc: Run unit tests only
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running unit tests...\n"
- go test -v -short ./...
test:integration:
desc: Run integration tests
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running integration tests...\n"
- go test -v -run Integration ./...
test:watch:
desc: Run tests in watch mode (requires entr)
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Watching for test changes...\n"
find . -name '*.go' | entr -c go test ./...
test:race:
desc: Run tests with race detector
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running tests with race detector...\n"
- go test -race ./...
test:msan:
desc: Run tests with memory sanitizer (Linux only, requires clang)
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running tests with memory sanitizer...\n"
- CC=clang go test -msan ./...
test:verbose:
desc: Run tests with verbose output
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running tests (verbose)...\n"
- go test -v -count=1 ./...
# ============================================================
# Coverage Tasks
# ============================================================
coverage:html:
desc: Generate HTML coverage report
deps: [check:test]
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Generating HTML coverage report...\n"
- go tool cover -html=coverage.out -o coverage.html
- |
printf "{{.GREEN}}[DONE]{{.NC}} Coverage report: coverage.html\n"
coverage:func:
desc: Show function-level coverage
deps: [check:test]
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Function coverage:\n"
- go tool cover -func=coverage.out
coverage:badge:
desc: Generate coverage badge data
deps: [check:test]
cmds:
- |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}')
COLOR="red"
if (( $(echo "$COVERAGE > 80.0" | bc -l) )); then COLOR="green"; fi
if (( $(echo "$COVERAGE > 60.0" | bc -l) )) && (( $(echo "$COVERAGE <= 80.0" | bc -l) )); then COLOR="yellow"; fi
printf "{{.GREEN}}[INFO]{{.NC}} Coverage: $COVERAGE (Color: $COLOR)\n"
# ============================================================
# Linting Tasks
# ============================================================
lint:fast:
desc: Quick lint with essential linters only
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running fast lint...\n"
- golangci-lint fmt --diff
- golangci-lint run --enable-only=govet,errcheck,staticcheck --timeout=2m
lint:full:
desc: Run all configured linters
cmds:
- task: check:lint
lint:fix:
desc: Auto-fix linting issues
cmds:
- task: fix:lint
lint:new:
desc: Lint only new/changed code
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Linting new code...\n"
- golangci-lint run --new-from-rev=HEAD~1 --timeout=5m
# ============================================================
# Benchmarking Tasks
# ============================================================
bench:
desc: Run benchmarks
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running benchmarks...\n"
mkdir -p bench
- go test -bench=. -benchmem -run=^$ ./... | tee bench/current.txt
bench:compare:
desc: Compare benchmarks with baseline
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Comparing with baseline...\n"
if [ ! -f bench/baseline.txt ]; then
echo "No baseline found. Run 'task bench' to create one."
exit 1
fi
- go test -bench=. -benchmem -run=^$ ./... | tee bench/current.txt
- |
printf "{{.BLUE}}[INFO]{{.NC}} Comparison:\n"
go run golang.org/x/perf/cmd/benchstat@latest bench/baseline.txt bench/current.txt
bench:profile:
desc: Run benchmarks with CPU profiling
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Running benchmarks with profiling...\n"
mkdir -p profiles
- go test -bench=. -benchmem -cpuprofile=profiles/bench-cpu.prof -memprofile=profiles/bench-mem.prof -run=^$ ./...
# ============================================================
# Profiling Tasks
# ============================================================
profile:cpu:
desc: Generate CPU profile and analyze
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Starting CPU profiling...\n"
mkdir -p profiles
- go test -cpuprofile=profiles/cpu.prof -bench=. ./...
- |
printf "{{.GREEN}}[INFO]{{.NC}} Opening profile with pprof...\n"
- go tool pprof -http=:8080 profiles/cpu.prof
profile:mem:
desc: Generate memory profile and analyze
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Starting memory profiling...\n"
mkdir -p profiles
- go test -memprofile=profiles/mem.prof -bench=. ./...
- |
printf "{{.GREEN}}[INFO]{{.NC}} Opening profile with pprof...\n"
- go tool pprof -http=:8080 profiles/mem.prof
profile:trace:
desc: Generate execution trace
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Generating execution trace...\n"
mkdir -p profiles
- go test -trace=profiles/trace.out ./...
- |
printf "{{.GREEN}}[INFO]{{.NC}} Opening trace viewer...\n"
- go tool trace profiles/trace.out
# ============================================================
# CI Tasks
# ============================================================
ci:local:
desc: Run full CI pipeline locally
cmds:
- task: deps:install
- task: check:lint
- task: check:test
- task: check:security
- task: build
- |
printf "{{.GREEN}}[DONE]{{.NC}} CI pipeline complete!\n"
ci:pre-commit:
desc: Run pre-commit checks
cmds:
- task: fix:fmt
- task: lint:fast
- task: test:unit
ci:pre-push:
desc: Run pre-push checks
cmds:
- task: check:lint
- task: check:test
- task: build
# ============================================================
# Tools Tasks
# ============================================================
tools:install:
desc: Install development tools
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Installing development tools...\n"
- go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
- go install github.com/securego/gosec/v2/cmd/gosec@latest
- go install golang.org/x/vuln/cmd/govulncheck@latest
- go install golang.org/x/perf/cmd/benchstat@latest
- go install github.com/go-delve/delve/cmd/dlv@latest
- |
printf "{{.GREEN}}[DONE]{{.NC}} Development tools installed.\n"
tools:update:
desc: Update development tools
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Updating development tools...\n"
- task: tools:install
hooks:install:
desc: Install git hooks
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Installing git hooks...\n"
if command -v pre-commit >/dev/null 2>&1; then
pre-commit install
printf "{{.GREEN}}[DONE]{{.NC}} Git hooks installed.\n"
else
printf "{{.BLUE}}[INFO]{{.NC}} pre-commit not found. Install with: pip install pre-commit\n"
fi
# ============================================================
# Release Tasks
# ============================================================
release:prepare:
desc: Prepare release (run checks, build, test)
cmds:
- task: clean
- task: deps:install
- task: ci:local
- |
printf "{{.GREEN}}[DONE]{{.NC}} Release preparation complete.\n"
printf "{{.BLUE}}[INFO]{{.NC}} Ready to tag and release.\n"
release:tag:
desc: Create and push a new release tag
cmds:
- |
printf "{{.BLUE}}[INFO]{{.NC}} Current version: {{.VERSION}}\n"
read -p "Enter new version (e.g., v2.0.0): " VERSION
git tag -a "$VERSION" -m "Release $VERSION"
git push origin "$VERSION"
printf "{{.GREEN}}[DONE]{{.NC}} Tag $VERSION created and pushed.\n"
release:publish:
desc: Publish release via GoReleaser
cmds:
- task: release
# ============================================================
# Internal Tasks
# ============================================================
internal:coverage-check:
internal: true
silent: true
cmds:
- |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | sed 's/%//')
echo "Coverage: ${COVERAGE}% (Threshold: {{.COVERAGE_THRESHOLD}}%)"
if (( $(echo "$COVERAGE < {{.COVERAGE_THRESHOLD}}" | bc -l) )); then
echo "FAIL: Coverage below threshold"
exit 1
fi