home / skills / einverne / dotfiles / deploy-staging

deploy-staging skill

/skills/deploy-staging

This skill deploys the current branch to staging after pre-checks, builds, runs deployment, and validates health, reporting results and offering rollback.

npx playbooks add skill einverne/dotfiles --skill deploy-staging

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
1.3 KB
---
name: deploy-staging
description: 将当前分支部署到测试环境。当用户要求部署、发布到测试或在 staging 环境测试时使用
---

# 部署到测试环境

## 前置条件检查

执行部署前,必须验证:

1. 当前分支所有变更已提交
   - 运行 `git status` 检查
   - 如有未提交内容,提示用户先提交

2. 所有测试通过
   - 运行 `npm test`
   - 如测试失败,停止部署并报告失败原因

3. 代码已推送到远程仓库
   - 运行 `git push`
   - 确保远程分支是最新状态

## 部署流程

1. 构建生产版本
   ```bash
   npm run build:staging
   ```

2. 运行部署脚本
   ```bash
   ./scripts/deploy-staging.sh
   ```

3. 等待部署完成
   - 显示部署进度
   - 捕获并显示错误信息

4. 验证部署
   ```bash
   curl -f https://staging.example.com/health
   ```

5. 报告部署结果
   - 成功:提供访问链接
   - 失败:显示错误日志和回滚建议

## 错误处理

如果部署失败:
1. 保存错误日志到 `.logs/deploy-staging-{timestamp}.log`
2. 建议用户检查日志
3. 提供回滚命令:`./scripts/rollback-staging.sh`

## 部署后检查

部署成功后,提醒用户验证:
- 关键功能是否正常
- 数据库迁移是否成功
- 静态资源是否加载正常

Overview

This skill deploys the current Git branch to a staging environment with pre-checks, build, deploy, verification, and post-deploy guidance. It automates the common steps required to push a branch to staging and surfaces failures, logs, and rollback options. Use it when you want a repeatable, safe staging release process.

How this skill works

The skill first validates repository state: ensures all changes are committed, tests pass, and commits are pushed to the remote. It runs a staging build, executes the staging deployment script, streams progress and errors, then performs a health check against the staging URL. On failure it saves logs, shows error details, and suggests a rollback command.

When to use it

  • You want to deploy the current branch to the staging environment for testing.
  • Before requesting QA or stakeholder review on staging.
  • When preparing a pre-production verification after feature work.
  • After merging feature work but before production release.

Best practices

  • Commit or stash all changes before running the deploy to avoid partial deploys.
  • Run the full test suite locally (npm test) and fix failures before deploying.
  • Push your branch to the remote so the staging environment builds from the expected ref.
  • Monitor the deployment output and run the health check (curl -f https://staging.example.com/health) after completion.
  • Save and inspect the timestamped log file if deployment fails, then use the provided rollback script.

Example use cases

  • Developer finished a feature branch and needs it available on staging for QA.
  • A bug fix that must be validated in an environment mirroring production.
  • Release candidate verification before scheduling a production deploy.
  • Automated CI job triggers a manual staging deployment when preconditions are met.

FAQ

What happens if tests fail before deployment?

Deployment stops and the failing test output is reported. Fix tests locally and re-run the deploy.

How do I roll back a failed staging deploy?

Inspect the saved log file (.logs/deploy-staging-{timestamp}.log) for root cause, then run the rollback script: ./scripts/rollback-staging.sh