#!/usr/bin/env bash # /look —— 一键:验证 → 构建 → 推 feature(源码)+ deploy(产物)→ 服务器拉取 → 上线 # 用法:bash infra/look.sh ["提交说明"] set -euo pipefail cd "$(dirname "$0")/.." MSG="${1:-chore: update}" SERVER="bigdata@100.64.0.62" SERVER_DIR="\$HOME/hs-data" # 服务器上 deploy 分支的 clone URL="http://100.64.0.62:8080/" echo "==> 1/5 验证 + 构建(real API:VITE_USE_MOCK=false)" corepack pnpm@10 --filter @hs-data/web test # 线上由服务器 uvicorn 同源托管 /api(真实 PG),构建关掉 mock。 VITE_USE_MOCK=false corepack pnpm@10 --filter @hs-data/web build echo "==> 2/5 源码 → 当前分支" BR="$(git branch --show-current)" [ "$BR" = "feature" ] || echo " ⚠️ 当前分支是 '$BR'(预期 feature),仍推到它以保持源码/部署同步" git add -A git diff --cached --quiet || git commit -q -m "$MSG" git push -q origin "$BR" echo "==> 3/5 产物 → deploy 分支(worktree 快进推送,无 force)" git fetch -q origin deploy WT="../hs-deploy-tmp" git worktree remove -f "$WT" 2>/dev/null || true git worktree add -f "$WT" origin/deploy >/dev/null find "$WT" -mindepth 1 -maxdepth 1 ! -name .git -exec rm -rf {} + cp -r apps/web/dist/. "$WT"/ ( cd "$WT" git add -A git diff --cached --quiet || git commit -q -m "deploy: $MSG" git push -q origin HEAD:deploy ) git worktree remove -f "$WT" echo "==> 4/5 服务器拉取(git pull,非 scp)+ 后端按需重启" # 前端产物:uvicorn 以 STATIC_DIR 实时读盘,纯前端改动无需重启(不抖)。 # 后端源码(~/hs-api):仅当 HEAD 变化才重启 uvicorn(新依赖需手动 pip,少见)。 ssh -o BatchMode=yes "$SERVER" ' cd $HOME/hs-data && GIT_TERMINAL_PROMPT=0 git pull -q cd $HOME/hs-api && before=$(git rev-parse HEAD) && GIT_TERMINAL_PROMPT=0 git pull -q && after=$(git rev-parse HEAD) if [ "$before" != "$after" ]; then echo "后端有更新 → 重启 uvicorn"; pkill -f "uvicorn app.main:app" || true; sleep 1; fi bash $HOME/serve-hs-api.sh echo pulled-ok ' echo "==> 5/5 完成 → $URL"