Repository navigation
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
394 lines (352 loc) · 13.6 KB
/
Copy pathTaskfile.yaml
File metadata and controls
394 lines (352 loc) · 13.6 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
---
# Reference:
# https://taskfile.dev/docs/reference/schema
# JSON schema:
# https://taskfile.dev/schema.json
# ╭────────────────────----------------──────────╮
# │ commit │
# ╰─────────────────────----------------─────────╯
#
# Before running any commands, ensure following tools are installed:
# - go @see https://go.dev/
# - mise @see https://mise.jdx.dev/
# - task @see https://taskfile.dev/
#
# This file can be executed manually, from CI, by IDE and invoked by AI.
version: '3'
set:
- errexit
- pipefail
vars:
# Task's env cannot override an inherited PATH; resolve pinned tools explicitly.
TOOLS_BIN: '{{.ROOT_DIR}}/.tools/shims'
env:
GOTOOLCHAIN: local
MISE_DEFAULT_CONFIG_FILENAME: etc/mise.toml
MISE_DATA_DIR: '{{.ROOT_DIR}}/.tools'
MISE_CACHE_DIR: '{{.ROOT_DIR}}/.tools/cache'
MISE_STATE_DIR: '{{.ROOT_DIR}}/.tools/state'
MISE_EXEC_AUTO_INSTALL: 'false'
TASK_TEMP_DIR: '{{.ROOT_DIR}}/.tools/task'
tasks:
# ╭────────────────────----------------──────────╮
# │ Setup │
# ╰─────────────────────----------------─────────╯
help:
desc: "List available tasks in Taskfile order"
aliases:
- default
cmds:
- "task --list --sort none"
x:
desc: "Run the pinned go42x CLI"
summary: "Usage: task x [-- COMMAND ...]"
interactive: true
cmds:
- '"{{.TOOLS_BIN}}/go42x" {{.CLI_ARGS}}'
tool:
desc: "Run a command with the project tools"
summary: "Usage: task tool -- COMMAND [ARGS...]"
interactive: true
silent: true
preconditions:
- sh: 'test -n {{.CLI_ARGS | shellQuote}}'
msg: "Usage: task tool -- COMMAND [ARGS...]"
cmds:
- 'mise exec -- {{.CLI_ARGS}}'
setup:
desc: "install dependencies"
cmds:
- "mise install --locked"
- "go mod download"
setup:release:
desc: "install release dependencies"
cmds:
- "mise install --locked task goreleaser syft cosign"
- "go mod download"
## bump | set a mise tool dependency to a version
bump:
desc: "Set a mise tool dependency to a version (writes)"
summary: "Usage: task bump TOOL=goreleaser VERSION=2.18.1"
requires:
vars:
- TOOL
- VERSION
preconditions:
- sh: 'test -n {{.TOOL | shellQuote}} && test -n {{.VERSION | shellQuote}}'
msg: "TOOL and VERSION must not be empty."
- sh: 'test -z {{.CLI_ARGS | shellQuote}}'
msg: "Pass TOOL=... VERSION=... without arguments after --."
cmds:
- 'mise use --pin -- {{printf "%s@%s" .TOOL .VERSION | shellQuote}}'
- 'mise lock -- {{.TOOL | shellQuote}}'
# ╭────────────────────----------------──────────╮
# │ Testing │
# ╰─────────────────────----------------─────────╯
test:
desc: "Run unit and CLI end-to-end tests"
aliases:
- test:all
cmds:
- task: test:unit
- task: test:e2e
# @note -count=1 is needed to prevent caching of test results.
test:unit:
desc: "run unit tests with coverage, or selected packages with race detection"
summary: "Usage: task test:unit [-- PACKAGE ...]. Defaults to the full unit suite with coverage."
preconditions:
- &package_paths
sh: |
set -- {{.CLI_ARGS}}
for package do
case "$package" in
./*) [ ! -d "${package%/...}" ] || continue ;;
esac
printf 'Expected a local Go package or subtree: %s\n' "$package" >&2
exit 2
done
msg: "Pass local Go packages after --."
cmds:
- |
set -eo pipefail
set -- {{.CLI_ARGS}}
if [ "$#" -gt 0 ]; then
exec go test -count=1 -race "$@"
fi
mkdir -p .build
unit_packages=$(go list ./...)
unit_exclude_pattern=$(printf '%s\n' mocks tests | paste -sd '|' -)
unit_packages=$(printf '%s\n' "$unit_packages" | grep -vE "/($unit_exclude_pattern)(/|$)")
# go list returns separate package names; preserve word splitting here.
# shellcheck disable=SC2086
go test -count=1 -v -race -covermode=atomic \
-coverpkg="$(printf '%s\n' "$unit_packages" | paste -sd, -)" \
-coverprofile=.build/coverage.out $unit_packages \
| sed -E 's/(coverage: [0-9.]+% of statements) in .*/\1/'
go tool cover -html=.build/coverage.out -o=.build/coverage.html
go tool cover -func=.build/coverage.out | grep '^total:'
test:e2e:
desc: "Run CLI tests with race detection in isolated Git repositories"
cmds:
- >-
go run github.com/onsi/ginkgo/v2/ginkgo --race --procs=4 --randomize-all --fail-on-pending --fail-on-empty --trace
--timeout={{.E2E_TIMEOUT | default "5m" | shellQuote}} ./tests/e2e
test:release:
desc: "Verify release artifacts and test the native packaged CLI"
env:
COMMIT_RELEASE_DIST: '{{.COMMIT_RELEASE_DIST | default ".build/dist"}}'
cmds:
- task: test:e2e
vars:
# Allow the full suite to finish on slower native macOS Intel runners.
E2E_TIMEOUT: '{{.E2E_TIMEOUT | default "10m"}}'
# ╭────────────────────----------------──────────╮
# │ General workflow │
# ╰─────────────────────----------------─────────╯
build:
desc: "build the binary for the current platform or GOOS/GOARCH"
cmds:
- "mkdir -p .build"
- "go build -mod=readonly -trimpath -buildvcs=false -o .build/commit ."
generate:
desc: "generate code for all modules"
cmds:
- "go mod tidy"
- |
export PATH="{{.TOOLS_BIN}}:$PATH"
go generate ./...
# ╭────────────────────----------------──────────╮
# │ Formatters │
# ╰─────────────────────----------------─────────╯
fmt:go:
desc: "Format explicit Go source files (writes)"
summary: "Usage: task fmt:go -- FILE.go [FILE.go ...]"
preconditions: &files
- sh: |
set -- {{.CLI_ARGS}}
[ "$#" -gt 0 ]
msg: "Pass explicit file paths after --."
- &file_paths
sh: |
set -- {{.CLI_ARGS}}
for file do
case "$file" in
-*|!*|*\**|*\?*|*\[*|*\]*|*\{*|*\}*) printf 'Expected a literal file path: %s\n' "$file" >&2; exit 2 ;;
esac
[ -f "$file" ] || { printf 'Expected an existing file: %s\n' "$file" >&2; exit 2; }
done
msg: "Pass explicit existing file paths after --."
cmds:
- |
set -- {{.CLI_ARGS}}
"{{.TOOLS_BIN}}/golangci-lint" fmt --config etc/golangci.yml "$@"
fmt:yaml:
desc: "Format explicit plain YAML files (writes)"
summary: "Usage: task fmt:yaml -- FILE.yaml [FILE.yaml ...]."
preconditions: *files
cmds:
- |
set -- {{.CLI_ARGS}}
"{{.TOOLS_BIN}}/yamlfmt" -conf etc/yamlfmt.yaml "$@"
fmt:json:
desc: "Format explicit JSON files (writes)"
summary: "Usage: task fmt:json -- FILE.json [FILE.json ...]"
preconditions: *files
cmds:
- |
set -- {{.CLI_ARGS}}
"{{.TOOLS_BIN}}/jsonfmt" -w "$@"
fmt:toml:
desc: "Format explicit TOML files (writes)"
summary: "Usage: task fmt:toml -- FILE.toml [FILE.toml ...]"
preconditions: *files
cmds:
- |
set -- {{.CLI_ARGS}}
for file do
case "$file" in
/*) ;;
*) file="$PWD/$file" ;;
esac
# Tombi discovers etc/tombi.toml from its working directory.
(cd etc && "{{.TOOLS_BIN}}/tombi" format --offline "$file")
done
# ╭────────────────────----------------──────────╮
# │ Linters │
# ╰─────────────────────----------------─────────╯
lint:
desc: "Run Go, security, configuration, and workflow checks"
cmds:
- task: lint:go
- task: lint:go-security
- task: lint:vulnerabilities
- task: lint:secrets
- task: lint:json
- task: lint:yaml
- task: lint:toml
- task: lint:actions
lint:go:
desc: "Lint all Go packages, or explicit local packages and subtrees (read only)"
summary: "Usage: task lint:go [-- ./internal/cmd ./pkg/kwb/...]"
preconditions:
- *package_paths
cmds:
- |
set -- {{.CLI_ARGS}}
"{{.TOOLS_BIN}}/golangci-lint" config verify --config etc/golangci.yml
"{{.TOOLS_BIN}}/golangci-lint" run --config etc/golangci.yml "$@"
lint:go-security:
desc: "Check handwritten Go code with Gosec"
cmds:
- '"{{.TOOLS_BIN}}/gosec" -terse -exclude-generated -exclude-dir=.build -exclude-dir=.tools ./...'
lint:vulnerabilities:
desc: "Check CLI vulnerabilities for all release platforms"
cmds:
- 'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 "{{.TOOLS_BIN}}/govulncheck" .'
- 'CGO_ENABLED=0 GOOS=linux GOARCH=arm64 "{{.TOOLS_BIN}}/govulncheck" .'
- 'CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 "{{.TOOLS_BIN}}/govulncheck" .'
- 'CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 "{{.TOOLS_BIN}}/govulncheck" .'
lint:secrets:
desc: "Scan Git history for secrets with Gitleaks"
cmds:
- '"{{.TOOLS_BIN}}/gitleaks" git --config etc/gitleaks.toml --no-banner --redact -v'
lint:actions:
desc: "check GitHub Actions workflows"
preconditions:
- *file_paths
cmds:
- '"{{.TOOLS_BIN}}/actionlint" -oneline {{.CLI_ARGS}}'
lint:yaml:
desc: "Check plain YAML source formatting, or explicit files (read only)"
summary: "Usage: task lint:yaml [-- FILE.yaml ...]."
vars:
SOURCE_FILES:
sh: |
{{if not .CLI_ARGS}}
git ls-files --cached --others --exclude-standard -z -- '*.yaml' '*.yml'
{{end}}
preconditions:
- *file_paths
cmds:
- |
set -- {{if .CLI_ARGS}}{{.CLI_ARGS}}{{else}}{{range splitList "\x00" .SOURCE_FILES}}{{if .}}{{. | shellQuote}} {{end}}{{end}}{{end}}
for file do
if [ -f "$file" ]; then
"{{.TOOLS_BIN}}/yamlfmt" -conf etc/yamlfmt.yaml -lint "$file"
fi
done
lint:json:
desc: "Check JSON source formatting, or explicit files (read only)"
summary: "Usage: task lint:json [-- FILE.json ...]; defaults exclude package-lock.json."
vars:
SOURCE_FILES:
sh: |
{{if not .CLI_ARGS}}
git ls-files --cached --others --exclude-standard -z -- '*.json' ':!:**/package-lock.json'
{{end}}
preconditions:
- *file_paths
cmds:
- |
set -- {{if .CLI_ARGS}}{{.CLI_ARGS}}{{else}}{{range splitList "\x00" .SOURCE_FILES}}{{if .}}{{. | shellQuote}} {{end}}{{end}}{{end}}
for file do
if [ -f "$file" ]; then
"{{.TOOLS_BIN}}/jsonfmt" "$file"
fi
done
lint:toml:
desc: "Check TOML source formatting and lint rules, or explicit files (read only)"
summary: "Usage: task lint:toml [-- FILE.toml ...]; defaults to Git source files ending in .toml."
vars:
SOURCE_FILES:
sh: |
{{if not .CLI_ARGS}}
git ls-files --cached --others --exclude-standard -z -- '*.toml'
{{end}}
preconditions:
- *file_paths
cmds:
- |
set -- {{if .CLI_ARGS}}{{.CLI_ARGS}}{{else}}{{range splitList "\x00" .SOURCE_FILES}}{{if .}}{{. | shellQuote}} {{end}}{{end}}{{end}}
for file do
if [ -f "$file" ]; then
case "$file" in
/*) ;;
*) file="$PWD/$file" ;;
esac
# Tombi discovers etc/tombi.toml from its working directory.
(
cd etc
"{{.TOOLS_BIN}}/tombi" format --offline --check "$file"
"{{.TOOLS_BIN}}/tombi" lint --offline --error-on-warnings "$file"
)
fi
done
# ╭────────────────────----------------──────────╮
# │ Release │
# ╰─────────────────────----------------─────────╯
release:check:
desc: "validate GoReleaser configuration"
cmds:
- '"{{.TOOLS_BIN}}/goreleaser" check --config etc/goreleaser.yaml'
release:snapshot:
desc: "build release artifacts without publishing or signing"
cmds:
- |
export PATH="{{.TOOLS_BIN}}:$PATH"
goreleaser release --config etc/goreleaser.yaml --snapshot --clean --skip=publish,sign
release:local:
desc: "build and sign a tagged release without publishing"
cmds:
- |
export PATH="{{.TOOLS_BIN}}:$PATH"
goreleaser release --config etc/goreleaser.yaml --clean --skip=publish
release:
desc: "build, sign, and publish the validated release (CI only)"
preconditions:
- sh: '[ "$GITHUB_ACTIONS" = "true" ]'
msg: "Dispatch the release workflow from master to publish a release."
cmds:
- |-
export PATH="{{.TOOLS_BIN}}:$PATH"
goreleaser release --config etc/goreleaser.yaml --clean