-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskfile.yml
More file actions
245 lines (210 loc) · 5.76 KB
/
Taskfile.yml
File metadata and controls
245 lines (210 loc) · 5.76 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
# https://taskfile.dev
version: '3'
vars:
BINARY_NAME: bdcli
MAIN_PACKAGE: ./main.go
BUILD_DIR: ./dist
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo "v0.0.0-dev"
COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo "none"
BUILD_DATE:
sh: date -u +%Y-%m-%dT%H:%M:%SZ
tasks:
default:
desc: List all available tasks
cmds:
- task --list-all
silent: true
# Development tasks
run:
desc: Run the CLI application
vars:
LDFLAGS: '-X main.version={{.VERSION}}-dev -X main.commit={{.COMMIT}} -X main.date={{.BUILD_DATE}}'
cmds:
- go run -ldflags "{{.LDFLAGS}}" {{.MAIN_PACKAGE}} {{.CLI_ARGS}}
# Build tasks
build:
desc: Build the binary for current platform
vars:
LDFLAGS: '-X main.version={{.VERSION}}-dev -X main.commit={{.COMMIT}} -X main.date={{.BUILD_DATE}}'
cmds:
- go build -ldflags "{{.LDFLAGS}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}{{if eq OS "windows"}}.exe{{end}} {{.MAIN_PACKAGE}}
sources:
- '**/*.go'
- go.mod
- go.sum
generates:
- '{{.BUILD_DIR}}/{{.BINARY_NAME}}{{if eq OS "windows"}}.exe{{end}}'
build:all:
desc: Build binaries for all platforms using GoReleaser
cmds:
- goreleaser build --snapshot --clean --skip=publish
sources:
- '**/*.go'
- go.mod
- go.sum
- .goreleaser.yaml
# Testing tasks
test:
desc: Run all tests
cmds:
- go test ./...
test:verbose:
desc: Run all tests with verbose output
cmds:
- go test -v ./...
# Benchmarking tasks
bench:
desc: Run all benchmarks
cmds:
- go test -bench=. -benchmem ./...
bench:cpu:
desc: Run benchmarks with CPU profiling
cmds:
- go test -bench=. -benchmem -cpuprofile=debug/cpu.prof
- echo "CPU profile saved to debug/cpu.prof"
- "echo 'View with: go tool pprof debug/cpu.prof'"
bench:mem:
desc: Run benchmarks with memory profiling
cmds:
- go test -bench=. -benchmem -memprofile=debug/mem.prof
- echo "Memory profile saved to debug/mem.prof"
- "echo 'View with: go tool pprof debug/mem.prof'"
# Coverage tasks
coverage:
desc: Run tests with coverage report
cmds:
- go test -cover ./...
coverage:html:
desc: Generate HTML coverage report
cmds:
- go test -coverprofile=debug/coverage.out ./...
- go tool cover -html=debug/coverage.out -o debug/coverage.html
- echo "Coverage report generated at debug/coverage.html"
coverage:func:
desc: Show coverage by function
cmds:
- go test -coverprofile=debug/coverage.out ./...
- go tool cover -func=debug/coverage.out
coverage:detailed:
desc: Run coverage with detailed output and open HTML report
cmds:
- go test -coverprofile=debug/coverage.out -covermode=atomic ./...
- go tool cover -func=debug/coverage.out
- go tool cover -html=debug/coverage.out -o debug/coverage.html
- echo "Coverage report generated at debug/coverage.html"
# Code quality tasks
lint:
desc: Run golangci-lint
cmds:
- golangci-lint run ./...
lint:fix:
desc: Run golangci-lint with auto-fix
cmds:
- golangci-lint run --fix ./...
fix:
desc: Fix and modernize all Go files
cmds:
- go fix ./...
fmt:
desc: Format all Go files
cmds:
- go fmt ./...
vet:
desc: Run go vet
cmds:
- go vet ./...
# Release tasks
release:
desc: Create a new release (runs GoReleaser)
cmds:
- goreleaser release --clean
preconditions:
- sh: command -v goreleaser
msg: 'goreleaser not installed. See: https://goreleaser.com/install/'
- sh: git diff-index --quiet HEAD
msg: 'Git working directory is not clean. Commit or stash changes first.'
release:snapshot:
desc: Create a snapshot release (no publish)
cmds:
- goreleaser release --snapshot --clean --skip=publish
release:test:
desc: Test the release process without publishing
cmds:
- goreleaser release --skip=publish --clean
release:npm:
desc: Publish to npm after GitHub release
cmds:
- npm publish
preconditions:
- sh: test -f package.json
msg: 'package.json not found'
# CI/CD tasks
ci:
desc: Run CI checks (used in CI/CD pipelines)
cmds:
- task: deps
- task: fix
- task: fmt
- task: vet
- task: coverage
- task: build
# Dependency management
deps:
desc: Tidy, download, and verify Go dependencies
cmds:
- go mod tidy
- go mod download
- go mod verify
deps:upgrade:
desc: Upgrade all Go dependencies
cmds:
- go get -u ./...
- go mod tidy
- go mod verify
# Setup and validation tasks
setup:
desc: Setup development environment
cmds:
- task: deps
- task: tools
tools:
desc: Install development tools
cmds:
- brew install golangci-lint
- brew install goreleaser
check:
desc: Run all checks (fix, fmt, vet, lint, test)
cmds:
- task: fix
- task: fmt
- task: vet
- task: lint
- task: test
validate:
desc: Validate goreleaser configuration
cmds:
- goreleaser check
preconditions:
- sh: command -v goreleaser
msg: 'goreleaser not installed. See: https://goreleaser.com/install/'
# Clean tasks
clean:
desc: Clean all generated files
cmds:
- task: clean:build
- task: clean:coverage
- task: clean:profiles
clean:build:
desc: Remove build directory
cmds:
- rm -rf {{.BUILD_DIR}}
clean:coverage:
desc: Remove coverage files
cmds:
- rm -f debug/coverage.out debug/coverage.html
clean:profiles:
desc: Remove profiling files
cmds:
- rm -f debug/cpu.prof debug/mem.prof