spark-server/Makefile
2026-09-21 15:42:16 +08:00

60 lines
1.3 KiB
Makefile

GO ?= go
MODULE := spark-server
BIN := bin/spark-server
LINT ?= golangci-lint
CONFIG ?= configs/config.yaml
LOGIC_COVER_MIN ?= 65
.PHONY: all build test lint fmt vet tidy migrate start run deploy
all: lint test build
build:
$(GO) build -o $(BIN) ./cmd/server
# All unit tests, then each module logic package must be >= LOGIC_COVER_MIN.
test:
$(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:
$(LINT) run ./...
tidy:
$(GO) mod tidy
migrate:
$(GO) run ./cmd/migrate -config $(CONFIG)
start:
$(GO) run ./cmd/server -config $(CONFIG)
run: build
./$(BIN) -config $(CONFIG)
deploy:
bash deploy/docker/deploy.sh