Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
138 lines (112 loc) · 5.73 KB
/
Copy pathMakefile
File metadata and controls
138 lines (112 loc) · 5.73 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
GO ?= go
COMPOSE ?= docker compose
# PostgreSQL major under test (see docs/postgresql-version-support.md).
PG_VERSION ?= 16
PG_PORT ?= 5432
# Local dev database credentials (compose/compose.yml); test-only defaults.
PG_USER ?= pgsprite
PG_PASSWORD ?= pgsprite
PG_DATABASE ?= pgsprite
# Localhost-only test credentials, parameterized above — not a real secret.
PG_DSN_LOCAL = postgres://$(PG_USER):$(PG_PASSWORD)@localhost:$(PG_PORT)/$(PG_DATABASE)?sslmode=disable# sadscan:disable np.postgres.1
# Which corpus replay project to run (replay/<project>/project.conf).
REPLAY_PROJECT ?= buzz
.PHONY: build gen-capabilities check-capabilities test test-unit test-db test-supported-postgres test-aws-boundary lint setup db-up db-down demos clean demo demo-seed demo-check replay replay-refresh replay-down
# The first target is make's default goal: keep build here so a bare
# `make` builds the binary rather than rewriting a checked-in document.
.DEFAULT_GOAL := build
build:
$(GO) build -o bin/pg-sprite ./cmd/pg-sprite
$(GO) build ./...
test:
$(GO) test -race ./...
# Unit tests only (no Docker required).
test-unit:
SKIP_INTEGRATION=1 $(GO) test -race ./...
# Integration suite against the long-lived compose database (no per-test
# containers). Start it first: make db-up [PG_VERSION=14]
test-db:
PG_DSN="$(PG_DSN_LOCAL)" $(GO) test -race -count=1 ./...
# Full suite against every supported PostgreSQL major (14 -> 18) via
# testcontainers — the local mirror of the CI matrix.
test-supported-postgres:
@for v in 14 15 16 17 18; do \
echo "=== PostgreSQL $$v ==="; \
PG_VERSION=$$v $(GO) test -race -count=1 ./... || exit 1; \
done
# AWS-boundary tests against Ministack's RDS/Aurora control plane
# (docs/testing.md). Needs Docker only — Ministack is MIT-licensed and
# tokenless. PG_VERSION selects the major of the provisioned database.
test-aws-boundary:
$(GO) test -tags ministack -race -count=1 -run 'AuroraControlPlane' -v ./internal/testutil/
lint:
golangci-lint run
# Regenerate the marked regions of docs/capabilities.md from the embedded
# matrix (pkg/capabilities/capabilities.yaml); CI fails if they drift. The
# gate below runs the same command, so the two cannot drift apart.
GEN_CAPABILITIES = $(GO) run ./internal/cmd/gen-capabilities
gen-capabilities:
$(GEN_CAPABILITIES)
# Regenerate the capabilities page and fail if regeneration changed it. Only the
# generator's own edits count, so an uncommitted edit to the hand-written prose
# outside the marker regions does not trip the gate. The target is a pure
# check: on failure — a generator error or a diff — it puts the page back as it
# was before the run, so a rerun fails the same way and `make gen-capabilities`
# is the only command that writes the page.
check-capabilities:
@before=$$(mktemp); cp docs/capabilities.md "$$before"; \
$(GEN_CAPABILITIES) || { cp "$$before" docs/capabilities.md; rm -f "$$before"; exit 1; }; \
if ! diff -u --label docs/capabilities.md --label regenerated "$$before" docs/capabilities.md; then \
cp "$$before" docs/capabilities.md; rm -f "$$before"; \
echo "docs/capabilities.md disagrees with pkg/capabilities/capabilities.yaml; run make gen-capabilities and commit the result" >&2; \
exit 1; \
fi; \
rm -f "$$before"
# Configure git hooks (relative path so worktrees work too).
setup:
git config core.hooksPath .githooks
# Start / stop the local development database (compose/compose.yml).
COMPOSE_ENV = PG_VERSION=$(PG_VERSION) PG_PORT=$(PG_PORT) PG_USER=$(PG_USER) PG_PASSWORD=$(PG_PASSWORD) PG_DATABASE=$(PG_DATABASE)
db-up:
$(COMPOSE_ENV) $(COMPOSE) -f compose/compose.yml up --wait -d
db-down:
$(COMPOSE_ENV) $(COMPOSE) -f compose/compose.yml down -v
# Re-render the README/docs demo GIFs from their VHS tapes (docs/demos).
# Needs vhs (brew install vhs); the binary and compose database are built
# and started as prerequisites — every tape puts bin/ on PATH, so rendering
# without a built binary would record "command not found" into the GIFs.
demos: build db-up
cd docs/demos && for t in *.tape; do vhs $$t || exit 1; done
clean:
rm -rf bin
# Runnable product tour: build the binary, start the compose database,
# reseed the demo tables, and walk the CLI through every planner route,
# the declarative diff, the offline commands, and real executions
# (demo/tour.sh). Rerunnable — each run starts from the same seed. The
# database is left running; stop it with make db-down.
demo: build db-up demo-seed
PGS="$(CURDIR)/bin/pg-sprite" PG_DSN="$(PG_DSN_LOCAL)" demo/tour.sh
# Reseed the demo tables to the baseline (psql runs inside the compose
# container, so no local client is required). Depends on db-up so it works
# standalone and never races the database under parallel make.
demo-seed: db-up
$(COMPOSE_ENV) $(COMPOSE) -f compose/compose.yml exec -T postgres \
psql -v ON_ERROR_STOP=1 -U $(PG_USER) -d $(PG_DATABASE) < demo/seed.sql
# The same tour as a packaged-binary smoke test (CI runs this): asserts on
# --json fields and exit codes only. Needs jq.
demo-check: build db-up demo-seed
CHECK=1 PGS="$(CURDIR)/bin/pg-sprite" PG_DSN="$(PG_DSN_LOCAL)" demo/tour.sh
# Corpus replay (replay/README.md): replay a real project's schema-change
# history through the built binary, asserting per statement that pg-sprite
# executes it or refuses with exactly the expected typed reason, class, and
# owner. Fetches the pinned corpus and starts (or resets) the project's own
# throwaway container as needed; stop it with make replay-down. Operator-run,
# not a CI gate.
replay: build
replay/fetch.sh $(REPLAY_PROJECT)
PGS="$(CURDIR)/bin/pg-sprite" replay/replay.sh $(REPLAY_PROJECT)
# Report corpus drift beyond the project's pin (read-only; see replay/README.md).
replay-refresh:
replay/fetch.sh $(REPLAY_PROJECT) refresh
replay-down:
replay/harness.sh $(REPLAY_PROJECT) down