GO ?= go MODULE := spark-server BIN := bin/spark-server LINUX_DIR := bin/linux_amd64 IMAGE ?= spark-server:latest LDFLAGS := -s -w -buildid= # Note: GNU Make predefines LINT=lint (lex); use := so golangci-lint wins over the builtin. GOLANGCI_LINT := golangci-lint CONFIG ?= configs/config.yaml LOGIC_COVER_MIN ?= 65 .PHONY: all build image test lint fmt vet tidy migrate seed start run deploy deploy-rollback install-git-hooks all: test build build: $(GO) build -o $(BIN) ./cmd/server # Cross-compile for ECS and pack a runtime-only amd64 image (no Go toolchain in the image). image: @command -v docker >/dev/null || { echo "docker is required for make image" >&2; exit 1; } mkdir -p $(LINUX_DIR) CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(LINUX_DIR)/spark-server ./cmd/server CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(LINUX_DIR)/spark-migrate ./cmd/migrate CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(GO) build -trimpath -ldflags="$(LDFLAGS)" -o $(LINUX_DIR)/spark-seed ./cmd/seed docker build --platform linux/amd64 -t $(IMAGE) . # All unit tests, then each module logic package must be >= LOGIC_COVER_MIN. # Requires lint to pass first. test: lint $(GO) test ./... @echo "==> logic Service coverage (>= $(LOGIC_COVER_MIN)%)" @covout=$$($(GO) test -cover ./internal/module/*/logic); \ status=$$?; \ printf '%s\n' "$$covout"; \ if [ $$status -ne 0 ]; then exit $$status; fi; \ printf '%s\n' "$$covout" | awk -v min=$(LOGIC_COVER_MIN) ' \ BEGIN { bad=0 } \ /\[no test files\]/ { printf "FAIL %s: no test files\n", $$2; bad=1; next } \ { \ cov=""; \ for (i = 1; i <= NF; i++) { \ if ($$i == "coverage:") { cov=$$(i+1); break } \ } \ if (cov == "" || cov == "[no") next; \ gsub("%", "", cov); \ if (cov+0 < min+0) { printf "FAIL %s: coverage %s%% < %s%%\n", $$2, cov, min; bad=1 } \ } \ END { if (bad) exit 1 }' vet: $(GO) vet ./... fmt: $(GO) fmt ./... lint: $(GOLANGCI_LINT) run ./... tidy: $(GO) mod tidy migrate: $(GO) run ./cmd/migrate -config $(CONFIG) seed: $(GO) run ./cmd/seed -config $(CONFIG) start: $(GO) run ./cmd/server -config $(CONFIG) run: build ./$(BIN) -config $(CONFIG) deploy: test bash deploy/docker/deploy.sh deploy-rollback: bash deploy/docker/rollback.sh # Copy pre-commit hook: runs `make test` before every commit (see .cursor/rules/git-commit-gate.mdc). install-git-hooks: @test -d .git || { echo "not a git repository" >&2; exit 1; } @mkdir -p .git/hooks @cp scripts/git-hooks/pre-commit .git/hooks/pre-commit @chmod +x scripts/git-hooks/pre-commit .git/hooks/pre-commit @echo "Installed .git/hooks/pre-commit → make test"