oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1APP := equipo
2
3# The gate and the release run on one named Go, not whichever release this
4# machine has. govulncheck judges the standard library of the Go doing the
5# scan, and make release builds the binary you ship with it, so a patch
6# release behind is both a red gate and an unpatched binary. go fetches
7# this release through the module proxy on first use. Raise it with
8# each Go security release.
9#
10# A plain =, not ?=: Go's container images set GOTOOLCHAIN=local, and ?=
11# would quietly keep whatever Go they ship. To override for one run:
12# make ci GOTOOLCHAIN=local
13export GOTOOLCHAIN = go1.26.11
14export CGO_ENABLED = 0
15
16# The deployment platform target for a release. Building for your own machine and shipping that is a
17# silent architecture mismatch: the binary uploads fine and fails to exec
18# on the instance. Override for a one-off:
19# make release RELEASE_GOARCH=amd64
20RELEASE_GOOS ?= linux
21RELEASE_GOARCH ?= arm64
22RELEASE_VERSION = $(shell git rev-parse --short HEAD)
23RELEASE_BIN = releases/$(APP)-$(RELEASE_GOOS)-$(RELEASE_GOARCH)-$(RELEASE_VERSION)
24RUNNER_RELEASE_DIR = releases/equipo-runner-linux-amd64-$(RELEASE_VERSION)
25
26# One target at a time, even under make -j: the perf lane measures time,
27# and a suite running beside it would be measured too.
28.NOTPARALLEL:
29
30.PHONY: build release test test-lane ci-shard ci-compile lanes-check test-quarantine vet fmt-check staticcheck govulncheck gitleaks budget perf migration-check runner-adapter-test runner-namespace-test runner-host runner-dead-references ci
31
32RASTRILLO := go run amadan.net/rastrillo/rastrillo/cmd/rastrillo
33
34# build is the compile check: with more than one package matched, go
35# build discards the output, so this catches a broken package without
36# producing an artifact. The runner also builds for a Mac worker
37# (darwin/arm64), so a Linux-only call outside a _linux.go file fails here.
38# The tool proxy is Linux only.
39build:
40 CGO_ENABLED=0 go build ./...
41 CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o /dev/null ./cmd/equipo-runner
42
43# A release is built from one fixed commit in a tree of its own
44# (scripts/release-isolated.sh): a fresh clone at HEAD under $TMPDIR,
45# clean before the build and after it, each binary checked against the
46# commit by its own build information, and only then the provenance
47# manifest. An edit here while it builds cannot reach a binary.
48release:
49 scripts/release-isolated.sh $(RELEASE_GOOS) $(RELEASE_GOARCH)
50
51# release-in-tree is the build itself, run by release in its own tree.
52# Stamp the clean commit so /api/version identifies the running release.
53# Strip debug data to reduce the upload size; keep module build metadata.
54.PHONY: release-in-tree
55release-in-tree: release-runner
56 @test -z "$$(git ls-files --others --exclude-standard)"
57 @git diff --quiet && git diff --cached --quiet || \
58 { echo "refusing to build a release from a dirty tree"; exit 1; }
59 @mkdir -p $(dir $(RELEASE_BIN))
60 scripts/build-instance-release.sh $(RUNNER_RELEASE_DIR) $(RELEASE_BIN) $(RELEASE_GOOS) $(RELEASE_GOARCH) "$$(git rev-parse --short HEAD)"
61 @git rev-parse HEAD > $(RELEASE_BIN).COMMIT
62
63# staged-check is the production gate: it refuses unless the artifacts
64# are the ones this release's build recorded (its provenance manifest,
65# written by make release) and releases/staged records a green staging
66# suite for exactly those bytes.
67.PHONY: staged-check
68staged-check:
69 python3 scripts/staged-artifacts.py check $(RELEASE_VERSION)
70
71# budget size holds each directory to 5,000 source and 8,000 test lines.
72# Past that, split by feature (docs/site/testing.md); a record in
73# .rastrillo/budgets.txt with a reason is the exception, not the fix.
74budget:
75 $(RASTRILLO) budget size
76
77# budget test runs go test itself, so its exit status survives, and
78# reports each package's time against its budget using the time
79# budget.Main prints in the package's TestMain, cached runs included.
80# Timing fails the step only where EQUIPO_CI_DEDICATED=1: on a shared,
81# loaded runner a package's time measures the box, not the change, so
82# there it is reported. go test's own 10-minute limit is set above the
83# longest package budget, so on a loaded runner the budget, not a panic,
84# says which package is slow.
85#
86# Results are cached: a package whose test binary, declared inputs
87# (internal/testci) and environment are unchanged replays its pass, so a
88# rerun after one failure runs only what failed. scripts/ci-test.py
89# lists the packages that must run every time (UNCACHED).
90#
91# test runs every package at once. CI runs the same packages as lanes,
92# shards of .amadan/ci.d/20-check@N side by side: the slow packages split
93# by test name into lanes of about a minute (make test-lane
94# LANE=headless-work runs one; scripts/ci-test.py lanes lists them), with
95# test-quarantine, runner-host and the static checks as further shards.
96# Known flaky tests are quarantined (scripts/ci-quarantine.txt): skipped
97# here and run by test-quarantine. The browser tests (-tags browser) run
98# after the rest, as their own lanes on CI; they need a Chromium
99# (RASTRILLO_CHROME, or one on PATH).
100#
101# A failed test is retried once, in the lane where it failed. A pass on
102# the retry keeps the lane green and prints a FLAKE line (the test, the
103# lane, the commit, how long the failed attempt took, the load average);
104# red means it failed twice. scripts/ci-flakes.py reads those lines back
105# from CI and names the tests that keep flaking.
106test:
107 RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py all
108
109test-lane:
110 RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py lane $(LANE)
111
112ci-shard:
113 RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py shard
114
115# ci-compile compiles every package once, before the shards of 20-check
116# start. Go does not share a compile between processes that start
117# together: 23 shards on an empty cache each compiled the same packages,
118# and every one of them took as long as the whole job used to. After this
119# the shards find their packages, their test packages and the tools the
120# static checks run in the cache: on an empty cache the shards building
121# those side by side held the load near 100 on 32 CPUs, and tests timed
122# out. No test is linked, so with a warm cache it takes a few seconds.
123ci-compile:
124 go build ./...
125 RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py compile
126 go run $(STATICCHECK) -version
127 go run $(GOVULNCHECK) -version
128 go run $(GITLEAKS) version
129
130test-quarantine:
131 python3 scripts/ci-test.py quarantine
132
133# lanes-check fails when the lanes do not run every test exactly once: a
134# lane names a test or package that no longer exists, two lanes take the
135# same test, or a split package has no lane for the tests nobody names.
136# It also holds the shard count of .amadan/ci.d/20-check@N to the lanes.
137# It reads the test files every time, so it runs on CI uncached.
138lanes-check:
139 python3 scripts/ci-test.py check
140
141# The perf lane: every GET screen at 150ms to first byte, cold boot at
142# 500ms. Serial (-p 1 -parallel 1) and uncached (-count=1), because a
143# measurement taken beside other work, or replayed from a cache, is not
144# one. -require fails the lane if the perf tests did not both run.
145perf:
146 $(RASTRILLO) budget test -no-time -require TestPerfScreens,TestPerfBoot -tags perf -count=1 -p 1 -parallel 1 -run '^TestPerf' ./...
147
148vet:
149 go vet ./...
150 go vet -tags testbuild ./internal/runner/thin ./internal/headless
151 GOOS=darwin GOARCH=arm64 go vet ./cmd/equipo-runner/... ./internal/runner/... ./internal/wire/... ./internal/release/...
152
153fmt-check:
154 @out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi
155
156# spacing holds the app's stylesheets to Fiesta's spacing scale: every
157# margin, padding and gap is a var(--rst-sp-N) step, or says why it is
158# not with a /* spacing-allow: why */ comment. tokens.css is rastrillo's,
159# copied byte for byte, so it is not read here. The rhythm audit, its
160# runtime half, is TestBrowserRhythm (internal/thintest).
161.PHONY: spacing
162spacing:
163 go tool fiesta spacing -skip tokens.css internal/equipo/static
164
165# staticcheck catches what vet does not: deprecated APIs, values that are
166# never read, a &*x that looks like a copy and is not.
167#
168# go run with a version, not a tool directive in go.mod. A tool's
169# requirements join the app's own module graph and can move the versions
170# of modules the app shares with it (golang.org/x/tools, which sqlc also
171# needs); go run resolves the tool in a graph of its own. The version is
172# the one rastrillo's own gate runs. Bump it when you raise the go
173# directive: a staticcheck older than your Go does not know that
174# release's deprecations, and says nothing.
175#
176# -tags browser,perf so the browser drive and the perf tests are read
177# too; no file is left out by them, so it covers everything the plain
178# build does.
179STATICCHECK := honnef.co/go/tools/cmd/staticcheck@v0.7.0
180# staticcheck keeps its cache in the user cache directory, ~/.cache,
181# which a sandboxed CI runner mounts read-only: "failed to initialize
182# build cache ... read-only file system". Where the runner hands the job
183# an absolute GOCACHE, staticcheck's goes inside it: writable wherever
184# Go's is, and evicted with it. Anywhere else it stays where staticcheck
185# puts it. Not beside it: a writable GOCACHE says nothing about its
186# parent.
187ifneq ($(filter /%,$(firstword $(GOCACHE))),)
188export STATICCHECK_CACHE ?= $(GOCACHE)/staticcheck
189# The mixed-version test (M8) builds the older release once and keeps it
190# beside the build cache, so later runs do not compile it again.
191export EQUIPO_M8_CACHE ?= $(GOCACHE)/equipo-m8
192endif
193
194staticcheck:
195 go run $(STATICCHECK) -tags browser,perf,testbuild ./...
196
197# govulncheck reports only the vulnerabilities your code can reach: a call
198# path, not a module that merely sits in go.sum. It reads the live
199# vulnerability database, so it can go red with no change here, which is
200# the point of running it on every push. A module finding is fixed by
201# raising that requirement in go.mod; a standard-library one by raising
202# GOTOOLCHAIN above.
203GOVULNCHECK := golang.org/x/vuln/cmd/govulncheck@v1.8.0
204govulncheck:
205 go run $(GOVULNCHECK) ./...
206
207# gitleaks scans every commit, not just the files you have now: a key that
208# was committed and then deleted is still in every clone. It only scans
209# when this directory is the root of its own repository. Before git init
210# there is nothing committed, and an app scaffolded inside somebody else's
211# checkout must not scan theirs. --redact keeps a finding out of CI logs.
212GITLEAKS := github.com/zricethezav/gitleaks/v8@v8.30.1
213gitleaks:
214 @if [ "$$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ] && [ -z "$$(git rev-parse --show-prefix)" ]; then \
215 go run $(GITLEAKS) git --no-banner --redact --log-opts=HEAD .; \
216 else \
217 echo "gitleaks: this directory is not the root of a git repository, so there is nothing committed to scan"; \
218 fi
219
220# Rastrillo v0.30.0's CLI assumes a single internal app directory. The
221# runner protocol is a second package, so call the same dump.Compute API
222# from the app test instead of using CLI package discovery.
223migration-check:
224 CGO_ENABLED=0 go test ./internal/equipo -run '^TestMigrationModels$$' -count=1
225
226runner-prerequisites:
227 python3 scripts/runner-prerequisites.py
228 @test "$$("$${EQUIPO_BWRAP_PATH:-/usr/bin/bwrap}" --version)" = "bubblewrap 0.11.0"
229
230runner-namespace-test:
231 @test "$$(/usr/bin/bwrap --version)" = "bubblewrap 0.11.0"
232 CGO_ENABLED=0 EQUIPO_REQUIRE_USER_SESSION=1 RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py retried runner-host -run '^TestNamespace' -count=1 ./internal/runner/containment
233
234runner-adapter-test: runner-prerequisites
235 CGO_ENABLED=0 RASTRILLO='$(RASTRILLO)' python3 scripts/ci-test.py retried runner-host -run 'TestDirect|TestProvider|TestCheckSandbox' -count=1 ./internal/runner/provider/... ./internal/runner/checks
236
237runner-dead-references:
238 python3 scripts/runner-dead-references.py
239 python3 native/scripts/check-share.py
240
241# runner-host checks the machine the tests run on, not only the code: the
242# exact bubblewrap build, the pinned Codex program, real namespaces, and a
243# process moved between two delegated cgroups. Uncached, every time. On
244# hosted CI the machine is the CI box (scripts/ci-box.py), which is made
245# to pass for a runner host. Its tests have the same one retry as the
246# lanes (scripts/ci-test.py retried).
247runner-host: runner-adapter-test runner-namespace-test
248
249# ci is the one gate: what a runner executes and what you run before
250# pushing are the same definition. amadan's runner falls back to this
251# target when .amadan/ci is absent; ci.d/ carries the same targets,
252# reported one by one, for a runner with step support. migration-check
253# fails the build the moment models.go and migrations/ disagree,
254# instead of at boot on whatever machine notices next. If the app
255# declares manifest resources, also add: rastrillo generate --check
256ci: copy-release-check runner-dead-references lanes-check build vet fmt-check spacing staticcheck govulncheck gitleaks budget test test-quarantine runner-host migration-check perf
257
258.PHONY: copy-release-check direct-release-check release-runner runner-prerequisites
259copy-release-check:
260 EQUIPO_RELEASE_COPY_CHECK=1 CGO_ENABLED=0 go test ./internal/equipotest -run '^TestReleaseCopyReviewed$$' -count=1
261
262# The programs this repository does not build (claude, codex, its code
263# mode host, bwrap) are pinned by digest in internal/release/manifest.json
264# and in the provider packages; a release needs both, and the installed
265# programs, to agree.
266direct-release-check:
267 python3 scripts/runner-release-check.py
268
269# What protects a release is where its bytes came from: a clean tree at one
270# commit, built by the Go named above. The tool proxy is built first and
271# its SHA-256 is linked into both runners and the instance
272# (internal/release toolProxySHA256), so a runner installs, and an instance
273# serves, only the tool proxy of its own build. Nothing here is typed in
274# after a live run, so raising GOTOOLCHAIN needs no one's sign-off. Every
275# binary carries its commit (go version -m), the tool proxy too.
276TOOL_PROXY_SHA256 = $$(sha256sum $(RUNNER_RELEASE_DIR)/equipo-tool-proxy | cut -d ' ' -f 1)
277GITLEAKS_SHA256 = $$(sha256sum $(RUNNER_RELEASE_DIR)/gitleaks | cut -d ' ' -f 1)
278# The renderer tree (scripts/build-renderer-tree.py, from the pinned debs
279# of internal/release/renderer.json) is named by its MANIFEST: that
280# digest is linked into the Linux runner as gitleaks' is, and recorded in
281# the install manifest's Linux target. A Mac runner has no renderer.
282RENDERER_SHA256 = $$(tar -xzOf $(RUNNER_RELEASE_DIR)/renderer.tar.gz MANIFEST | sha256sum | cut -d ' ' -f 1)
283# The archive itself is not in the instance (it would pass the platform's
284# 256 MiB ship cap): the Linux runner fetches it from its forge release,
285# renderer-<first 12 of its SHA-256> (internal/release RendererForge), and
286# checks its digest and size, linked here from the same file. A withdrawn
287# release's bytes are published again as renderer-<12>-<RENDERER_REVISION>
288# (r2, r3, ...): set it for that build. scripts/publish-renderer.sh
289# publishes the kit's archive and SOURCES under the linked tag.
290RENDERER_ARCHIVE_SHA256 = $$(sha256sum $(RUNNER_RELEASE_DIR)/renderer.tar.gz | cut -d ' ' -f 1)
291RENDERER_ARCHIVE_SIZE = $$(stat -c %s $(RUNNER_RELEASE_DIR)/renderer.tar.gz)
292RENDERER_REVISION ?=
293RENDERER_TAG = renderer-$$(sha256sum $(RUNNER_RELEASE_DIR)/renderer.tar.gz | cut -c 1-12)$(if $(RENDERER_REVISION),-$(RENDERER_REVISION))
294RELEASE_LDFLAGS = -s -w -X amadan.net/rastrillo/rastrillo.BuildVersion=$$(git rev-parse --short HEAD) -X amadan.net/oficina/equipo/internal/release.toolProxySHA256=$(TOOL_PROXY_SHA256)
295
296release-runner: copy-release-check direct-release-check
297 @test -z "$$(git ls-files --others --exclude-standard)"
298 @git diff --quiet && git diff --cached --quiet || exit 1
299 @$(MAKE) --no-print-directory runner-prerequisites
300 @mkdir -p $(RUNNER_RELEASE_DIR)
301 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod=readonly -trimpath -o $(abspath $(RUNNER_RELEASE_DIR))/gitleaks github.com/zricethezav/gitleaks/v8
302 @mkdir -p $(RUNNER_RELEASE_DIR)/darwin-arm64
303 CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -mod=readonly -trimpath -o $(abspath $(RUNNER_RELEASE_DIR))/darwin-arm64/gitleaks github.com/zricethezav/gitleaks/v8
304 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" -o $(RUNNER_RELEASE_DIR)/equipo-tool-proxy ./cmd/equipo-tool-proxy
305 python3 scripts/build-renderer-tree.py internal/release/renderer.json $(RUNNER_RELEASE_DIR)/renderer.tar.gz
306 CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath \
307 -ldflags "$(RELEASE_LDFLAGS) -X amadan.net/oficina/equipo/internal/release.gitleaksSHA256=$(GITLEAKS_SHA256) -X amadan.net/oficina/equipo/internal/release.rendererSHA256=$(RENDERER_SHA256) -X amadan.net/oficina/equipo/internal/release.rendererArchiveSHA256=$(RENDERER_ARCHIVE_SHA256) -X amadan.net/oficina/equipo/internal/release.rendererArchiveSize=$(RENDERER_ARCHIVE_SIZE) -X amadan.net/oficina/equipo/internal/release.rendererTag=$(RENDERER_TAG)" \
308 -o $(RUNNER_RELEASE_DIR)/equipo-runner ./cmd/equipo-runner
309 scripts/no-fake-worker.sh $(RUNNER_RELEASE_DIR)/equipo-runner
310 @mkdir -p $(RUNNER_RELEASE_DIR)/darwin-arm64
311 CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -trimpath \
312 -ldflags "$(RELEASE_LDFLAGS) -X amadan.net/oficina/equipo/internal/release.gitleaksSHA256=$$(sha256sum $(RUNNER_RELEASE_DIR)/darwin-arm64/gitleaks | cut -d ' ' -f 1)" \
313 -o $(RUNNER_RELEASE_DIR)/darwin-arm64/equipo-runner ./cmd/equipo-runner
314 scripts/no-fake-worker.sh $(RUNNER_RELEASE_DIR)/darwin-arm64/equipo-runner
315 cp packaging/equipo-runner.service internal/release/manifest.json $(RUNNER_RELEASE_DIR)/
316 cp packaging/install/install-v1.sh $(RUNNER_RELEASE_DIR)/install-v1.sh
317 python3 scripts/runner-install-manifest.py $(RUNNER_RELEASE_DIR) "$$(git rev-parse --short HEAD)"
318 @git rev-parse HEAD > $(RUNNER_RELEASE_DIR)/COMMIT
319
320.PHONY: e2e-live
321e2e-live:
322 CGO_ENABLED=0 go test ./internal/runner/provider -run '^Test(Refresh|SourceRefresh)' -count=1
323 EQUIPO_E2E_LIVE=1 go test -tags e2elive,browser ./internal/e2elivetest -run '^TestCoordinatorE2ELive$$' -count=1 -timeout=10m -v
324