-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTaskfile.yml
More file actions
293 lines (258 loc) · 10.3 KB
/
Taskfile.yml
File metadata and controls
293 lines (258 loc) · 10.3 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
version: '3'
vars:
BINARY_NAME: compass
BUILD_DIR: dist
MAIN_PATH: ./main.go
MODULE:
sh: go list -m
VERSION:
sh: git describe --tags --always --dirty 2>/dev/null || echo "dev"
COMMIT:
sh: git rev-parse --short HEAD 2>/dev/null || echo "unknown"
BUILD_DATE:
sh: date -u +"%Y-%m-%dT%H:%M:%SZ"
BUILD_USER:
sh: whoami 2>/dev/null || echo "unknown"
BUILD_HOST:
sh: hostname 2>/dev/null || echo "unknown"
BUILD_ARCH:
sh: echo "$(go env GOOS)/$(go env GOARCH)"
COVERAGE_MIN: "75"
tasks:
default:
desc: Show available tasks
cmds:
- task --list-all
build:
desc: Build the application
cmds:
- mkdir {{.BUILD_DIR}} || true
- go build -ldflags="-X {{.MODULE}}/internal/version.Version={{.VERSION}} -X {{.MODULE}}/internal/version.Commit={{.COMMIT}} -X {{.MODULE}}/internal/version.BuildDate={{.BUILD_DATE}} -X {{.MODULE}}/internal/version.BuildUser={{.BUILD_USER}} -X {{.MODULE}}/internal/version.BuildHost={{.BUILD_HOST}} -X {{.MODULE}}/internal/version.BuildArch={{.BUILD_ARCH}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}} {{.MAIN_PATH}}
build-all:
desc: Build for multiple platforms
cmds:
- task: build-linux
- task: build-linux-arm64
- task: build-darwin
- task: build-darwin-arm64
- task: build-windows
build-linux:
desc: Build for Linux
env:
GOOS: linux
GOARCH: amd64
cmds:
- mkdir {{.BUILD_DIR}} || true
- go build -ldflags="-X {{.MODULE}}/internal/version.Version={{.VERSION}} -X {{.MODULE}}/internal/version.Commit={{.COMMIT}} -X {{.MODULE}}/internal/version.BuildDate={{.BUILD_DATE}} -X {{.MODULE}}/internal/version.BuildUser={{.BUILD_USER}} -X {{.MODULE}}/internal/version.BuildHost={{.BUILD_HOST}} -X {{.MODULE}}/internal/version.BuildArch={{.BUILD_ARCH}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-amd64 {{.MAIN_PATH}}
build-linux-arm64:
desc: Build for Linux ARM64
env:
GOOS: linux
GOARCH: arm64
cmds:
- mkdir {{.BUILD_DIR}} || true
- go build -ldflags="-X {{.MODULE}}/internal/version.Version={{.VERSION}} -X {{.MODULE}}/internal/version.Commit={{.COMMIT}} -X {{.MODULE}}/internal/version.BuildDate={{.BUILD_DATE}} -X {{.MODULE}}/internal/version.BuildUser={{.BUILD_USER}} -X {{.MODULE}}/internal/version.BuildHost={{.BUILD_HOST}} -X {{.MODULE}}/internal/version.BuildArch={{.BUILD_ARCH}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-linux-arm64 {{.MAIN_PATH}}
build-darwin:
desc: Build for macOS
env:
GOOS: darwin
GOARCH: amd64
cmds:
- mkdir {{.BUILD_DIR}} || true
- go build -ldflags="-X {{.MODULE}}/internal/version.Version={{.VERSION}} -X {{.MODULE}}/internal/version.Commit={{.COMMIT}} -X {{.MODULE}}/internal/version.BuildDate={{.BUILD_DATE}} -X {{.MODULE}}/internal/version.BuildUser={{.BUILD_USER}} -X {{.MODULE}}/internal/version.BuildHost={{.BUILD_HOST}} -X {{.MODULE}}/internal/version.BuildArch={{.BUILD_ARCH}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-amd64 {{.MAIN_PATH}}
build-darwin-arm64:
desc: Build for macOS ARM64
env:
GOOS: darwin
GOARCH: arm64
cmds:
- mkdir {{.BUILD_DIR}} || true
- go build -ldflags="-X {{.MODULE}}/internal/version.Version={{.VERSION}} -X {{.MODULE}}/internal/version.Commit={{.COMMIT}} -X {{.MODULE}}/internal/version.BuildDate={{.BUILD_DATE}} -X {{.MODULE}}/internal/version.BuildUser={{.BUILD_USER}} -X {{.MODULE}}/internal/version.BuildHost={{.BUILD_HOST}} -X {{.MODULE}}/internal/version.BuildArch={{.BUILD_ARCH}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-darwin-arm64 {{.MAIN_PATH}}
build-windows:
desc: Build for Windows
env:
GOOS: windows
GOARCH: amd64
cmds:
- mkdir {{.BUILD_DIR}} || true
- go build -ldflags="-X {{.MODULE}}/internal/version.Version={{.VERSION}} -X {{.MODULE}}/internal/version.Commit={{.COMMIT}} -X {{.MODULE}}/internal/version.BuildDate={{.BUILD_DATE}} -X {{.MODULE}}/internal/version.BuildUser={{.BUILD_USER}} -X {{.MODULE}}/internal/version.BuildHost={{.BUILD_HOST}} -X {{.MODULE}}/internal/version.BuildArch={{.BUILD_ARCH}}" -o {{.BUILD_DIR}}/{{.BINARY_NAME}}-windows-amd64.exe {{.MAIN_PATH}}
test:
desc: Run tests
cmds:
- go test -v ./...
test-short:
desc: Run tests in short mode (skip integration tests)
cmds:
- go test -short -v ./...
test-coverage:
desc: Run tests with coverage
cmds:
- go test -v -coverprofile=coverage.out ./...
- go tool cover -html=coverage.out -o coverage.html
test-coverage-func:
desc: Run tests with coverage and show function coverage
cmds:
- go test -v -coverprofile=coverage.out ./...
- go tool cover -func=coverage.out
test-coverage-threshold:
desc: Run tests with coverage and fail if total coverage < 75%
cmds:
- go test -v -coverprofile=coverage.out ./...
- |
total=$(go tool cover -func=coverage.out | awk '/^total:/ {print substr($3, 1, length($3)-1)}')
echo "Total coverage: ${total}%"
if awk "BEGIN {exit !(${total} < {{.COVERAGE_MIN}})}"; then
echo "Coverage below required threshold ({{.COVERAGE_MIN}}%)." >&2
exit 1
fi
test-race:
desc: Run tests with race detector
cmds:
- go test -race -v ./...
test-bench:
desc: Run benchmark tests
cmds:
- go test -bench=. -v ./...
test-unit:
desc: Run only unit tests (exclude integration tests)
cmds:
- go test -short -v ./internal/...
test-integration:
desc: Run integration tests
cmds:
- go test -v ./cmd/... ./main_test.go
lint:
desc: Run golangci-lint with configuration
cmds:
- golangci-lint run ./...
lint-fix:
desc: Run golangci-lint and fix auto-fixable issues
cmds:
- golangci-lint run --fix ./...
lint-verbose:
desc: Run golangci-lint with verbose output
cmds:
- golangci-lint run -v ./...
lint-new:
desc: Run golangci-lint only on new/changed files (requires git)
cmds:
- golangci-lint run --new-from-rev=HEAD~1 ./...
fmt:
desc: Format code
cmds:
- go fmt ./...
vet:
desc: Run go vet
cmds:
- go vet ./...
mod-tidy:
desc: Tidy module dependencies
cmds:
- go mod tidy
mod-vendor:
desc: Vendor dependencies
cmds:
- go mod vendor
clean:
desc: Clean build artifacts
cmds:
- rm -rf {{.BUILD_DIR}}
- rm -f coverage.out coverage.html
- rm -rf vendor/
- rm -rf tmp/
install:
desc: Install the application to ~/.local/bin with shell completions
cmds:
- task: build
- echo "Installing {{.BINARY_NAME}} to $HOME/.local/bin..."
- mkdir -p $HOME/.local/bin
- |
if [ -f "$HOME/.local/bin/{{.BINARY_NAME}}" ]; then
echo "Backing up existing binary to {{.BINARY_NAME}}.backup"
cp "$HOME/.local/bin/{{.BINARY_NAME}}" "$HOME/.local/bin/{{.BINARY_NAME}}.backup"
fi
- cp {{.BUILD_DIR}}/{{.BINARY_NAME}} $HOME/.local/bin/
- chmod +x $HOME/.local/bin/{{.BINARY_NAME}}
- |
if [ ! -f "$HOME/.local/bin/cps" ] || [ ! -L "$HOME/.local/bin/cps" ]; then
echo "Creating cps alias symlink..."
ln -sf "$HOME/.local/bin/{{.BINARY_NAME}}" "$HOME/.local/bin/cps"
fi
- echo "Installing shell completions..."
- mkdir -p $HOME/.local/share/bash-completion/completions
- $HOME/.local/bin/{{.BINARY_NAME}} completion bash > $HOME/.local/share/bash-completion/completions/{{.BINARY_NAME}}
- mkdir -p $HOME/.local/share/zsh/site-functions
- $HOME/.local/bin/{{.BINARY_NAME}} completion zsh > $HOME/.local/share/zsh/site-functions/_{{.BINARY_NAME}}
- mkdir -p $HOME/.config/fish/completions
- $HOME/.local/bin/{{.BINARY_NAME}} completion fish > $HOME/.config/fish/completions/{{.BINARY_NAME}}.fish
- |
if command -v pwsh >/dev/null 2>&1; then
echo "Installing PowerShell completion..."
PWSH_PROFILE_DIR=$(pwsh -NoProfile -Command 'Split-Path $PROFILE')
mkdir -p "$PWSH_PROFILE_DIR"
$HOME/.local/bin/{{.BINARY_NAME}} completion powershell > "$PWSH_PROFILE_DIR/{{.BINARY_NAME}}_completion.ps1"
echo " PowerShell completion installed. Add this to your profile (\$PROFILE):"
echo " . \"\$PSScriptRoot/{{.BINARY_NAME}}_completion.ps1\""
fi
- echo "✓ Installation complete!"
- $HOME/.local/bin/{{.BINARY_NAME}} version
- |
if ! echo "$PATH" | grep -q "$HOME/.local/bin"; then
echo ""
echo "⚠️ Warning: $HOME/.local/bin is not in your PATH"
echo " Add this to your shell profile (.bashrc, .zshrc, etc.):"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
fi
uninstall:
desc: Uninstall the application and remove shell completions
cmds:
- echo "Uninstalling {{.BINARY_NAME}}..."
- rm -f $HOME/.local/bin/{{.BINARY_NAME}}
- rm -f $HOME/.local/bin/cps
- rm -f $HOME/.local/bin/{{.BINARY_NAME}}.backup
- rm -f $HOME/.local/share/bash-completion/completions/{{.BINARY_NAME}}
- rm -f $HOME/.local/share/zsh/site-functions/_{{.BINARY_NAME}}
- rm -f $HOME/.config/fish/completions/{{.BINARY_NAME}}.fish
- |
if command -v pwsh >/dev/null 2>&1; then
PWSH_PROFILE_DIR=$(pwsh -NoProfile -Command 'Split-Path $PROFILE')
rm -f "$PWSH_PROFILE_DIR/{{.BINARY_NAME}}_completion.ps1"
echo " PowerShell completion removed. You may need to remove the sourcing line from your profile (\$PROFILE)"
fi
- echo "✓ Uninstall complete!"
run:
desc: Run the application
cmds:
- go run {{.MAIN_PATH}} {{.CLI_ARGS}}
dev:
desc: Development mode with auto-reload (requires air)
cmds:
- air
test-watch:
desc: Run tests in watch mode (requires entr)
cmds:
- find . -name '*.go' | entr -c go test -v ./...
check:
desc: Run all checks (fmt, vet, lint, test)
cmds:
- task: fmt
- task: vet
- task: lint
- task: test
ci:
desc: Run CI checks (used for continuous integration)
cmds:
- task: fmt
- task: vet
- task: test-race
- task: test-coverage-func
release:
desc: Build release binaries
cmds:
- task: clean
- task: check
- task: build-all
help:
desc: Show help for the built application
cmds:
- ./{{.BINARY_NAME}} --help