safe-deploy

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Safe Deploy

安全部署

Core Rule

核心规则

NEVER deploy to production without first verifying the branch includes all commits from
origin/main
.
This prevents the critical bug where a feature branch deploys older code that overwrites recently merged PRs.
在未先验证分支包含
origin/main
的所有提交之前,绝对不要部署到生产环境。
这可以防止功能分支部署旧代码覆盖最近合并的PR这一严重问题。

Before Every Deploy

每次部署前的步骤

Run these checks in order:
  1. Fetch latest main
    bash
    git fetch origin main
  2. Check if branch is up-to-date
    bash
    git merge-base --is-ancestor origin/main HEAD
    • Exit code 0 = safe to deploy
    • Exit code 1 = STOP, branch is behind main
  3. If behind, show missing commits
    bash
    git log --oneline origin/main ^HEAD
  4. Merge before deploying
    bash
    git merge origin/main
  5. Run tests after merge
    bash
    npx vitest run
  6. Only then deploy
按顺序执行以下检查:
  1. 拉取最新的main分支
    bash
    git fetch origin main
  2. 检查分支是否为最新版本
    bash
    git merge-base --is-ancestor origin/main HEAD
    • 退出码0 = 可以安全部署
    • 退出码1 = 停止,分支落后于main分支
  3. 若分支落后,显示缺失的提交
    bash
    git log --oneline origin/main ^HEAD
  4. 部署前合并分支
    bash
    git merge origin/main
  5. 合并后运行测试
    bash
    npx vitest run
  6. 仅在完成上述步骤后部署

Automated Enforcement

自动化强制执行

Projects should have a
predeploy
npm script that runs
scripts/pre-deploy-check.mjs
automatically before
npm run deploy
. If the project has this script, always use
npm run deploy
instead of calling the deploy tool directly.
项目应配置
predeploy
npm脚本,在
npm run deploy
自动运行
scripts/pre-deploy-check.mjs
。如果项目有此脚本,请始终使用
npm run deploy
,而非直接调用部署工具。

When This Applies

适用场景

  • Running
    npm run deploy
  • Running
    wrangler pages deploy
    directly
  • Any command that pushes code to production
  • When the user asks to "deploy", "push to production", or "ship it"
  • 运行
    npm run deploy
  • 直接运行
    wrangler pages deploy
  • 任何将代码推送到生产环境的命令
  • 当用户要求“部署”、“推送到生产环境”或“发布”时

What To Do

操作规范

  1. Always check branch status against
    origin/main
    first
  2. If behind, inform the user and merge before proceeding
  3. Run tests after merge to catch conflicts
  4. Only deploy after tests pass
  5. Never skip this check, even if the user says "just deploy"
  1. 始终先检查分支相对于
    origin/main
    的状态
  2. 若分支落后,通知用户并在继续前合并
  3. 合并后运行测试以发现冲突
  4. 仅在测试通过后部署
  5. 绝对不要跳过此检查,即使用户说“直接部署”