Makefile · 8093 bytes Raw Blame History
1 # shithub Makefile
2 # Targets mirror what CI runs. The Makefile is the source of truth.
3
4 .DEFAULT_GOAL := help
5 .PHONY: help dev build test test-race lint lint-policy lint-markdown lint-secret-logs lint-spdx verify-api-docs fmt tidy clean ci assets install-tools version deploy deploy-check restore-drill bench-staging docs docs-serve docs-verify gen-third-party-notices
6
7 # Build metadata embedded into the binary via -ldflags.
8 VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
9 COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo unknown)
10 BUILT := $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
11 LDFLAGS := -X github.com/tenseleyFlow/shithub/internal/version.Version=$(VERSION) \
12 -X github.com/tenseleyFlow/shithub/internal/version.Commit=$(COMMIT) \
13 -X github.com/tenseleyFlow/shithub/internal/version.BuiltAt=$(BUILT)
14
15 GOFLAGS := -trimpath
16 BIN := bin/shithubd
17
18 # Tools installed via 'go install' live in GOBIN (or GOPATH/bin). Reference
19 # them by absolute path so make recipes don't depend on PATH ordering.
20 GOBIN := $(shell go env GOBIN)
21 ifeq ($(GOBIN),)
22 GOBIN := $(shell go env GOPATH)/bin
23 endif
24 GOFUMPT := $(GOBIN)/gofumpt
25 GOIMPORTS := $(GOBIN)/goimports
26 AIR := $(GOBIN)/air
27
28 help: ## Show this help.
29 @awk 'BEGIN {FS = ":.*##"} /^[a-zA-Z_-]+:.*##/ {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST)
30
31 dev: ## Run the web server with hot reload via air. Sources .env if present.
32 @if [ -f .env ]; then set -a; . ./.env; set +a; fi; $(AIR)
33
34 dev-migrate: ## Apply DB migrations against $$SHITHUB_DATABASE_URL (sources .env).
35 @if [ -f .env ]; then set -a; . ./.env; set +a; fi; \
36 go run ./cmd/shithubd migrate up
37
38 dev-run: ## Run the binary directly (no air); sources .env.
39 @if [ -f .env ]; then set -a; . ./.env; set +a; fi; \
40 go run ./cmd/shithubd web
41
42 build: ## Build the shithubd binary into bin/.
43 @mkdir -p bin
44 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN) ./cmd/shithubd
45
46 test: ## Run unit tests.
47 go test $(GOFLAGS) ./...
48
49 test-race: ## Run unit tests with the race detector.
50 go test $(GOFLAGS) -race ./...
51
52 lint: ## Run golangci-lint.
53 golangci-lint run
54
55 fmt: ## Format the codebase with gofumpt and goimports.
56 $(GOFUMPT) -l -w cmd internal pkg
57 $(GOIMPORTS) -local github.com/tenseleyFlow/shithub -w cmd internal pkg
58
59 tidy: ## Tidy go.mod / go.sum.
60 go mod tidy
61
62 clean: ## Remove build artifacts.
63 rm -rf bin tmp coverage.out
64
65 assets: ## Copy Primer CSS into internal/web/static/ for embedding.
66 @mkdir -p internal/web/static/primer
67 @if [ -d .refs/primer-css/dist ]; then \
68 cp -R .refs/primer-css/dist/* internal/web/static/primer/; \
69 else \
70 echo "warn: .refs/primer-css/dist not found; run 'git clone https://github.com/primer/css .refs/primer-css' first"; \
71 fi
72
73 ci: lint lint-policy lint-markdown lint-secret-logs lint-spdx verify-api-docs test build ## Full CI pipeline (matches .github/workflows/ci.yml).
74 @echo "ci: ok"
75
76 lint-policy: ## Enforce policy-package boundary (no inline auth checks in handlers/git/cmd).
77 @scripts/lint-policy-boundary.sh
78
79 lint-markdown: ## Enforce markdown-package boundary (no goldmark/bluemonday outside internal/markdown).
80 @scripts/lint-markdown-boundary.sh
81
82 lint-secret-logs: ## Fail when source emits log lines containing token-prefix patterns.
83 @scripts/lint-secret-logs.sh
84
85 lint-spdx: ## Verify every Go + shell source carries the SPDX license header.
86 @scripts/verify-spdx-headers.sh
87
88 verify-api-docs: ## Fail when an /api/v1 route in code is missing from docs/public/api/.
89 @scripts/verify-api-docs.sh
90
91 bench-small: ## Run the bench harness against $$BENCH_TARGET (default localhost:8080).
92 @go run ./bench -target=$${BENCH_TARGET:-http://localhost:8080} -iters=$${BENCH_ITERS:-20}
93
94 bench-full: ## Placeholder — runs nightly off-CI against big fixtures (see bench/fixtures/README.md).
95 @echo "bench-full: big-fixture generators land in a follow-up — see bench/fixtures/README.md"
96 @exit 0
97
98 install-tools: ## Install development tools via 'go install'.
99 go install mvdan.cc/gofumpt@latest
100 go install golang.org/x/tools/cmd/goimports@latest
101 go install github.com/air-verse/air@latest
102 go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
103
104 dev-db: ## Bring up Postgres in docker-compose.
105 docker compose up -d postgres
106 @echo "Waiting for postgres to become healthy..."
107 @until docker compose exec -T postgres pg_isready -U shithub -d shithub >/dev/null 2>&1; do sleep 1; done
108 @echo "Postgres ready at 127.0.0.1:5432"
109
110 dev-db-down: ## Stop the dev Postgres container.
111 docker compose down
112
113 dev-db-reset: ## Drop the dev Postgres volume and re-create.
114 docker compose down -v
115 $(MAKE) dev-db
116
117 dev-storage: ## Bring up MinIO + run minio-init to seed the bucket.
118 docker compose up -d minio
119 docker compose run --rm minio-init
120 @echo "MinIO S3 API: http://127.0.0.1:9000 console: http://127.0.0.1:9001"
121 @echo "Credentials: shithub-dev / shithub-dev-secret-please-change"
122
123 dev-storage-down: ## Stop the MinIO container (volume persists).
124 docker compose stop minio
125
126 dev-storage-reset: ## Drop the MinIO volume and re-seed.
127 docker compose down minio
128 docker volume rm -f shithub-miniodata
129 $(MAKE) dev-storage
130
131 storage-check: build ## Run shithubd storage check against the configured backend.
132 ./bin/shithubd storage check
133
134 dev-email: ## Bring up MailHog for local email capture (S05).
135 docker compose up -d mailhog
136 @echo "MailHog SMTP: 127.0.0.1:1025 web UI: http://127.0.0.1:8025"
137
138 dev-email-down: ## Stop MailHog.
139 docker compose stop mailhog
140
141 migrate-up: ## Apply all pending migrations.
142 ./bin/shithubd migrate up
143
144 migrate-down: ## Roll back the most recent migration.
145 ./bin/shithubd migrate down
146
147 migrate-status: ## Show migration status.
148 ./bin/shithubd migrate status
149
150 sqlc-generate: ## Regenerate sqlc Go code from queries.
151 $(GOBIN)/sqlc generate
152
153 test-integration: ## Run tests with SHITHUB_TEST_DATABASE_URL set against the dev Postgres.
154 SHITHUB_TEST_DATABASE_URL=$${SHITHUB_TEST_DATABASE_URL:-postgres://shithub:shithub_dev@127.0.0.1:5432/postgres?sslmode=disable} \
155 go test -trimpath ./...
156
157 version: ## Print version info that would be embedded into the binary.
158 @echo "Version: $(VERSION)"
159 @echo "Commit: $(COMMIT)"
160 @echo "Built: $(BUILT)"
161
162 # --- deploy ---
163 # Inventory selection: ANSIBLE_INVENTORY=production make deploy (default: staging).
164 ANSIBLE_INVENTORY ?= staging
165 ANSIBLE_TAGS ?=
166 ANSIBLE_LIMIT ?=
167
168 deploy-check: ## Dry-run the Ansible playbook (--check) against $$ANSIBLE_INVENTORY.
169 cd deploy/ansible && ansible-playbook -i inventory/$(ANSIBLE_INVENTORY) site.yml --check --diff \
170 $(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) \
171 $(if $(ANSIBLE_LIMIT),--limit $(ANSIBLE_LIMIT))
172
173 deploy: ## Apply the Ansible playbook against $$ANSIBLE_INVENTORY (set to production for prod).
174 cd deploy/ansible && ansible-playbook -i inventory/$(ANSIBLE_INVENTORY) site.yml \
175 $(if $(ANSIBLE_TAGS),--tags $(ANSIBLE_TAGS)) \
176 $(if $(ANSIBLE_LIMIT),--limit $(ANSIBLE_LIMIT))
177
178 restore-drill: ## Run the restore drill on the backup host (must be run via ssh on that host).
179 deploy/restore-drill/run.sh
180
181 bench-staging: ## Run the bench harness against staging (BENCH_TARGET must be set to the staging URL).
182 @if [ -z "$$BENCH_TARGET" ]; then echo "set BENCH_TARGET=https://staging.shithub.example"; exit 2; fi
183 go run ./bench -target=$$BENCH_TARGET -iters=$${BENCH_ITERS:-50}
184
185 # --- docs ---
186 docs: ## Build the public docs site to build/docs/ via mdBook.
187 cd docs/public && mdbook build
188
189 docs-serve: ## Serve the public docs site locally on http://127.0.0.1:3000.
190 cd docs/public && mdbook serve --port 3000
191
192 docs-verify: verify-api-docs ## Verify docs are in sync (API routes documented + SPDX headers).
193 @$(MAKE) lint-spdx
194 @if command -v mdbook >/dev/null 2>&1; then \
195 cd docs/public && mdbook build >/dev/null && echo "mdbook build: ok"; \
196 else \
197 echo "mdbook not installed; skipping site build"; \
198 fi
199
200 gen-third-party-notices: ## Regenerate THIRD_PARTY_NOTICES.md from the active go.mod.
201 @scripts/gen-third-party-notices.sh > THIRD_PARTY_NOTICES.md
202 @echo "gen-third-party-notices: wrote THIRD_PARTY_NOTICES.md"