|
| 1 | +SHELL := /usr/bin/env bash |
| 2 | +.DEFAULT_GOAL := help |
| 3 | +.EXPORT_ALL_VARIABLES: |
| 4 | + |
| 5 | +MKCERT_INSTALL_PATH ?= $(HOME)/.local/bin |
| 6 | +MKCERT_VERSION := v1.4.4 |
| 7 | +MKCERT_ASSET := mkcert-$(MKCERT_VERSION)-linux-amd64 |
| 8 | +MKCERT_URL := https://github.com/FiloSottile/mkcert/releases/latest/download/$(MKCERT_ASSET) |
| 9 | +CERT_DIR ?= ./certs |
| 10 | +HOSTS ?= localhost 127.0.0.1 ::1 |
| 11 | + |
| 12 | + |
| 13 | +.PHONY: setup |
| 14 | +setup: install-mkcert mkcert-generate mkcert-generate mkcert-install-ca |
| 15 | + |
| 16 | + |
| 17 | +.PHONY: check |
| 18 | +check: ## Run linters |
| 19 | + @go tool golangci-lint run |
| 20 | + |
| 21 | +.PHONY: fix |
| 22 | +fix: ## Auto-fix lint issues where possible |
| 23 | + @go tool golangci-lint run --fix |
| 24 | + |
| 25 | +.PHONY: fieldalign |
| 26 | +fieldalign: ## Apply field alignment fixes |
| 27 | + @go tool fieldalignment -fix ./pkg/... |
| 28 | + |
| 29 | +.PHONY: fmt |
| 30 | +fmt: ## Run project formatting helpers |
| 31 | + @go tool golangci-lint fmt |
| 32 | + |
| 33 | +.PHONY: tidy |
| 34 | +tidy: ## Tidy go.mod and download modules |
| 35 | + go mod tidy |
| 36 | + go mod download |
| 37 | + |
| 38 | +.PHONY: test |
| 39 | +test: ## Run unit tests with coverage (JSON output piped through gotestfmt) |
| 40 | + @go test -covermode=atomic -gcflags='all=-N -l' -tags testing -coverprofile=coverage.txt -timeout 5m -json -v ./... 2>&1 | go tool gotestfmt -showteststatus |
| 41 | + |
| 42 | +.PHONY: security |
| 43 | +security: ## Run basic security checks (gosec) |
| 44 | + go tool gosec ./... |
| 45 | + |
| 46 | + |
| 47 | +# --- Mkcert ------------------------------- |
| 48 | +install-mkcert: ## Install mkcert binary to $(MKCERT_INSTALL_PATH) if missing |
| 49 | + @if [ ! -f "$(MKCERT_INSTALL_PATH)/mkcert" ]; then \ |
| 50 | + mkdir -p $(MKCERT_INSTALL_PATH) 2>/dev/null || true; \ |
| 51 | + echo "Downloading mkcert from $(MKCERT_URL)..."; \ |
| 52 | + tmp=$$(mktemp -d); \ |
| 53 | + curl -L --fail -o $$tmp/$(MKCERT_ASSET) "$(MKCERT_URL)"; \ |
| 54 | + chmod +x $$tmp/$(MKCERT_ASSET); \ |
| 55 | + mv $$tmp/$(MKCERT_ASSET) $(MKCERT_INSTALL_PATH)/mkcert || { echo "Failed to move mkcert to $(MKCERT_INSTALL_PATH)"; exit 1; }; \ |
| 56 | + rm -rf $$tmp; \ |
| 57 | + echo "mkcert installed to $(MKCERT_INSTALL_PATH)/mkcert"; \ |
| 58 | + fi |
| 59 | + |
| 60 | +mkcert-install-ca: install-mkcert ## Install mkcert CA into system trust stores |
| 61 | + @echo "Installing mkcert CA..." |
| 62 | + @$(MKCERT_INSTALL_PATH)/mkcert -install |
| 63 | + |
| 64 | +mkcert-generate: mkcert-install-ca ## Generate cert/key for HOSTS into $(CERT_DIR) (usage: make mkcert-generate HOSTS='example.test localhost') |
| 65 | + @mkdir -p $(CERT_DIR) |
| 66 | + @echo "Generating cert for: $(HOSTS)" |
| 67 | + @$(MKCERT_INSTALL_PATH)/mkcert -cert-file $(CERT_DIR)/smtp.crt -key-file $(CERT_DIR)/smtp.key $(HOSTS) |
| 68 | + @echo "Created $(CERT_DIR)/smtp.crt and $(CERT_DIR)/smtp.key" |
| 69 | + @$(MKCERT_INSTALL_PATH)/mkcert -cert-file $(CERT_DIR)/local.crt -key-file $(CERT_DIR)/local.key $(HOSTS) |
| 70 | + @echo "Created $(CERT_DIR)/local.crt and $(CERT_DIR)/local.key" |
| 71 | + |
| 72 | +mkcert-uninstall-ca: install-mkcert ## Uninstall mkcert CA from system trust stores |
| 73 | + @echo "Uninstalling mkcert CA..." |
| 74 | + @$(MKCERT_INSTALL_PATH)/mkcert -uninstall || echo "mkcert -uninstall failed (maybe not installed)" |
| 75 | + |
| 76 | + |
| 77 | +.PHONY: clean |
| 78 | +clean: ## Remove build artifacts |
| 79 | + rm -rf bin/ |
| 80 | + go clean |
| 81 | + |
| 82 | +.PHONY: help |
| 83 | +help: |
| 84 | + @echo 'UTILS - Available commands:' |
| 85 | + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-20s %s\n", $$1, $$2}' $(MAKEFILE_LIST) |
0 commit comments