Makefile · 4345 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 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.
32 @$(AIR)
33
34 build: ## Build the shithubd binary into bin/.
35 @mkdir -p bin
36 go build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN) ./cmd/shithubd
37
38 test: ## Run unit tests.
39 go test $(GOFLAGS) ./...
40
41 test-race: ## Run unit tests with the race detector.
42 go test $(GOFLAGS) -race ./...
43
44 lint: ## Run golangci-lint.
45 golangci-lint run
46
47 fmt: ## Format the codebase with gofumpt and goimports.
48 $(GOFUMPT) -l -w cmd internal pkg
49 $(GOIMPORTS) -local github.com/tenseleyFlow/shithub -w cmd internal pkg
50
51 tidy: ## Tidy go.mod / go.sum.
52 go mod tidy
53
54 clean: ## Remove build artifacts.
55 rm -rf bin tmp coverage.out
56
57 assets: ## Copy Primer CSS into internal/web/static/ for embedding.
58 @mkdir -p internal/web/static/primer
59 @if [ -d .refs/primer-css/dist ]; then \
60 cp -R .refs/primer-css/dist/* internal/web/static/primer/; \
61 else \
62 echo "warn: .refs/primer-css/dist not found; run 'git clone https://github.com/primer/css .refs/primer-css' first"; \
63 fi
64
65 ci: lint test build ## Full CI pipeline (matches .github/workflows/ci.yml).
66 @echo "ci: ok"
67
68 install-tools: ## Install development tools via 'go install'.
69 go install mvdan.cc/gofumpt@latest
70 go install golang.org/x/tools/cmd/goimports@latest
71 go install github.com/air-verse/air@latest
72 go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
73
74 dev-db: ## Bring up Postgres in docker-compose.
75 docker compose up -d postgres
76 @echo "Waiting for postgres to become healthy..."
77 @until docker compose exec -T postgres pg_isready -U shithub -d shithub >/dev/null 2>&1; do sleep 1; done
78 @echo "Postgres ready at 127.0.0.1:5432"
79
80 dev-db-down: ## Stop the dev Postgres container.
81 docker compose down
82
83 dev-db-reset: ## Drop the dev Postgres volume and re-create.
84 docker compose down -v
85 $(MAKE) dev-db
86
87 dev-storage: ## Bring up MinIO + run minio-init to seed the bucket.
88 docker compose up -d minio
89 docker compose run --rm minio-init
90 @echo "MinIO S3 API: http://127.0.0.1:9000 console: http://127.0.0.1:9001"
91 @echo "Credentials: shithub-dev / shithub-dev-secret-please-change"
92
93 dev-storage-down: ## Stop the MinIO container (volume persists).
94 docker compose stop minio
95
96 dev-storage-reset: ## Drop the MinIO volume and re-seed.
97 docker compose down minio
98 docker volume rm -f shithub-miniodata
99 $(MAKE) dev-storage
100
101 storage-check: build ## Run shithubd storage check against the configured backend.
102 ./bin/shithubd storage check
103
104 migrate-up: ## Apply all pending migrations.
105 ./bin/shithubd migrate up
106
107 migrate-down: ## Roll back the most recent migration.
108 ./bin/shithubd migrate down
109
110 migrate-status: ## Show migration status.
111 ./bin/shithubd migrate status
112
113 sqlc-generate: ## Regenerate sqlc Go code from queries.
114 $(GOBIN)/sqlc generate
115
116 test-integration: ## Run tests with SHITHUB_TEST_DATABASE_URL set against the dev Postgres.
117 SHITHUB_TEST_DATABASE_URL=$${SHITHUB_TEST_DATABASE_URL:-postgres://shithub:shithub_dev@127.0.0.1:5432/postgres?sslmode=disable} \
118 go test -trimpath ./...
119
120 version: ## Print version info that would be embedded into the binary.
121 @echo "Version: $(VERSION)"
122 @echo "Commit: $(COMMIT)"
123 @echo "Built: $(BUILT)"