Commit 3626c1c02c433ca6dc90355dc56804f16626804d

Authored by zichun
1 parent 723621ed

chore(infra): make scripts/test.sh runnable on macOS without preset PATH

- setup-test-db.sh: prepend Homebrew mysql-client bin paths if present
- test.sh: skip frontend build/lint/test segments when frontend/ absent
scripts/setup-test-db.sh
... ... @@ -13,6 +13,12 @@
13 13  
14 14 set -euo pipefail
15 15  
  16 +# macOS Homebrew 的 mysql-client 是 keg-only,默认不在 PATH;非交互式 bash 也不读 ~/.zshrc。
  17 +# 这里幂等 prepend 常见安装路径,命中则用,未命中(如 Linux CI 已自带 mysql)则跳过。
  18 +for p in /opt/homebrew/opt/mysql-client/bin /usr/local/opt/mysql-client/bin; do
  19 + [ -d "$p" ] && case ":$PATH:" in *":$p:"*) ;; *) PATH="$p:$PATH" ;; esac
  20 +done
  21 +
16 22 ENV_FILE="$(dirname "$0")/../.env.local"
17 23 [ -f "$ENV_FILE" ] || { echo "[setup-test-db] ⚠️ .env.local 不存在($ENV_FILE)" >&2; exit 1; }
18 24  
... ...
scripts/test.sh
... ... @@ -12,13 +12,27 @@ echo "[test.sh] 1/6 setup test db"
12 12 ./scripts/setup-test-db.sh
13 13  
14 14 echo "[test.sh] 2/6 build"
15   -(cd backend && mvn -B -DskipTests clean package) && (cd frontend && npm ci && npm run build)
  15 +(cd backend && mvn -B -DskipTests clean package)
  16 +if [ -d frontend ]; then
  17 + (cd frontend && npm ci && npm run build)
  18 +else
  19 + echo "[test.sh] skip frontend build (frontend/ not initialized yet)"
  20 +fi
16 21  
17 22 echo "[test.sh] 3/6 lint"
18   -(cd frontend && npm run lint)
  23 +if [ -d frontend ]; then
  24 + (cd frontend && npm run lint)
  25 +else
  26 + echo "[test.sh] skip frontend lint (frontend/ not initialized yet)"
  27 +fi
19 28  
20 29 echo "[test.sh] 4/6 unit + integration"
21   -(cd backend && mvn -B test) && (cd frontend && npm test -- --run)
  30 +(cd backend && mvn -B test)
  31 +if [ -d frontend ]; then
  32 + (cd frontend && npm test -- --run)
  33 +else
  34 + echo "[test.sh] skip frontend unit tests (frontend/ not initialized yet)"
  35 +fi
22 36  
23 37 echo "[test.sh] 5/6 E2E"
24 38 echo "[test.sh] e2e 略"
... ...