Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
356 lines (330 loc) · 16.5 KB
/
Copy pathTaskfile.yml
File metadata and controls
356 lines (330 loc) · 16.5 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
# spin-machine — a virtual machine: QEMU, the guest kernel, the base image, and the
# definition of the machine they make.
#
# The command is spin-machine-dev (cmd/spin-machine-dev; spin-machine-dev --help): a person builds,
# verifies, boots, releases and keeps the pins with its verbs, and a workflow composes the same
# verbs, a step each (docs/cli.md). `task bin` puts it in _output/bin.
#
# This file is go-tools' gates and CI's plumbing: test, lint, mutate and coverage; the tasks
# go-tools writes once for every repository (the common include below); bin, the release app's
# git (git:app), and the probes' (boot/ and the lab's targets), which boot what the verbs built.
# `task <name>` is go-tools' task command, installed outside go.mod (`go install
# github.com/spin-stack/go-tools/cmd/task@latest` once; spin-stack/go-tools' action in CI): the
# Task versions.yaml pins, with the latest go-tools release's commands on its PATH.
#
# What is deliberately NOT here: the software that runs inside a guest. This repository
# builds a machine and knows nothing about what boots on it, and there is no exception to
# that. A debug initramfs is the one that keeps being proposed: it is a second init, doing
# what the init a consumer already brings does, and the machine boots straight into
# /sbin/init without one.
version: '3'
silent: true
output: prefixed
includes:
# versions, bump, release, lint:workflows and consumers, as every spin-stack repository has
# them: go-tools' own file, which its task command names. RELEASE says how this repository is
# released, and release refuses with it: release.yml builds, signs and tags with
# spin-machine-dev release, and the common task would publish a tag with no tarball.
common:
taskfile: '{{.GO_TOOLS_TASKS}}'
flatten: true
vars:
RELEASE:
map: {elsewhere: release.yml}
boot:
taskfile: boot/Taskfile.yml
dir: '{{.ROOT_DIR}}'
vars:
ROOT_DIR:
sh: pwd
OUTPUT_DIR: '{{.OUTPUT_DIR | default "_output"}}'
# The same directory, absolute, resolved once.
#
# Everything handed to `docker -v`, to a VM, or to a checksum has to be an absolute path,
# and `{{.OUTPUT_ABS}}` is only one when OUTPUT_DIR is relative. With
# OUTPUT_DIR=/tmp/build it produced <repository>/tmp/build, so QEMU and the kernel were
# extracted to /tmp/build and the base image was written somewhere else entirely — a
# build that succeeds and leaves half its output where nothing looks for it.
#
# -m so an output directory that does not exist yet still resolves.
OUTPUT_ABS:
sh: realpath -m "{{.OUTPUT_DIR}}"
SPIN_MACHINE_DEV: '{{.ROOT_DIR}}/_output/bin/spin-machine-dev'
tasks:
default:
cmds:
- '{{.TASK_EXE}} --list'
bin:
desc: Build spin-machine-dev into _output/bin/.
# Once per run: several steps depend on it in parallel, and one rebuilding it while another
# runs it is "text file busy". No sources: an up-to-date task runs no command, and the PATH
# line below has to run in every job; go build relinks nothing that is current.
run: once
cmds:
- go build -o {{.SPIN_MACHINE_DEV}} ./cmd/spin-machine-dev
# A workflow's later steps run spin-machine-dev by name: go run would flatten its exit
# status to 1, and a step branches on 0, 1 and 2 (docs/cli.md).
- if [ -n "${GITHUB_PATH:-}" ]; then dirname {{.SPIN_MACHINE_DEV}} >> "$GITHUB_PATH"; fi
dev:
desc: spin-machine-dev with go-tools' commands on its PATH, which outdated, bump and refresh run versions from (task dev -- bump qemu).
deps: [bin]
cmds:
- '{{.SPIN_MACHINE_DEV}} {{.CLI_ARGS}}'
pin:
desc: The version versions.yaml pins for NAME, said and, in a workflow, the step's output `version`, for an action that installs it (task pin NAME=cosign).
requires:
vars: [NAME]
cmds:
- |
v=$(versions version {{.NAME}})
echo "$v"
if [ -n "${GITHUB_OUTPUT:-}" ]; then echo "version=$v" >> "$GITHUB_OUTPUT"; fi
# The probes' (boot/) spin-machine, which every one of them boots with: the verb, under the
# name their targets depend on.
tools:
internal: true
deps: [bin]
cmds:
- '{{.SPIN_MACHINE_DEV}} --out {{.OUTPUT_ABS}} build spin-machine'
trace:
desc: Where a workflow run's time went - the Job Summary, trace.html and trace.json in _output/ghatrace (go-tools' ghatrace, release.yml's last job).
cmds:
- ghatrace run -out {{.OUTPUT_ABS}}/ghatrace
# spin-stack/ship-it reads the releases here and dispatches what follows one (spin's machine
# proposal). GitHub's schedule does not wake it (its */5 ran 3 of 576 in 48 h), so the run that
# made the release does. A hint: ship-it reads the state itself, and its hourly cron catches a
# wake that was lost.
ship-it:wake:
desc: Wake spin-stack/ship-it with this run and its CONCLUSION (GH_TOKEN, the release app's on ship-it; release.yml's last job).
requires:
vars: [CONCLUSION]
cmds:
- |
set -euo pipefail
workflow=${GITHUB_WORKFLOW_REF%@*}
gh api repos/spin-stack/ship-it/dispatches -f event_type=wake \
-f "client_payload[repository]=${GITHUB_REPOSITORY}" \
-f "client_payload[workflow]=${workflow##*/}" \
-f "client_payload[run]=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" \
-f "client_payload[conclusion]=${CONCLUSION}"
vsock:
desc: spin-machine-dev vsock, for the probes and the lab (lab.yml and report.yml run it by this name).
deps: [bin]
cmds:
- '{{.SPIN_MACHINE_DEV}} vsock'
graphviz:
desc: graphviz's dot, which draws the bootchart probe's ordering graph (lab.yml runs it by this name); the probe keeps the graph as dot without it.
status:
- command -v dot
cmds:
- sudo apt-get update -q
- sudo apt-get install -y -q graphviz
patched-build-deps:
desc: What `spin-machine-dev patched prepare` and `compile` need to compile the kernel's and QEMU's touched files (codeql.yml runs it by this name).
cmds:
- sudo apt-get update -q
- sudo apt-get install -y -q --no-install-recommends bc bison flex libelf-dev libssl-dev dwarves ninja-build libglib2.0-dev libpixman-1-dev python3-venv
sanitize-deps:
desc: What `spin-machine-dev patched sanitized` and `patched fuzzer` need to build QEMU on this host (sanitize.yml runs it by this name).
cmds:
- sudo apt-get update -q
# No clang: patched fuzzer builds with versions.yaml's llvm, which it fetches and zstd unpacks.
- sudo apt-get install -y -q --no-install-recommends build-essential zstd ninja-build python3-venv pkg-config libglib2.0-dev libpixman-1-dev libaio-dev liburing-dev libcap-ng-dev libseccomp-dev
sanitized:
desc: >-
QEMU's patched tree built under ASan and UBSan with the release's configuration (spin-machine-dev
patched sanitized), its directory and the sanitizers' options exported to the steps after in
CI. Needs the release's firmware in _output/qemu (spin-machine-dev fetch qemu).
deps: [bin]
cmds:
- '{{.SPIN_MACHINE_DEV}} patched tree qemu'
- '{{.SPIN_MACHINE_DEV}} patched sanitized >> "${GITHUB_ENV:-/dev/stdout}"'
qemu-fuzz:
desc: >-
QEMU's generic-fuzz over a virtio-scsi controller with qemu/patches/0002's max_target at
spin's 15 and a disk at target 3, for FUZZTIME seconds (default 1800), under ASan and UBSan
(spin-machine-dev patched fuzzer). A crash leaves its input in _output/patched/qemu/crashes;
spin-machine-dev patched reports names it.
vars:
FUZZTIME: '{{.FUZZTIME | default "1800"}}'
CRASHES: '{{.OUTPUT_ABS}}/patched/qemu/crashes'
deps: [bin]
cmds:
- '{{.SPIN_MACHINE_DEV}} patched tree qemu'
- '{{.SPIN_MACHINE_DEV}} patched fuzzer > {{.OUTPUT_ABS}}/patched/qemu/fuzzer.env'
- |
set -euo pipefail
set -a; . {{.OUTPUT_ABS}}/patched/qemu/fuzzer.env; set +a
mkdir -p {{.CRASHES}}
QEMU_FUZZ_ARGS='-machine q35 -nodefaults -device virtio-scsi-pci,id=scsi0,num_queues=8,max_target=15 -device scsi-hd,drive=disk0,bus=scsi0.0,scsi-id=3 -drive file=null-co://,id=disk0,if=none,format=raw' \
QEMU_FUZZ_OBJECTS='scsi* virtio*' \
"$SPIN_FUZZER" --fuzz-target=generic-fuzz -max_total_time={{.FUZZTIME}} -artifact_prefix={{.CRASHES}}/
test:
desc: Test the machine definition, under the race detector, with its coverage in coverage.out and held to a floor.
vars:
# Below today's number, of the statements CI can run: a function marked `mutate-lane:` is
# held by a test that needs root and KVM, and go-tools' coverfloor leaves it out by mutate's
# own reading of the marker (#410, #496). 93.36% on 2026-11-22, 80.65% with the lane's 1601 statements counted. Raise
# it when the number has moved up and stayed; never lower it to let a change through, or it
# is a gate that reports whatever it is given.
COVERAGE_FLOOR: 93
# No release tree, as CI has none when it runs this: the tests that ask for a QEMU skip, and
# a checkout that has one built gives CI's verdict and CI's coverage, not a point more
# (09-28's floor broke main that way). `spin-machine-dev verify args` is where they run. The
# boot/ Taskfile's own SPIN_MACHINE_OUTPUT reaches every task, and this one wins over it.
env:
SPIN_MACHINE_OUTPUT: /nonexistent
cmds:
# A test writes into a directory of its own, never the checkout's _output: a developer's
# checkout has one and CI's has none, so a test that used it gave a different verdict on
# each (#413). Only a checkout with none, as CI's is here, sees one made.
- |
set -eu
had=$([ -e _output ] && echo yes || echo no)
go test -race -covermode=atomic -coverprofile=coverage.out ./...
if [ "$had" = no ] && [ -e _output ]; then
echo "a test wrote into the checkout's _output; give it a directory of its own:" >&2
find _output >&2
exit 1
fi
- coverfloor {{.COVERAGE_FLOOR}} coverage.out
fuzz:
desc: >-
Each Go fuzz target (func FuzzX: what the machine parses from outside, a checkpoint's record
and QMP's replies, #653) for FUZZTIME (default 60s) each. A failing input is written to the
package's testdata/fuzz, where go test runs it from then on: commit it with the fix.
vars:
FUZZTIME: '{{.FUZZTIME | default "60s"}}'
env:
SPIN_MACHINE_OUTPUT: /nonexistent
cmds:
# The targets are found, not listed: a list is how one goes missing. Minimizing an input
# that adds coverage takes up to a minute by default, which a bounded run spends idle.
- |
set -eu
go test -list '^Fuzz' ./... | awk '/^Fuzz/ { t[n++] = $1 } /^ok / { for (i = 0; i < n; i++) print $2, t[i]; n = 0 }' > "${TMPDIR:-/tmp}/fuzz-targets"
[ -s "${TMPDIR:-/tmp}/fuzz-targets" ] || { echo "no fuzz targets found" >&2; exit 1; }
while read -r pkg target; do
echo "== $pkg $target"
go test -run '^$' -fuzz "^$target\$" -fuzztime {{.FUZZTIME}} -fuzzminimizetime 5s "$pkg"
done < "${TMPDIR:-/tmp}/fuzz-targets"
lint:
desc: >-
Everything CI checks that is not a build: formatting, vet, the Taskfiles parse, every
shell script is syntactically valid, and go-tools' gates over the Go and the prose.
cmds:
- |
set -euo pipefail
unformatted=$(gofmt -l machine qmp cmd boot internal gates)
if [ -n "$unformatted" ]; then
echo "not gofmt'd:"; echo "$unformatted"; exit 1
fi
echo "OK: gofmt"
- go vet ./...
- cmd: 'echo "OK: go vet"'
# `task --list` parses every included Taskfile, so a syntax error or a name defined
# twice fails here rather than in whichever lane first called it.
- '{{.TASK_EXE}} --list > /dev/null'
- cmd: 'echo "OK: the Taskfiles parse"'
- |
set -euo pipefail
for f in image/build.sh image/mkosi.postinst.chroot \
image/mkosi.extra/usr/local/lib/spin-base/*.sh boot/testdata/*.sh internal/shirudo/*.sh; do
bash -n "$f" || { echo "$f does not parse" >&2; exit 1; }
done
echo "OK: the shell scripts parse"
# go-tools' gates, of its latest release: every goroutine held to a context, no test
# that cannot fail, every path and task AGENTS.md and CLAUDE.md name resolves, every
# mutate-exempt reason covers an edit mutate makes, every workflow step is one task or one
# invocation of spin-machine-dev - the verbs a person types, on a job's PATH by the bin task
# (docs/cli.md) - and pnpm is the one package manager, installing through Socket Firewall.
- ctxlife
- testquality ./...
- refs
- mutate -stale-exempts
# The Task running this one, which taskgate asks for the task names a workflow step runs.
- taskgate -common -allow .github/taskgate-allow.txt -task {{.TASK_EXE}} -command spin-machine-dev
- sfw check
- task: lint:workflows
mutate:
desc: >-
Break what the change against BASE touched and fail on an edit no test refuses
(task mutate BASE=origin/main, the default). In CI the base is what the change is to: a
pull request's target branch, or on a push what the push replaced (BEFORE).
# As test's: the verdict is CI's, whatever this checkout has built.
env:
SPIN_MACHINE_OUTPUT: /nonexistent
cmds:
- |
set -euo pipefail
base='{{.BASE}}'
if [ -z "$base" ] && [ "${GITHUB_ACTIONS:-}" = true ]; then
if [ "$GITHUB_EVENT_NAME" = pull_request ]; then
base="origin/$GITHUB_BASE_REF"
else
base="${BEFORE:-}"
fi
# A push that created its branch has no commit before it.
git rev-parse --verify "$base^{commit}" >/dev/null 2>&1 || base=HEAD~1
fi
mutate -base "${base:-origin/main}" -max 2000
coverage:
desc: >-
What `task test` covered, function by function: on the run's summary in CI, on stdout
here, and as coverage.html.
cmds:
- |
set -e
summary=${GITHUB_STEP_SUMMARY:-/dev/stdout}
if [ ! -f coverage.out ]; then
echo "coverage.out was not produced; the tests may have failed before coverage ran." >> "$summary"
exit 0
fi
{
echo "## Go coverage"
echo
echo "**$(go tool cover -func=coverage.out | awk '/^total:/ {print $3}')** total"
echo
echo '<details><summary>Function detail</summary>'
echo
echo '```'
go tool cover -func=coverage.out
echo '```'
echo '</details>'
} >> "$summary"
go tool cover -html=coverage.out -o coverage.html
# Measuring is spin-machine-dev lab (docs/cli.md); these build it and run it. Built rather than
# go run, which flattens a verb's exit status to 1, and a lost measurement (1) is not a lab that
# could not run (2).
lab:
desc: spin-machine-dev lab with the arguments after --, e.g. `task lab -- run ssh-first --tree 'r=--from release'`.
cmds:
- go build -o {{.OUTPUT_ABS}}/bin/spin-machine-dev ./cmd/spin-machine-dev
- '{{.OUTPUT_ABS}}/bin/spin-machine-dev lab {{.CLI_ARGS}}'
lab:ci:
desc: >-
lab.yml's experiment from the job's PROBE, TREES, REPS and OPTIONS: a probe run over the trees
into _output/lab/result, or check:TARGET, boot:TARGET on the first tree.
cmds:
- go build -o {{.OUTPUT_ABS}}/bin/spin-machine-dev ./cmd/spin-machine-dev
- |
case "$PROBE" in
check:*) {{.OUTPUT_ABS}}/bin/spin-machine-dev lab check "${PROBE#check:}" --tree "$TREES" ;;
*) {{.OUTPUT_ABS}}/bin/spin-machine-dev lab run "$PROBE" --tree "$TREES" --reps "$REPS" --opt "$OPTIONS" --out _output/lab/result ;;
esac
# A pull request opened with a workflow run's own token starts no checks; one the release app
# (spin-stack-release) opens does, and parts.yml is the check a kernel bump needs.
git:app:
desc: Make git commit and push as the GitHub App whose token is GH_TOKEN (APP_SLUG= its slug) - a workflow's step, as it writes git's global configuration.
requires:
vars: [APP_SLUG]
preconditions:
- sh: test -n "${GITHUB_ACTIONS:-}"
msg: git:app rewrites git's global user and credentials; it is for a workflow's runner, not this machine
cmds:
- |
set -e
gh auth setup-git
id=$(gh api "/users/{{.APP_SLUG}}[bot]" --jq .id)
git config --global user.name "{{.APP_SLUG}}[bot]"
git config --global user.email "${id}+{{.APP_SLUG}}[bot]@users.noreply.github.com"