-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathTaskfile.yml
More file actions
471 lines (421 loc) · 14.4 KB
/
Taskfile.yml
File metadata and controls
471 lines (421 loc) · 14.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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
# https://taskfile.dev
version: '3'
vars:
BINARY_NAME: gosqlx
BUILD_DIR: build
COVERAGE_FILE: coverage.out
COVERAGE_HTML: coverage.html
GO_PACKAGES:
sh: go list ./...
GO_FILES:
sh: find . -type f -name '*.go' -not -path './vendor/*'
env:
CGO_ENABLED: '0'
tasks:
# =============================================================================
# DEFAULT
# =============================================================================
default:
desc: Show available tasks
cmds:
- task --list-all
# =============================================================================
# BUILD TASKS
# =============================================================================
build:
desc: Build all packages
cmds:
- echo "Building packages..."
- go build -v ./...
build:cli:
desc: Build the CLI binary
cmds:
- echo "Building CLI binary..."
- go build -v -o {{.BUILD_DIR}}/{{.BINARY_NAME}} ./cmd/gosqlx
generates:
- '{{.BUILD_DIR}}/{{.BINARY_NAME}}'
build:cli:all:
desc: Build CLI for all platforms (linux, darwin, windows)
cmds:
- echo "Building for Linux amd64..."
- GOOS=linux GOARCH=amd64 go build -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-amd64 ./cmd/gosqlx
- echo "Building for Linux arm64..."
- GOOS=linux GOARCH=arm64 go build -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-arm64 ./cmd/gosqlx
- echo "Building for macOS amd64..."
- GOOS=darwin GOARCH=amd64 go build -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-amd64 ./cmd/gosqlx
- echo "Building for macOS arm64..."
- GOOS=darwin GOARCH=arm64 go build -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-arm64 ./cmd/gosqlx
- echo "Building for Windows amd64..."
- GOOS=windows GOARCH=amd64 go build -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-windows-amd64.exe ./cmd/gosqlx
install:
desc: Install the CLI globally
cmds:
- echo "Installing gosqlx CLI..."
- go install ./cmd/gosqlx
# =============================================================================
# TEST TASKS
# =============================================================================
test:
desc: Run all tests
cmds:
- echo "Running tests..."
- go test -v ./...
test:short:
desc: Run tests in short mode
cmds:
- echo "Running short tests..."
- go test -short ./...
test:race:
desc: Run tests with race detection (CRITICAL for production)
cmds:
- echo "Running tests with race detection..."
- go test -race -timeout 60s ./...
test:pkg:
desc: Run tests for a specific package (use PKG=./pkg/sql/parser)
cmds:
- echo "Running tests for {{.PKG}}..."
- go test -v -race {{.PKG}}
vars:
PKG: '{{default "./..." .PKG}}'
# =============================================================================
# COVERAGE TASKS
# =============================================================================
coverage:
desc: Generate test coverage report
cmds:
- echo "Running tests with coverage..."
- go test -cover -coverprofile={{.COVERAGE_FILE}} ./...
- go tool cover -html={{.COVERAGE_FILE}} -o {{.COVERAGE_HTML}}
- echo "Coverage report generated at {{.COVERAGE_HTML}}"
generates:
- '{{.COVERAGE_FILE}}'
- '{{.COVERAGE_HTML}}'
coverage:func:
desc: Show coverage by function
deps: [coverage]
cmds:
- go tool cover -func={{.COVERAGE_FILE}}
coverage:pkg:
desc: Generate coverage for specific package (use PKG=./pkg/models)
cmds:
- go test -coverprofile={{.COVERAGE_FILE}} {{.PKG}}
- go tool cover -func={{.COVERAGE_FILE}}
vars:
PKG: '{{default "./pkg/models" .PKG}}'
# =============================================================================
# BENCHMARK TASKS
# =============================================================================
bench:
desc: Run all benchmarks
cmds:
- echo "Running benchmarks..."
- go test -bench=. -benchmem ./...
bench:pkg:
desc: Run benchmarks for specific package (use PKG=./pkg/sql/parser)
cmds:
- echo "Running benchmarks for {{.PKG}}..."
- go test -bench=. -benchmem {{.PKG}}
vars:
PKG: '{{default "./pkg/sql/parser" .PKG}}'
bench:cpu:
desc: Run benchmarks with CPU profiling
cmds:
- echo "Running benchmarks with CPU profile..."
- go test -bench=. -benchmem -cpuprofile=cpu.prof ./pkg/sql/parser
- echo "CPU profile saved to cpu.prof - use 'go tool pprof cpu.prof'"
bench:mem:
desc: Run benchmarks with memory profiling
cmds:
- echo "Running benchmarks with memory profile..."
- go test -bench=. -benchmem -memprofile=mem.prof ./pkg/sql/parser
- echo "Memory profile saved to mem.prof - use 'go tool pprof mem.prof'"
# =============================================================================
# FUZZ TESTING
# =============================================================================
fuzz:
desc: Run fuzz tests (duration configurable via FUZZ_TIME, default 30s)
cmds:
- echo "Running fuzz tests for {{.FUZZ_TIME}}..."
- |
if [ -f "./scripts/run_fuzz_tests.sh" ]; then
./scripts/run_fuzz_tests.sh
else
echo "Error: scripts/run_fuzz_tests.sh not found"
echo "You can run fuzz tests directly with: go test -fuzz=FuzzTokenizer -fuzztime={{.FUZZ_TIME}} ./pkg/sql/tokenizer"
exit 1
fi
vars:
FUZZ_TIME: '{{default "30s" .FUZZ_TIME}}'
fuzz:tokenizer:
desc: Run tokenizer fuzz tests
cmds:
- echo "Fuzzing tokenizer..."
- go test -fuzz=FuzzTokenizer -fuzztime={{.FUZZ_TIME}} ./pkg/sql/tokenizer
vars:
FUZZ_TIME: '{{default "30s" .FUZZ_TIME}}'
# =============================================================================
# CODE QUALITY TASKS
# =============================================================================
fmt:
desc: Format Go code
cmds:
- echo "Formatting code..."
- go fmt ./...
fmt:check:
desc: Check if code is formatted (fails if not)
cmds:
- echo "Checking code formatting..."
- test -z "$(gofmt -l .)"
silent: true
vet:
desc: Run go vet
cmds:
- echo "Running go vet..."
- go vet ./...
lint:
desc: Run golangci-lint
cmds:
- echo "Running golangci-lint..."
- |
if command -v golangci-lint > /dev/null; then
golangci-lint run
else
echo "golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"
exit 1
fi
lint:fix:
desc: Run golangci-lint with auto-fix
cmds:
- echo "Running golangci-lint with auto-fix..."
- |
if command -v golangci-lint > /dev/null; then
golangci-lint run --fix
else
echo "golangci-lint not installed. Run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"
exit 1
fi
staticcheck:
desc: Run staticcheck
cmds:
- echo "Running staticcheck..."
- |
if command -v staticcheck > /dev/null; then
staticcheck ./...
else
echo "staticcheck not installed. Run: go install honnef.co/go/tools/cmd/staticcheck@latest"
exit 1
fi
quality:
desc: Run all quality checks (fmt, vet, lint)
deps: [fmt, vet, lint]
check:
desc: Run full check suite (format check, vet, lint, test with race)
cmds:
- task: fmt:check
- task: vet
- task: lint
- task: test:race
# =============================================================================
# SECURITY TASKS
# =============================================================================
security:scan:
desc: Run security vulnerability scan
cmds:
- echo "Running security scan..."
- |
if command -v govulncheck > /dev/null; then
govulncheck ./...
else
echo "govulncheck not installed. Run: go install golang.org/x/vuln/cmd/govulncheck@latest"
exit 1
fi
security:validate:
desc: Validate security setup
cmds:
- |
if [ -f "./scripts/validate-security-setup.sh" ]; then
./scripts/validate-security-setup.sh
else
echo "Error: scripts/validate-security-setup.sh not found"
exit 1
fi
# =============================================================================
# DOCUMENTATION
# =============================================================================
docs:
desc: Generate documentation
cmds:
- echo "Generating documentation..."
- |
if command -v godoc > /dev/null; then
echo "Starting godoc server at http://localhost:6060/pkg/github.com/ajitpratap0/GoSQLX/"
godoc -http=:6060
else
echo "godoc not installed. Run: go install golang.org/x/tools/cmd/godoc@latest"
fi
# =============================================================================
# LSP SERVER
# =============================================================================
lsp:
desc: Start the LSP server
cmds:
- go run ./cmd/gosqlx lsp
lsp:debug:
desc: Start LSP server with debug logging
cmds:
- go run ./cmd/gosqlx lsp --log /tmp/gosqlx-lsp.log
# =============================================================================
# EXAMPLES
# =============================================================================
examples:
desc: Run example programs
cmds:
- echo "Running basic example..."
- go run ./examples/cmd/example.go
examples:test:
desc: Run example tests
dir: examples/cmd
cmds:
- go test -v example_test.go
# =============================================================================
# DEPENDENCIES
# =============================================================================
deps:
desc: Download and verify dependencies
cmds:
- echo "Downloading dependencies..."
- go mod download
- go mod verify
deps:tidy:
desc: Tidy go.mod and go.sum
cmds:
- echo "Tidying dependencies..."
- go mod tidy
deps:update:
desc: Update all dependencies
cmds:
- echo "Updating dependencies..."
- go get -u ./...
- go mod tidy
deps:tools:
desc: Install development tools
cmds:
- echo "Installing development tools..."
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
- go install honnef.co/go/tools/cmd/staticcheck@latest
- go install golang.org/x/vuln/cmd/govulncheck@latest
- go install golang.org/x/tools/cmd/godoc@latest
- echo "Installing task runner..."
- go install github.com/go-task/task/v3/cmd/task@latest
- echo ""
- echo "All Go tools installed!"
- echo ""
- echo "Optional - For task dev watch mode, install watchexec"
- echo " via Homebrew - brew install watchexec"
- echo " via Cargo - cargo install watchexec-cli"
# =============================================================================
# GIT HOOKS
# =============================================================================
hooks:install:
desc: Install Git pre-commit hooks
cmds:
- echo "Installing Git hooks..."
- |
if [ -f "./scripts/install-hooks.sh" ]; then
./scripts/install-hooks.sh
else
echo "Error: scripts/install-hooks.sh not found"
exit 1
fi
# =============================================================================
# CLEAN
# =============================================================================
clean:
desc: Clean build artifacts
cmds:
- echo "Cleaning..."
- rm -rf {{.BUILD_DIR}}
- rm -f {{.COVERAGE_FILE}} {{.COVERAGE_HTML}}
- rm -f cpu.prof mem.prof
- go clean -cache -testcache
clean:all:
desc: Deep clean including module cache
cmds:
- task: clean
- go clean -modcache
# =============================================================================
# CI/CD
# =============================================================================
ci:
desc: Run full CI pipeline (used in GitHub Actions)
cmds:
- echo "=== CI Pipeline Starting ==="
- task: deps
- task: fmt:check
- task: vet
- task: lint
- task: test:race
- task: build
- echo "=== CI Pipeline Complete ==="
ci:quick:
desc: Quick CI check (no race detection)
cmds:
- task: deps
- task: vet
- task: test:short
- task: build
# =============================================================================
# RELEASE
# =============================================================================
release:dry:
desc: Dry-run release with goreleaser
cmds:
- echo "Running goreleaser dry-run..."
- |
if command -v goreleaser > /dev/null; then
goreleaser release --snapshot --clean
else
echo "goreleaser not installed. Install from: https://goreleaser.com/install/"
exit 1
fi
release:check:
desc: Check goreleaser configuration
cmds:
- |
if command -v goreleaser > /dev/null; then
goreleaser check
else
echo "goreleaser not installed. Install from: https://goreleaser.com/install/"
exit 1
fi
# =============================================================================
# DEVELOPMENT HELPERS
# =============================================================================
dev:
desc: Start development mode (watch for changes)
cmds:
- echo "Development mode - run tests on file changes"
- |
if command -v watchexec > /dev/null; then
watchexec -e go -- go test -short ./...
else
echo "watchexec not installed. Install via: brew install watchexec or cargo install watchexec-cli"
fi
validate:
desc: Validate SQL via CLI (use SQL="SELECT * FROM users")
cmds:
- go run ./cmd/gosqlx validate "{{.SQL}}"
vars:
SQL: '{{default "SELECT * FROM users" .SQL}}'
format:sql:
desc: Format SQL via CLI (use SQL="select * from users")
cmds:
- go run ./cmd/gosqlx format "{{.SQL}}"
vars:
SQL: '{{default "select * from users" .SQL}}'
analyze:
desc: Analyze SQL via CLI (use SQL="SELECT * FROM users")
cmds:
- go run ./cmd/gosqlx analyze "{{.SQL}}"
vars:
SQL: '{{default "SELECT * FROM users WHERE id = 1" .SQL}}'