| 1 | APP := mapa |
| 2 | |
| 3 | # The toolchain go.mod names, pinned here too: a newer local Go would |
| 4 | # otherwise win, and the gate would not be the one CI runs. |
| 5 | export GOTOOLCHAIN := go1.26.11 |
| 6 | |
| 7 | # estilo, the suite's design module, and notion, the Notion import's |
| 8 | # client, are private: fetch them with Git auth. |
| 9 | private_comma := , |
| 10 | export GOPRIVATE := $(if $(GOPRIVATE),$(GOPRIVATE)$(private_comma))amadan.net/oficina/estilo.git,amadan.net/oficina/notion.git |
| 11 | |
| 12 | # What `carlos ship -target` defaults to, and so what a release must be |
| 13 | # built for. Override for a one-off: make release RELEASE_GOARCH=amd64 |
| 14 | RELEASE_GOOS ?= linux |
| 15 | RELEASE_GOARCH ?= arm64 |
| 16 | RELEASE_BIN := releases/$(APP)-$(RELEASE_GOOS)-$(RELEASE_GOARCH) |
| 17 | |
| 18 | # What GET /api/version answers. An unstamped binary answers "dev" |
| 19 | # forever, and the deploy check can then never fail. |
| 20 | VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null) |
| 21 | |
| 22 | .PHONY: build release version-check deps test vet fmt-check code \ |
| 23 | migration-check mutate browser preview editor golden editor-golden \ |
| 24 | corpus-local credits credits-check ci locale-dates pandoc-fixture \ |
| 25 | spacing |
| 26 | |
| 27 | build: |
| 28 | CGO_ENABLED=0 go build ./... |
| 29 | |
| 30 | release: version-check |
| 31 | @mkdir -p releases |
| 32 | CGO_ENABLED=0 GOOS=$(RELEASE_GOOS) GOARCH=$(RELEASE_GOARCH) go build -trimpath \ |
| 33 | -ldflags "-s -w -X amadan.net/rastrillo/rastrillo.BuildVersion=$(VERSION)" \ |
| 34 | -o $(RELEASE_BIN) ./cmd/$(APP) |
| 35 | @echo "built $(RELEASE_BIN) reporting version $(VERSION)" |
| 36 | |
| 37 | version-check: |
| 38 | @test -n "$(VERSION)" || { echo "make release: no version to stamp; commit, or name it: make release VERSION=v0.1.0"; exit 1; } |
| 39 | @case "$(VERSION)" in *-dirty) echo "make release: the tree is dirty, so $(VERSION) does not name what you would ship"; exit 1;; esac |
| 40 | |
| 41 | # deps repairs a module cache whose extracted copy lost files (go mod |
| 42 | # verify names it), the CI runner's known failure (memoria's Makefile). |
| 43 | deps: |
| 44 | @go mod download |
| 45 | @out=$$(go mod verify 2>&1) || { \ |
| 46 | echo "$$out"; \ |
| 47 | echo "$$out" | sed -n 's/.*: dir has been modified (\(.*\))$$/\1/p' | while read -r dir; do \ |
| 48 | echo "deps: re-extracting $$dir"; chmod -R u+w "$$dir" && rm -rf "$$dir"; \ |
| 49 | done; \ |
| 50 | go mod download && go mod verify; \ |
| 51 | } |
| 52 | |
| 53 | # test is every gate in spec §11 that slice 1 meets, the 10,000-page |
| 54 | # speed gate (6) included. |
| 55 | test: |
| 56 | CGO_ENABLED=0 go test ./... |
| 57 | |
| 58 | # Also vets the browser-tagged tests: they are outside `make test`, and a |
| 59 | # file behind a tag that nothing compiles rots silently (Fichas, once). |
| 60 | vet: deps |
| 61 | go vet ./... |
| 62 | go vet -tags browser ./internal/mapatest/ |
| 63 | |
| 64 | fmt-check: |
| 65 | @out=$$(gofmt -l .); if [ -n "$$out" ]; then echo "gofmt needed:"; echo "$$out"; exit 1; fi |
| 66 | |
| 67 | # code is rastrillo's code budget: 80 columns, 40-line functions, |
| 68 | # 400-line files, no one-letter names. |
| 69 | code: |
| 70 | go tool rastrillo budget code |
| 71 | |
| 72 | # spacing is Fiesta's spacing check (level-up build note 89): every |
| 73 | # margin, padding and gap in Mapa's own stylesheets is a step of the |
| 74 | # scale, var(--rst-sp-N), or says why it is not with |
| 75 | # /* spacing-allow: why */. estilo's and rastrillo's files are served |
| 76 | # from their modules, so nothing here is somebody else's to skip. |
| 77 | spacing: |
| 78 | go tool fiesta spacing internal/mapa/static |
| 79 | |
| 80 | # A step of its own, so ci.d/ can report it: it fails the build the |
| 81 | # moment models.go and migrations/ disagree, instead of at boot. |
| 82 | migration-check: |
| 83 | go tool rastrillo migration check |
| 84 | |
| 85 | # mutate breaks each security gate's code on purpose (spec §11: gates 1, |
| 86 | # 4 and 8; and L9's rename carry, level-up build note 79) through `go |
| 87 | # test -overlay`, never touching the tree, and fails unless every |
| 88 | # mutation makes its gate fail. |
| 89 | mutate: |
| 90 | go run ./scripts/mutate |
| 91 | |
| 92 | # browser is spec §11 gate 7: the walk in real Chromium, scripts off then |
| 93 | # on, failing on any console error. Behind a build tag because CI |
| 94 | # runners may have no Chromium. rastrillo's harness looks on PATH and in |
| 95 | # Linux's Playwright cache; on a Mac this finds Playwright's Chromium |
| 96 | # when RASTRILLO_CHROME is unset. |
| 97 | browser: |
| 98 | @chrome="$${RASTRILLO_CHROME:-$$(ls -d "$$HOME"/Library/Caches/ms-playwright/chromium-*/chrome-mac*/*.app/Contents/MacOS/* 2>/dev/null | tail -1)}"; \ |
| 99 | RASTRILLO_CHROME="$$chrome" go test -tags browser -count=1 ./internal/mapatest/ |
| 100 | |
| 101 | # preview serves the real app, signed in, over synthetic pages on |
| 102 | # loopback: go run ./scripts/preview, then open http://127.0.0.1:8747/ |
| 103 | preview: |
| 104 | go run ./scripts/preview |
| 105 | |
| 106 | # editor is the page editor's half of the gate (spec §6.2, §7): Node's |
| 107 | # dependencies exactly as the lockfile pins them, the bundle rebuilt and |
| 108 | # compared byte for byte with the committed one (L12, its size logged), |
| 109 | # then node --test, which holds markup.mjs and the schema's toDOM to Go's |
| 110 | # golden file (L4). It uses the node and npm on PATH. Drift is the |
| 111 | # rebuilt bundle against git's index (a staged bundle counts), and it is |
| 112 | # left in the tree for you to look at and commit; nothing is restored. |
| 113 | editor: |
| 114 | @command -v node >/dev/null && command -v npm >/dev/null || { \ |
| 115 | echo "make editor: node and npm must be on PATH"; exit 1; } |
| 116 | cd editor && npm ci --no-audit --no-fund --loglevel=error |
| 117 | cd editor && node build-bundles.mjs |
| 118 | @drift=$$(git diff --name-status -- 'internal/mapa/static/editor.*'; \ |
| 119 | git ls-files --others --exclude-standard -- 'internal/mapa/static/editor.*'); \ |
| 120 | if [ -n "$$drift" ]; then echo "$$drift"; \ |
| 121 | echo "make editor: internal/mapa/static/editor.*.js does not match a fresh build; commit the rebuilt bundle"; \ |
| 122 | exit 1; fi |
| 123 | cd editor && node --test |
| 124 | |
| 125 | # golden rewrites what gate L4 compares against: the corpus's synthetic |
| 126 | # pages, then markup's golden file, then the editor's (below). Commit all |
| 127 | # three. |
| 128 | golden: |
| 129 | CGO_ENABLED=0 go test ./internal/mapa/ -run TestSyntheticCorpusIsCurrent -count=1 -update |
| 130 | CGO_ENABLED=0 go test ./internal/mapa/markup/ -run 'TestGolden$$|TestGoldenLocales$$' -count=1 -update |
| 131 | CGO_ENABLED=0 go test ./internal/mapa/locale/ -run 'TestDateLabelsAreCurrent$$' -count=1 -update |
| 132 | $(MAKE) editor-golden |
| 133 | |
| 134 | # pandoc-fixture records how the pandoc on PATH reads every column layout |
| 135 | # case and Join's output for it (columns and icons spec COL12), which the |
| 136 | # markup tests hold Mapa to. CI has no pandoc; commit the result. |
| 137 | pandoc-fixture: |
| 138 | CGO_ENABLED=0 go test ./internal/mapa/markup/ -run 'TestCOL12' -count=1 -pandoc |
| 139 | |
| 140 | # locale-dates rewrites internal/mapa/locale/dates.json, the CLDR date |
| 141 | # patterns Mapa writes dates with (level-up build note 85), from the ICU |
| 142 | # the node on PATH links, then the cases Go and the editor are held to. |
| 143 | # Commit both. A different Node may carry a different CLDR: the file |
| 144 | # records which one it came from. |
| 145 | locale-dates: |
| 146 | node editor/gen-dates.mjs |
| 147 | CGO_ENABLED=0 go test ./internal/mapa/locale/ -run 'TestDateLabelsAreCurrent$$' -count=1 -update |
| 148 | |
| 149 | # editor-golden rewrites markup/testdata/editor.json, gates L1 and L3's Go |
| 150 | # half: the bodies the editor's seeded edits saved, with the blocks its |
| 151 | # document held, which markup's TestEditorBodies parses with Go. |
| 152 | editor-golden: |
| 153 | cd editor && npm ci --no-audit --no-fund --loglevel=error |
| 154 | cd editor && MAPA_EDITOR_UPDATE=1 node --test fidelity.test.mjs |
| 155 | |
| 156 | # corpus-local runs gates L1 to L4 over Markdown read in place, for example |
| 157 | # make corpus-local DIR=/abs/path/to/notes. Go's answers go to a |
| 158 | # temporary file outside the repository, removed afterwards: nothing |
| 159 | # read is committed. Record the result in the build notes. |
| 160 | corpus-local: |
| 161 | @test -n "$(DIR)" || { echo "usage: make corpus-local DIR=<a directory of .md files>"; exit 1; } |
| 162 | @out=$$(mktemp -t mapa-corpus); \ |
| 163 | MAPA_CORPUS_DIR="$(DIR)" MAPA_CORPUS_OUT="$$out" CGO_ENABLED=0 \ |
| 164 | go test ./internal/mapa/markup/ -run TestCorpusLocal -count=1 -v && \ |
| 165 | (cd editor && MAPA_GOLDEN="$$out" node --test parity.test.mjs fidelity.test.mjs); \ |
| 166 | status=$$?; rm -f "$$out"; exit $$status |
| 167 | |
| 168 | # credits regenerates Help → Colophon's inventory, |
| 169 | # internal/mapa/credits/: the Go modules the release build links (estilo's |
| 170 | # oficina-notices over ./cmd/mapa for linux/arm64), Lucide's notice, and |
| 171 | # the npm packages inside the committed editor bundle, each with its own |
| 172 | # licence text. It runs npm ci in editor/, so it needs node and npm on |
| 173 | # PATH. Commit both files. credits-check needs Go only: it fails when the |
| 174 | # Go modules, their notices, the toolchain, the lockfile or the bundle no |
| 175 | # longer match what was recorded. |
| 176 | credits: |
| 177 | python3 scripts/credits.py |
| 178 | |
| 179 | credits-check: |
| 180 | python3 scripts/credits.py --check |
| 181 | |
| 182 | # ci is the one gate: what the runner executes and what you run before |
| 183 | # pushing. |
| 184 | ci: vet fmt-check code spacing test migration-check editor credits-check |
| 185 | |