No. 095 部署上线

部署前检查清单

当变更需要离开本机时使用

  • Claude Code
  • Codex
  • Cursor
  • 部署上线

提示词

译

# 部署前检查清单

请帮我确认我们已准备好部署到 ${ENVIRONMENT:-production}。

部署类型:${DEPLOY_TYPE:-standard}
目标分支:${TARGET_BRANCH:-main}
跳过检查:${SKIP_CHECKS:-none}

## 关键检查

1. **移除调试代码**:
   ```bash
   # Check for console logs
   ch cq console-logs
   
   # Find debug flags
   chs find-code "DEBUG|debug.*=.*true|__DEV__"
   
   # Check for development URLs
   chs find-code "localhost|127\\.0\\.0\\.1|192\\.168\\."
   ```

2. **环境配置**:
   ```bash
   # Find environment variables
   chs find-code "process\\.env\\.|ENV\\[|getenv\\("
   
   # Check for missing defaults
   chs find-code "process\\.env\\.\\w+" 2>/dev/null | while IFS= read -r match; do
     echo "$match" | grep -q "||" || echo "Missing default: $match"
   done
   
   # Verify .env.example is updated
   diff .env .env.example 2>/dev/null || echo "Check .env files"
   ```

3. **安全扫描**:
   ```bash
   # Final secrets check
   ch cq secrets-scan
   
   # Check file permissions
   find . -type f -name "*.${SCRIPT_EXT:-sh|py}" -exec ls -la {} \; | grep -v "r--"
   
   # Verify no sensitive files
   chs find-file "*.pem|*.key|*.env|*.secret"
   ```

4. **构建验证**:
   ```bash
   # Clean build
   # Remove any build artifacts (adjust paths for your project)
   # Examples: dist/, build/, target/, out/, _site/
   
   # Run your project's build command
   # Examples: npm run build, make build, gradle build, etc.
   
   # Verify no source maps or debug files in production
   # Check your build output directory for .map files or debug symbols
   ```

5. **测试套件**:
   ```bash
   # Run your project's test suite
   # Examples: npm test, pytest, go test, mvn test, etc.
   
   # Run E2E/integration tests if available
   
   # Check test coverage if configured
   ```

6. **数据库检查**:
   ```bash
   # Find migration files
   chs find-file "*migration*|*migrate*" --sort-date | tail -5
   
   # Check for migration conflicts
   git diff "${TARGET_BRANCH:-main}" --name-only | grep -i migration
   
   # Look for schema changes
   chs find-code "CREATE TABLE|ALTER TABLE|DROP TABLE"
   ```

7. **性能检查**:
   ```bash
   # Check build size (if applicable)
   # Look for unexpectedly large files in your build output
   
   # Find large assets in your build directory
   # Adjust the path to match your build output location
   
   # Check for unoptimized images
   find . -name "*.png" -o -name "*.jpg" -size "+${IMG_SIZE:-500k}"
   ```

8. **文档**:
   ```bash
   # Check if README is updated
   git diff ${TARGET_BRANCH:-main} README.md
   
   # Verify API docs if applicable
   chs find-file "*api*.md|*API*.md"
   
   # Check changelog
   git log --oneline ${TARGET_BRANCH:-main}..HEAD > PENDING_CHANGES.txt
   ```

## 部署就绪

### 版本检查:
- [ ] 版本已适当递增
- [ ] 变更日志已更新
- [ ] 如需要已创建标签

### 基础设施:
- [ ] 数据库迁移已就绪
- [ ] 环境变量已设置
- [ ] 如需要已清除 CDN 缓存
- [ ] 监控告警已配置

### 回滚计划:
- [ ] 上一版本已打标签
- [ ] 回滚脚本已测试
- [ ] 数据库回滚计划
- [ ] 功能开关已就绪

## 最终验证

```bash
# Generate deployment summary
echo "=== Deployment Summary ==="
echo "Environment: ${ENVIRONMENT:-production}"
echo "Branch: $(git branch --show-current)"
echo "Commit: $(git rev-parse --short HEAD)"
echo "Changes: $(git rev-list --count ${TARGET_BRANCH:-main}..HEAD) commits"
echo ""
echo "Files changed:"
git diff --stat ${TARGET_BRANCH:-main}
```

## 部署后检查清单

- [ ] 冒烟测试通过
- [ ] 监控显示指标正常
- [ ] 日志中没有错误激增
- [ ] 关键功能已验证
- [ ] 性能指标正常

请确认所有检查均通过,并提供部署建议。

什么时候用

「部署前检查清单」 是当变更需要离开本机时打开的操作面板,因为它写着“部署前检查清单”,且其写下的第一步是“移除调试代码:”。

对于 「部署前检查清单」,你额外输入的一行就是这些步骤所要求的需求,例如“让 src/cart.js 在空购物车时返回 0,并跳过没有价格的行”,然后文件从“移除调试代码:”开始。

什么时候别用

当变更仍只是本地问题且没有任何内容准备发布时,不要使用 「部署前检查清单」,因为“部署前检查清单”指向的是另一方向

怎么用

Claude Code

Claude Code 将 「部署前检查清单」 存储为 Claude 命令,并通过 这个命令 运行,把需求放在参数中;CLAUDE.md 不应同时包含“部署前检查清单”。

Codex

Codex 将 「部署前检查清单」 作为任务上方的粘贴内容。保持 AGENTS.md 不变,以免下一个线程继承“部署前检查清单”。

Cursor

Cursor 应仅在本次会话中把 「部署前检查清单」 视为对“部署前检查清单”的聊天粘贴内容。放在 .cursor/rules 的文件会在本次会话结束后继续生效。

使用前后对比

对比待补

这条前后对比还没有在本机跑过。

相关

来源:Darin Cassler · https://github.com/cassler/awesome-claude-code-setup/blob/main/commands/pre-deploy-check.md · MIT · Copyright (c) 2025 Darin Cassler · 2026-12-01