-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
309 lines (280 loc) · 10.8 KB
/
Taskfile.yml
File metadata and controls
309 lines (280 loc) · 10.8 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
# Copyright 2026 — see LICENSE file for terms.
version: "3"
vars:
BINARY: aifr
release_tag_message_prefix: aifr version
version_embedded_file: internal/version/version.go
env:
# Allow a version override to come before the command as an env override,
# OR to come after the command as a var-assignment.
#
# We do this at the top-level because `release:commits-and-tag` uses a
# sub-process to invoke us, to get the version into a shell variable, and we
# need the CLI assignment to propagate into the environment.
# Note though that we do need to explicitly unset this for the _second_ invocation.
VERSION_OVERRIDE: "{{.VERSION_OVERRIDE}}"
tasks:
default:
deps: [help]
help:
silent: true
cmds:
- |
cat <<'EOHELP'
There are various commands available, see `task -l` for more details
EOHELP
build:
desc: Build the aifr binary
sources:
- "**/*.go"
- go.mod
- go.sum
generates:
- "{{.BINARY}}"
vars:
repo_version:
sh: git describe --dirty --always --tags 2>/dev/null || echo dev
env:
VERSION: "{{.VERSION | default .repo_version}}"
cmds:
- |-2
set -eu
ns='go.pennock.tech/aifr/internal/version'
COMMIT="$(git rev-parse HEAD 2>/dev/null || echo unknown)"
BUILD_DATE="$(git log -1 --format=%cI 2>/dev/null || echo unknown)"
LDFLAGS="-s -w -X $ns.Version=${VERSION} -X $ns.Commit=${COMMIT} -X $ns.BuildDate=${BUILD_DATE}"
CGO_ENABLED=0 go build -v -ldflags="${LDFLAGS}" -trimpath -o {{.BINARY}} ./cmd/aifr
test:
desc: Run all tests
cmds:
- go test -count=1 -race ./...
test:coverage:
desc: Run tests with coverage
cmds:
- go test -race -coverprofile=coverage.out ./...
- go tool cover -html=coverage.out -o coverage.html
fmt:
desc: Format Go source files
cmds:
- go fmt ./...
tidy:
desc: Tidy module dependencies
cmds:
- go mod tidy
lint:
desc: Run static analysis
cmds:
- go vet ./...
clean:
desc: Remove built artifacts
cmds:
- rm -f {{.BINARY}}
- rm -f coverage.out coverage.html
check:
desc: Run all checks (fmt, lint, test)
cmds:
- task: fmt
- task: lint
- task: test
release:snapshot:
desc: Create a snapshot release
cmds:
- goreleaser release --snapshot --clean --skip=sign
ci:check-github:
desc: Validate GitHub Actions workflows with zizmor
preconditions:
- sh: command -v zizmor
msg: >-
zizmor is not installed.
Install via: pip install zizmor (or: cargo install zizmor)
cmds:
- zizmor --format plain .github/workflows/
ci:pin-actions:
desc: Pin GitHub Actions to exact commit SHAs using pinact
preconditions:
- sh: command -v pinact
msg: >-
pinact is not installed.
Install via: go install github.com/suzuki-shunsuke/pinact/cmd/pinact@latest
cmds:
# See explanation below for when we're bumping the versions.
- pinact run --min-age 4
ci:pin-bump-actions:
desc: Bump pins of GitHub Actions
preconditions:
- sh: command -v pinact
msg: >-
pinact is not installed.
Install via: go install github.com/suzuki-shunsuke/pinact/cmd/pinact@latest
cmds:
# The minimum age is a cool-down defense against supply-chain attacks.
# We can always manually bump something explicitly if we know we must get a particular fix.
# Background reading:
# * <https://blog.yossarian.net/2025/11/21/We-should-all-be-using-dependency-cooldowns>
# * <https://nesbitt.io/2026/03/04/package-managers-need-to-cool-down.html>
- pinact run --min-age 4 --update
next-version:show:
desc: Show the next version to use
silent: true
deps: [_have_cargo_tool:convco]
env:
task_exe: "{{.TASK_EXE}}"
task_name: "{{.TASK}}"
cmd: |-2
shopt -s extglob
if [[ -n "${VERSION_OVERRIDE:-}" ]]; then
case "$VERSION_OVERRIDE" in
( v+([0-9]).+([0-9]).+([0-9])?(-*) ) printf '%s\n' "$VERSION_OVERRIDE" ;;
( +([0-9]).+([0-9]).+([0-9])?(-*) ) printf '%s\n' "v$VERSION_OVERRIDE" ;;
*) echo >&2 "${task_exe}: ${task_name}: REJECTING dubious VERSION_OVERRIDE=${VERSION_OVERRIDE@Q}"; exit 65 ;;
esac
exit 0
fi
old="$(convco version --pp)"
pure="$(convco version --pp --bump)"
if [[ "$old" != "$pure" ]]; then
printf '%s\n' "$pure"
exit 0
fi
if convco check "${old}..HEAD" >/dev/null; then
# all commits were conventional
current="$(git describe)"
if [[ "$current" == "$old" ]]; then
# We are at the release, we bump to -dev
echo "$(convco version --pp --patch)-dev"
else
echo >&2 "${task_exe}: ${task_name}: error: ${old@Q}..${current@Q} has commits and were all conventional but failed to get a version bump"
exit 1
fi
else
# I have not been behaving
convco version --pp --patch
fi
next-version:write:
desc: update repo_version.go with the next version
deps: [_have_cargo_tool:convco]
env:
version_file: "{{.version_embedded_file}}"
cmd: |-2
nv="$(task next-version:show)"
sed -i.bak -Ee s'/^(const[[:space:]]+HARDCODED_VERSION[[:space:]]+=[[:space:]]+")[^"]+"/\1'"$nv"'"/' "$version_file"
rm -f "${version_file}.bak"
release:preflight:
desc: Verify we're on main and up-to-date with all remotes
internal: true
silent: true
env:
task_exe: "{{.TASK_EXE}}"
task_name: "{{.TASK}}"
cmd: |-2
branch="$(git rev-parse --abbrev-ref HEAD)"
# FUTURE: also allow release/v* branches (see release:commits-and-tag for full design notes)
if [[ "$branch" != "main" ]]; then
echo >&2 "${task_exe}: ${task_name}: must be on 'main', currently on ${branch@Q}"
exit 1
fi
if ! git diff --quiet || ! git diff --cached --quiet; then
echo >&2 "${task_exe}: ${task_name}: working tree or index is dirty — commit or stash first"
exit 1
fi
git fetch --all --quiet
local_sha="$(git rev-parse HEAD)"
stale=()
while IFS= read -r remote; do
remote_ref="refs/remotes/${remote}/${branch}"
if ! git rev-parse --verify "$remote_ref" >/dev/null 2>&1; then
continue
fi
remote_sha="$(git rev-parse "$remote_ref")"
if [[ "$remote_sha" == "$local_sha" ]]; then
continue
fi
# Remote is strictly behind us — that's fine (we have unpushed commits, or are about to)
if git merge-base --is-ancestor "$remote_sha" "$local_sha"; then
continue
fi
stale+=("${remote}/${branch} (${remote_sha::12})")
done < <(git remote)
if [[ ${#stale[@]} -gt 0 ]]; then
echo >&2 "${task_exe}: ${task_name}: local ${branch} is behind or has diverged from:"
printf >&2 ' - %s\n' "${stale[@]}"
echo >&2 "Pull or rebase before releasing."
exit 1
fi
release:commits-and-tag:
# Deliberately DOES NOT PUSH: a human must review for sanity.
#
# CURRENT LIMITATION: assumes release from main.
# The -dev bump commit is made on the current branch, which is correct for main
# but wrong for release branches.
#
# FUTURE: support release/v* branches. When on a release branch:
# - Do bump + tag only (no -dev bump on the release branch)
# - After tagging, print instructions for the merge-to-main step
# - The preflight check should also validate the release branch is up-to-date
#
# After tagging on a release branch, the tag may need to become an ancestor
# of main so that git-describe on main produces sane output. But ONLY if the
# tag is newer than any tag already reachable from main. Two cases:
#
# (a) Main already has a newer tag (e.g., main is at v2.3.0-dev, release
# branch just tagged v1.0.1): No merge needed. git-describe on main
# already uses the newer tag. Just sanity-check that main is ahead.
#
# (b) The release tag is newer than main's latest tag (e.g., initial release
# from a branch just cut from main): Use a single synthetic merge commit
# that records the tag as an ancestor AND bumps main to -dev:
# tag="$(git describe)"
# next_ver="$(convco version --patch)-dev"
# git checkout main
# git fetch origin main
# git merge --ff-only origin/main # abort if main has diverged
# git diff --quiet && git diff --cached --quiet \
# || { echo >&2 "main is dirty"; exit 1; }
# VERSION_OVERRIDE="$next_ver" task next-version:write
# git add internal/version/version.go
# main_tree="$(git write-tree)"
# c="$(git commit-tree "$main_tree" -p HEAD -p "$tag" \
# -m "merge: record $tag as ancestor & bump to $next_ver")"
# git merge --ff-only "$c"
# The merge commit's tree contains main's content with the -dev bump,
# while its parents link both main and the tag. One commit, no conflicts,
# no misleading diffs. Uses git plumbing — needs good comments.
#
# Defer implementation until we have experience with at least one release branch.
#
desc: commit a version bump, tag, commit version bump
deps: [_have_cargo_tool:convco, release:preflight]
env:
release_version:
sh: task next-version:show
message_prefix: "{{.release_tag_message_prefix}}"
version_file: "{{.version_embedded_file}}"
cmds:
- '[[ -n "${message_prefix:-}" ]] || { echo >&2 "missing message_prefix, Taskfile problem"; exit 70; }'
- task: next-version:write
- 'git commit -o "$version_file" -m "chore: bump hard-coded version to ${release_version}"'
- 'git tag -s -m "${message_prefix} ${release_version#v}" -e "$release_version"'
- task: next-version:write
vars:
VERSION_OVERRIDE: ""
- 'git commit -o "$version_file" -m "chore: bump hard-coded version to $(env VERSION_OVERRIDE="" task next-version:show)"'
_have_cargo_tool:*: # shim for when the binary name == crate name
internal: true
silent: true
cmds:
- task: "_have_cargo_tool_crate:{{index .MATCH 0}}:{{index .MATCH 0}}"
_have_cargo_tool_crate:*:*: # wildcards are: binary name, then crate
internal: true
silent: true
# if: block seems to not succeed when there's a templated index in there
env:
task_exe: "{{.TASK_EXE}}"
want_bin: "{{index .MATCH 0}}"
crate: "{{index .MATCH 1}}"
cmd: |-2
if command -v "$want_bin" >/dev/null 2>&1; then
exit 0 # we have it
fi
echo >&2 "${task_exe}: missing tool '${want_bin}', consider: cargo install --locked ${crate@Q}"
exit 69 # EX_UNAVAILABLE