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