| 1 | export GOTOOLCHAIN := go1.26.5 |
| 2 | export GOPRIVATE := $(GOPRIVATE),amadan.net/oficina/estilo.git |
| 3 | |
| 4 | APP := memoria |
| 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 |
| 11 | RELEASE_GOOS ?= linux |
| 12 | RELEASE_GOARCH ?= arm64 |
| 13 | RELEASE_BIN := releases/$(APP)-$(RELEASE_GOOS)-$(RELEASE_GOARCH) |
| 14 | |
| 15 | .PHONY: build release deps test vet fmt-check migration-check ci browser |
| 16 | |
| 17 | # build is the compile check: with more than one package matched, go |
| 18 | # build discards the output, so this catches a broken package without |
| 19 | # producing an artifact. |
| 20 | build: |
| 21 | CGO_ENABLED=0 go build ./... |
| 22 | |
| 23 | # release is what ships. -s -w drops the symbol table and DWARF, which on |
| 24 | # this family's apps is 23-31% off the binary and 45-53% off the |
| 25 | # compressed artifact — and compressed size is what actually gets |
| 26 | # transferred. carlos is built the same way (see platform's Makefile). |
| 27 | # |
| 28 | # What survives: panic traces keep their function names AND line numbers |
| 29 | # (Go's pclntab is untouched by these flags), debug.ReadBuildInfo works, |
| 30 | # and go version -m still reports module metadata. What you lose is |
| 31 | # source-level debugging with delve or gdb — build without the flags for |
| 32 | # that. rastrillo dev never strips, for the same reason. |
| 33 | # The scaffold's release target stamped no version and did not refuse a |
| 34 | # dirty tree. Both matter: rastrillo.BuildVersion defaults to "dev", and |
| 35 | # an unstamped binary answers "dev" from /api/version forever — which |
| 36 | # makes the deploy check structurally incapable of failing, since the |
| 37 | # thing it compares can never disagree. |
| 38 | # |
| 39 | # The stamp was a short sha because there were no tags to describe. Now |
| 40 | # that a release IS a tag, git describe --tags --always answers with the |
| 41 | # tag when the build sits on one and falls back to the same short sha |
| 42 | # when it does not — so the reasoning above is unchanged, and a |
| 43 | # published binary reports the name it was published under. |
| 44 | VERSION ?= $(shell git describe --tags --always 2>/dev/null) |
| 45 | |
| 46 | release: |
| 47 | @git diff --quiet && git diff --cached --quiet || \ |
| 48 | { echo "refusing to build a release from a dirty tree"; exit 1; } |
| 49 | @test -n "$(VERSION)" || \ |
| 50 | { echo "make release: no version to stamp; commit, or name it: make release VERSION=v0.1.0"; exit 1; } |
| 51 | @mkdir -p releases |
| 52 | CGO_ENABLED=0 GOOS=$(RELEASE_GOOS) GOARCH=$(RELEASE_GOARCH) go build -trimpath \ |
| 53 | -ldflags "-s -w -X amadan.net/rastrillo/rastrillo.BuildVersion=$(VERSION)" \ |
| 54 | -o $(RELEASE_BIN) ./cmd/$(APP) |
| 55 | @echo "built $(RELEASE_BIN) reporting version $(VERSION)" |
| 56 | @echo "deploy it with:" |
| 57 | @echo " carlos deploy --app $(APP) --account bds --channel edge --timeout 5m $(RELEASE_BIN)" |
| 58 | @echo "publish it with:" |
| 59 | @echo " amadan release create -repo oficina/$(APP) -notes-file NOTES.md $(VERSION) $(RELEASE_BIN)" |
| 60 | |
| 61 | test: |
| 62 | go test ./... |
| 63 | |
| 64 | # deps makes sure the module cache holds what go.sum says, and repairs it |
| 65 | # when it does not. The CI runner's cache held an extracted |
| 66 | # amadan.net/rastrillo/rastrillo whose embedded files (locales/*.toml, |
| 67 | # migrations/*.sql, ui/calendar.js) were missing, so vet failed with |
| 68 | # "pattern ...: no matching files found" while the same commit passed |
| 69 | # here (Calendar met it first, oficina/calendar#26). `go mod verify` |
| 70 | # names such a directory as "dir has been modified"; deleting it lets |
| 71 | # `go mod download` extract it again from the checksummed zip. |
| 72 | deps: |
| 73 | @go mod download |
| 74 | @out=$$(go mod verify 2>&1) || { \ |
| 75 | echo "$$out"; \ |
| 76 | echo "$$out" | sed -n 's/.*: dir has been modified (\(.*\))$$/\1/p' | while read -r dir; do \ |
| 77 | echo "deps: re-extracting $$dir"; chmod -R u+w "$$dir" && rm -rf "$$dir"; \ |
| 78 | done; \ |
| 79 | go mod download && go mod verify; \ |
| 80 | } |
| 81 | |
| 82 | # Also vets the browser-tagged tests: they are outside `make ci`, and a |
| 83 | # test behind a tag that nothing compiles rots silently. |
| 84 | vet: deps |
| 85 | go vet ./... |
| 86 | go vet -tags browser ./internal/memoriatest/ |
| 87 | |
| 88 | fmt-check: |
| 89 | @out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi |
| 90 | |
| 91 | # A step of its own, not folded into another target's recipe: ci.d/ |
| 92 | # steps each exec one make target, so migration-check needs its own |
| 93 | # name to get its own reported step on a runner with step support. |
| 94 | # |
| 95 | # go tool, not a bare "rastrillo": go.mod pins the CLI as a tool at the |
| 96 | # module's own version, so this needs nothing on PATH but the Go |
| 97 | # toolchain, works offline after go mod download, and always runs the |
| 98 | # migrate the app is built against. A bare "rastrillo migration check" |
| 99 | # failed a fresh clone's very first CI run with "make: rastrillo: |
| 100 | # Command not found", and nothing in the scaffold said what to install. |
| 101 | migration-check: |
| 102 | go tool rastrillo migration check |
| 103 | |
| 104 | # ci is the one gate: what a runner executes and what you run before |
| 105 | # pushing are the same definition. amadan's runner falls back to this |
| 106 | # target when .amadan/ci is absent; ci.d/ carries the same targets, |
| 107 | # reported one by one, for a runner with step support. migration-check |
| 108 | # fails the build the moment models.go and migrations/ disagree, |
| 109 | # instead of at boot on whatever machine notices next. If the app |
| 110 | # declares manifest resources, also add: rastrillo generate --check |
| 111 | ci: vet fmt-check test migration-check |
| 112 | |
| 113 | # The browser checks (internal/memoriatest/*_browser_test.go), in a real |
| 114 | # Chromium through chromedp. Deliberately NOT part of `ci`: the gate |
| 115 | # every push runs must not need a browser. Run it before shipping a |
| 116 | # change to the CSS or to rastrillo's pin; TestNoZoomOnTap is the iOS |
| 117 | # zoom-on-tap check, and TestPagesRenderUnderTheProductionCSP is the one |
| 118 | # browser check served through rastrillo's production stack, so it sees |
| 119 | # the real CSP. The Chromium comes from RASTRILLO_CHROME, or on a |
| 120 | # Mac from the Playwright cache. |
| 121 | RASTRILLO_CHROME ?= $(firstword $(wildcard $(HOME)/Library/Caches/ms-playwright/chromium-*/chrome-mac*/Chromium.app/Contents/MacOS/Chromium)) |
| 122 | browser: |
| 123 | RASTRILLO_CHROME="$(RASTRILLO_CHROME)" CGO_ENABLED=0 go test -tags browser -count=1 -run 'OnTap|ProductionCSP' ./internal/memoriatest/ |
| 124 | |
| 125 | .PHONY: credits |
| 126 | credits: |
| 127 | @set -eu; notices_tmp=$$(mktemp -d); trap 'rm -rf "$$notices_tmp"' EXIT; \ |
| 128 | GOOS=$$(go env GOHOSTOS) GOARCH=$$(go env GOHOSTARCH) CGO_ENABLED=0 \ |
| 129 | go build -o "$$notices_tmp/notices" amadan.net/oficina/estilo.git/cmd/oficina-notices; \ |
| 130 | GOOS=linux GOARCH=arm64 CGO_ENABLED=0 "$$notices_tmp/notices" \ |
| 131 | -package ./cmd/memoria -lucide -onest \ |
| 132 | -exclude amadan.net/oficina/estilo.git,amadan.net/oficina/home/connect,amadan.net/oficina/home/handoff,amadan.net/oficina/suite,amadan.net/rastrillo/native/server \ |
| 133 | > "$$notices_tmp/notices.json"; \ |
| 134 | mv "$$notices_tmp/notices.json" internal/memoria/credits/notices.json |
| 135 | |