Makefile · 5827 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 fmt tidy clean ci assets install-tools version
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 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 bench-small: ## Run the bench harness against $$BENCH_TARGET (default localhost:8080).
86 @go run ./bench -target=$${BENCH_TARGET:-http://localhost:8080} -iters=$${BENCH_ITERS:-20}
87
88 bench-full: ## Placeholder — runs nightly off-CI against big fixtures (see bench/fixtures/README.md).
89 @echo "bench-full: big-fixture generators land in a follow-up — see bench/fixtures/README.md"
90 @exit 0
91
92 install-tools: ## Install development tools via 'go install'.
93 go install mvdan.cc/gofumpt@latest
94 go install golang.org/x/tools/cmd/goimports@latest
95 go install github.com/air-verse/air@latest
96 go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
97
98 dev-db: ## Bring up Postgres in docker-compose.
99 docker compose up -d postgres
100 @echo "Waiting for postgres to become healthy..."
101 @until docker compose exec -T postgres pg_isready -U shithub -d shithub >/dev/null 2>&1; do sleep 1; done
102 @echo "Postgres ready at 127.0.0.1:5432"
103
104 dev-db-down: ## Stop the dev Postgres container.
105 docker compose down
106
107 dev-db-reset: ## Drop the dev Postgres volume and re-create.
108 docker compose down -v
109 $(MAKE) dev-db
110
111 dev-storage: ## Bring up MinIO + run minio-init to seed the bucket.
112 docker compose up -d minio
113 docker compose run --rm minio-init
114 @echo "MinIO S3 API: http://127.0.0.1:9000 console: http://127.0.0.1:9001"
115 @echo "Credentials: shithub-dev / shithub-dev-secret-please-change"
116
117 dev-storage-down: ## Stop the MinIO container (volume persists).
118 docker compose stop minio
119
120 dev-storage-reset: ## Drop the MinIO volume and re-seed.
121 docker compose down minio
122 docker volume rm -f shithub-miniodata
123 $(MAKE) dev-storage
124
125 storage-check: build ## Run shithubd storage check against the configured backend.
126 ./bin/shithubd storage check
127
128 dev-email: ## Bring up MailHog for local email capture (S05).
129 docker compose up -d mailhog
130 @echo "MailHog SMTP: 127.0.0.1:1025 web UI: http://127.0.0.1:8025"
131
132 dev-email-down: ## Stop MailHog.
133 docker compose stop mailhog
134
135 migrate-up: ## Apply all pending migrations.
136 ./bin/shithubd migrate up
137
138 migrate-down: ## Roll back the most recent migration.
139 ./bin/shithubd migrate down
140
141 migrate-status: ## Show migration status.
142 ./bin/shithubd migrate status
143
144 sqlc-generate: ## Regenerate sqlc Go code from queries.
145 $(GOBIN)/sqlc generate
146
147 test-integration: ## Run tests with SHITHUB_TEST_DATABASE_URL set against the dev Postgres.
148 SHITHUB_TEST_DATABASE_URL=$${SHITHUB_TEST_DATABASE_URL:-postgres://shithub:shithub_dev@127.0.0.1:5432/postgres?sslmode=disable} \
149 go test -trimpath ./...
150
151 version: ## Print version info that would be embedded into the binary.
152 @echo "Version: $(VERSION)"
153 @echo "Commit: $(COMMIT)"
154 @echo "Built: $(BUILT)"