@@ -0,0 +1,76 @@ |
| | 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 | + |
| | 73 | +version: ## Print version info that would be embedded into the binary. |
| | 74 | + @echo "Version: $(VERSION)" |
| | 75 | + @echo "Commit: $(COMMIT)" |
| | 76 | + @echo "Built: $(BUILT)" |