safe-deploy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSafe Deploy
安全部署
Core Rule
核心规则
NEVER deploy to production without first verifying the branch includes all commits from .
origin/mainThis 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:
-
Fetch latest mainbash
git fetch origin main -
Check if branch is up-to-datebash
git merge-base --is-ancestor origin/main HEAD- Exit code 0 = safe to deploy
- Exit code 1 = STOP, branch is behind main
-
If behind, show missing commitsbash
git log --oneline origin/main ^HEAD -
Merge before deployingbash
git merge origin/main -
Run tests after mergebash
npx vitest run -
Only then deploy
按顺序执行以下检查:
-
拉取最新的main分支bash
git fetch origin main -
检查分支是否为最新版本bash
git merge-base --is-ancestor origin/main HEAD- 退出码0 = 可以安全部署
- 退出码1 = 停止,分支落后于main分支
-
若分支落后,显示缺失的提交bash
git log --oneline origin/main ^HEAD -
部署前合并分支bash
git merge origin/main -
合并后运行测试bash
npx vitest run -
仅在完成上述步骤后部署
Automated Enforcement
自动化强制执行
Projects should have a npm script that runs automatically before . If the project has this script, always use instead of calling the deploy tool directly.
predeployscripts/pre-deploy-check.mjsnpm run deploynpm run deploy项目应配置 npm脚本,在自动运行。如果项目有此脚本,请始终使用,而非直接调用部署工具。
predeploynpm run deployscripts/pre-deploy-check.mjsnpm run deployWhen This Applies
适用场景
- Running
npm run deploy - Running directly
wrangler pages deploy - 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
操作规范
- Always check branch status against first
origin/main - If behind, inform the user and merge before proceeding
- Run tests after merge to catch conflicts
- Only deploy after tests pass
- Never skip this check, even if the user says "just deploy"
- 始终先检查分支相对于的状态
origin/main - 若分支落后,通知用户并在继续前合并
- 合并后运行测试以发现冲突
- 仅在测试通过后部署
- 绝对不要跳过此检查,即使用户说“直接部署”