oficina / slides Public

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

Plain git — no account needed to clone.

Download

Download this file

1export GOTOOLCHAIN := go1.26.5
2export GOPRIVATE := $(GOPRIVATE),amadan.net/oficina/estilo.git
3
4APP := slides
5
6# What `carlos ship -target` defaults to, and therefore what a release
7# must be built for. Building for your own machine and shipping that is a
8# silent architecture mismatch: the binary uploads fine and fails to exec
9# on the instance. Override for a one-off:
10# make release RELEASE_GOARCH=amd64
11RELEASE_GOOS ?= linux
12RELEASE_GOARCH ?= arm64
13RELEASE_BIN := releases/$(APP)-$(RELEASE_GOOS)-$(RELEASE_GOARCH)
14
15# What the running binary reports from GET /api/version. The platform's
16# deploy verification polls that endpoint on every instance socket and
17# compares what it finds against the release it believes it adopted; an
18# unstamped binary answers "dev" from every build you have ever made, so
19# those two facts can never disagree and a process that was never
20# recycled onto the new release verifies green. Stamping this is what
21# gives that check the ability to fail.
22#
23# git describe, because the tag is what you ship against. Outside a
24# repository, or before the first commit, name it yourself:
25# make release VERSION=v0.1.0
26VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null)
27
28.PHONY: build release version-check test vet fmt-check migration-check ci
29
30# build is the compile check: with more than one package matched, go
31# build discards the output, so this catches a broken package without
32# producing an artifact.
33build:
34 CGO_ENABLED=0 go build ./...
35
36# release is what ships. -s -w drops the symbol table and DWARF, which on
37# this family's apps is 23-31% off the binary and 45-53% off the
38# compressed artifact — and compressed size is what actually gets
39# transferred. carlos is built the same way (see platform's Makefile).
40#
41# What survives: panic traces keep their function names AND line numbers
42# (Go's pclntab is untouched by these flags), debug.ReadBuildInfo works,
43# and go version -m still reports module metadata. What you lose is
44# source-level debugging with delve or gdb — build without the flags for
45# that. rastrillo dev never strips, for the same reason.
46release: version-check
47 @mkdir -p releases
48 CGO_ENABLED=0 GOOS=$(RELEASE_GOOS) GOARCH=$(RELEASE_GOARCH) \
49 go build -ldflags="-s -w -X 'amadan.net/rastrillo/rastrillo.BuildVersion=$(VERSION)'" \
50 -o $(RELEASE_BIN) ./cmd/$(APP)
51 @echo
52 @echo "built $(RELEASE_BIN) reporting version $(VERSION)"
53 @echo "ship it with:"
54 @echo " carlos ship -app $(APP) -target $(RELEASE_GOOS)-$(RELEASE_GOARCH) $(RELEASE_BIN)"
55
56# version-check refuses rather than letting release ship a binary whose
57# version is untrue. Both refusals are about the same thing: /api/version
58# is only evidence if the answer identifies one artifact.
59#
60# An empty stamp is worse than the "dev" default, because "dev" is
61# saying something true about itself and "" looks like a value that
62# arrived from somewhere.
63#
64# A dirty tree is refused rather than suffixed. A -dirty stamp names a
65# commit plus changes nobody can name, so two different binaries can
66# carry the identical string — which does not fix the check, it makes
67# it look reliable while it is not, and that is the more expensive
68# failure. Refusing costs one `git stash`; a wrong stamp ships. If you
69# mean to ship uncommitted work, say so out loud:
70# make release VERSION=v0.1.0-wip
71version-check:
72 @if [ -z "$(VERSION)" ]; then \
73 echo "make release: no version to stamp."; \
74 echo " git describe found nothing here: no repository, or no commit yet."; \
75 echo " Commit, or name it: make release VERSION=v0.1.0"; \
76 exit 1; \
77 fi
78 @case "$(VERSION)" in *-dirty) \
79 echo "make release: the tree is dirty, so $(VERSION) does not name what you are about to ship."; \
80 echo " Commit or stash first, or name it: make release VERSION=v0.1.0-wip"; \
81 exit 1;; \
82 esac
83
84test:
85 go test ./...
86
87vet:
88 go vet ./...
89
90fmt-check:
91 @out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi
92
93# A step of its own, not folded into another target's recipe: ci.d/
94# steps each exec one make target, so migration-check needs its own
95# name to get its own reported step on a runner with step support.
96#
97# go run, not a bare "rastrillo": go.mod already requires rastrillo, so
98# this needs nothing on PATH but the Go toolchain, and works offline
99# after go mod download. A bare "rastrillo migration check" failed a
100# fresh clone's very first CI run with "make: rastrillo: Command not
101# found", and nothing in the scaffold said what to install.
102#
103# What makes the go run resolve is the tool directive at the foot of
104# go.mod — it is what keeps the CLI's own dependencies in go.sum. See
105# the comment there before removing it.
106migration-check:
107 go run amadan.net/rastrillo/rastrillo/cmd/rastrillo migration check
108
109# ci is the one gate: what a runner executes and what you run before
110# pushing are the same definition. amadan's runner falls back to this
111# target when .amadan/ci is absent; ci.d/ carries the same targets,
112# reported one by one, for a runner with step support. migration-check
113# fails the build the moment models.go and migrations/ disagree,
114# instead of at boot on whatever machine notices next. If the app
115# declares manifest resources, also add: rastrillo generate --check
116ci: vet fmt-check test migration-check
117
118.PHONY: credits credits-check
119credits:
120 python3 scripts/credits.py
121
122credits-check:
123 python3 scripts/credits.py --check
124
125ci: credits-check
126