Files
affiliate_dash/Makefile
T
yml2213 d423fc652c chore(build): 新增 make test/lint/fmt 并修复 testdb 连接串缺陷
- make test 自动拉起并等待 PostgreSQL 就绪;测试用临时 schema 隔离,不污染开发库
- 新增 make test-db / lint / fmt
- 修复 testdb.withSearchPath:原实现用 url.Values.Encode() 重编码整个查询串,
  把 TimeZone=Asia/Shanghai 变成 Asia%2FShanghai,pgx 原样传给服务端后报
  "unknown time zone Asia%2FShanghai",导致数据库起来后集成测试依然全挂。
  改为只追加 search_path,并补测试锁定该行为。
2026-10-06 19:42:49 +08:00

79 lines
2.1 KiB
Makefile

.PHONY: start dev backend frontend install stop fmt lint test test-db docker-build docker-up docker-down docker-logs docker-ps docker-config
ifneq (,$(wildcard .env))
include .env
export
endif
# 一键启动前后端(推荐)
start dev:
@bash ./start.sh
backend:
cd backend && go run ./cmd/server
frontend:
cd frontend && npm run dev
install:
cd backend && go mod tidy
cd frontend && npm install
# 代码格式化(仅后端;前端由 oxlint 负责)
fmt:
@before=$$(gofmt -l backend | wc -l | tr -d ' '); \
gofmt -w backend; \
echo "已格式化;之前存在格式偏差的文件数: $$before"
lint:
cd backend && go vet ./...
cd frontend && npm run lint
# 全量测试:集成测试依赖真实 PostgreSQL,先确保容器起来再跑。
# 测试使用临时 schema 隔离,不会污染开发库(见 backend/internal/testdb)。
test: test-db
cd backend && go test ./...
test-db:
@docker compose up -d postgres
@echo "等待 PostgreSQL 就绪..."
@for i in $$(seq 1 60); do \
if docker compose exec -T postgres pg_isready -U "$${POSTGRES_USER:-affiliate}" -d "$${POSTGRES_DB:-affiliate_dash}" >/dev/null 2>&1; then \
echo "PostgreSQL 已就绪"; \
exit 0; \
fi; \
sleep 1; \
done; \
echo "PostgreSQL 启动超时,请检查: docker compose logs postgres" >&2; \
exit 1
# 停止占用默认端口的进程
stop:
@-lsof -tiTCP:18080 -sTCP:LISTEN | xargs kill 2>/dev/null || true
@-lsof -tiTCP:15173 -sTCP:LISTEN | xargs kill 2>/dev/null || true
@-lsof -tiTCP:15432 -sTCP:LISTEN | xargs kill 2>/dev/null || true
@echo "已尝试停止 18080 / 15173 / 15432 端口服务"
# Docker 部署:宿主机只需要 Docker/Compose,前端与后端都在镜像内构建
docker-build:
@echo "构建 Docker 镜像..."
docker compose build
docker-up:
@echo "启动 Docker Compose 服务..."
docker compose up -d --build
docker-down:
@echo "停止并移除容器..."
docker compose down
docker-logs:
@echo "查看 backend 和 caddy 日志..."
docker compose logs -f backend caddy
docker-ps:
docker compose ps
docker-config:
docker compose config