workflow-setup
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTable of Contents
目录
- When To Use
- Standard Workflows
- Python Workflows
- Rust Workflows
- TypeScript Workflows
- Workflow
- 1. Check Existing Workflows
- 2. Identify Missing Workflows
- 3. Render Workflow Templates
- 4. Validate Workflows
- Workflow Best Practices
- Use Latest Action Versions
- Matrix Testing (Python)
- Caching Dependencies
- Updating Workflows
- Related Skills
Workflow Setup Skill
工作流搭建技能
Set up GitHub Actions workflows for continuous integration and deployment.
为持续集成与部署搭建GitHub Actions工作流。
When To Use
适用场景
- Need CI/CD for a new project
- Adding missing workflows to existing project
- Updating workflow versions to latest
- Automating testing and quality checks
- Setting up deployment pipelines
- 新项目需要CI/CD
- 为现有项目补充缺失的工作流
- 将工作流版本更新至最新
- 自动化测试与质量检查
- 搭建部署流水线
When NOT To Use
不适用场景
- GitHub Actions workflows already configured and current
- Project uses different CI platform (GitLab CI, CircleCI, etc.)
- Not hosted on GitHub
- Use instead for updating existing workflows
/attune:upgrade-project
- 已配置并使用当前版本的GitHub Actions工作流
- 项目使用其他CI平台(GitLab CI、CircleCI等)
- 项目未托管在GitHub上
- 更新现有工作流请使用
/attune:upgrade-project
Standard Workflows
标准工作流
Python Workflows
Python工作流
- test.yml - Run pytest on push/PR
- lint.yml - Run ruff linting
- typecheck.yml - Run mypy type checking
- publish.yml - Publish to PyPI on release
- test.yml - 在推送/PR时运行pytest测试
- lint.yml - 运行ruff代码检查
- typecheck.yml - 运行mypy类型检查
- publish.yml - 在发布时推送至PyPI
Rust Workflows
Rust工作流
- ci.yml - Combined test/lint/check workflow
- release.yml - Build and publish releases
- ci.yml - 整合测试/代码检查/验证的工作流
- release.yml - 构建并发布版本
TypeScript Workflows
TypeScript工作流
- test.yml - Run Jest tests
- lint.yml - Run ESLint
- build.yml - Build for production
- deploy.yml - Deploy to hosting (Vercel, Netlify, etc.)
- test.yml - 运行Jest测试
- lint.yml - 运行ESLint代码检查
- build.yml - 构建生产环境版本
- deploy.yml - 部署至托管平台(Vercel、Netlify等)
Workflow
操作流程
1. Check Existing Workflows
1. 检查现有工作流
bash
ls -la .github/workflows/Verification: Run the command with flag to verify availability.
--helpbash
ls -la .github/workflows/验证方式: 加上参数运行命令,确认其可用。
--help2. Identify Missing Workflows
2. 识别缺失的工作流
python
from project_detector import ProjectDetector
detector = ProjectDetector(Path.cwd())
language = detector.detect_language()
required_workflows = {
"python": ["test.yml", "lint.yml", "typecheck.yml"],
"rust": ["ci.yml"],
"typescript": ["test.yml", "lint.yml", "build.yml"],
}
missing = detector.get_missing_configurations(language)Verification: Run to verify tests pass.
pytest -vpython
from project_detector import ProjectDetector
detector = ProjectDetector(Path.cwd())
language = detector.detect_language()
required_workflows = {
"python": ["test.yml", "lint.yml", "typecheck.yml"],
"rust": ["ci.yml"],
"typescript": ["test.yml", "lint.yml", "build.yml"],
}
missing = detector.get_missing_configurations(language)验证方式: 运行确认测试通过。
pytest -v3. Render Workflow Templates
3. 渲染工作流模板
python
workflows_dir = Path(".github/workflows")
workflows_dir.mkdir(parents=True, exist_ok=True)
for workflow in required_workflows[language]:
template = templates_dir / language / "workflows" / f"{workflow}.template"
output = workflows_dir / workflow
engine.render_file(template, output)
print(f"✓ Created: {output}")Verification: Run the command with flag to verify availability.
--helppython
workflows_dir = Path(".github/workflows")
workflows_dir.mkdir(parents=True, exist_ok=True)
for workflow in required_workflows[language]:
template = templates_dir / language / "workflows" / f"{workflow}.template"
output = workflows_dir / workflow
engine.render_file(template, output)
print(f"✓ Created: {output}")验证方式: 加上参数运行命令,确认其可用。
--help4. Validate Workflows
4. 验证工作流
bash
undefinedbash
undefinedSyntax check (requires act or gh CLI)
语法检查(需要act或gh CLI)
gh workflow list
gh workflow list
Or manually check YAML syntax
或手动检查YAML语法
python3 -c "import yaml; yaml.safe_load(open('.github/workflows/test.yml'))"
**Verification:** Run `pytest -v` to verify tests pass.python3 -c "import yaml; yaml.safe_load(open('.github/workflows/test.yml'))"
**验证方式:** 运行`pytest -v`确认测试通过。Workflow Best Practices
工作流最佳实践
Use Latest Action Versions
使用最新Action版本
yaml
undefinedyaml
undefinedGood - pinned to major version
推荐 - 固定到主版本
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Avoid - unpinned or outdated
避免 - 未固定或版本过时
- uses: actions/checkout@v2
- uses: actions/setup-python@latest
**Verification:** Run `pytest -v` to verify tests pass.- uses: actions/checkout@v2
- uses: actions/setup-python@latest
**验证方式:** 运行`pytest -v`确认测试通过。Matrix Testing (Python)
矩阵测试(Python)
yaml
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]Verification: Run to verify tests pass.
pytest -vyaml
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]验证方式: 运行确认测试通过。
pytest -vCaching Dependencies
依赖缓存
yaml
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip' # Cache pip dependenciesVerification: Run to verify Python environment.
python --versionyaml
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip' # 缓存pip依赖验证方式: 运行确认Python环境正确。
python --versionShell Script Safety in Workflows
工作流中的Shell脚本安全
When writing inline shell scripts in workflows, ensure proper exit code handling:
yaml
undefined在工作流中编写内联Shell脚本时,需确保正确处理退出码:
yaml
undefinedBAD - pipeline masks exit code
错误示例 - 流水线会掩盖退出码
- run: | make typecheck 2>&1 | grep -v "^make[" echo "Typecheck passed" # Runs even if make failed!
- run: | make typecheck 2>&1 | grep -v "^make[" echo "Typecheck passed" # 即使make失败也会执行!
GOOD - use pipefail
正确示例 - 使用pipefail
- run: | set -eo pipefail make typecheck 2>&1 | grep -v "^make["
- run: | set -eo pipefail make typecheck 2>&1 | grep -v "^make["
GOOD - capture exit code explicitly
正确示例 - 显式捕获退出码
- run: | output=$(make typecheck 2>&1) || exit_code=$? echo "$output" | grep -v "^make[" || true exit ${exit_code:-0}
For complex wrapper scripts, run `/pensive:shell-review` before integrating.- run: | output=$(make typecheck 2>&1) || exit_code=$? echo "$output" | grep -v "^make[" || true exit ${exit_code:-0}
对于复杂的包装脚本,集成前请运行`/pensive:shell-review`。Updating Workflows
更新工作流
To update workflows to latest versions:
bash
/attune:upgrade-project --component workflowsVerification: Run the command with flag to verify availability.
--help将工作流更新至最新版本:
bash
/attune:upgrade-project --component workflows验证方式: 加上参数运行命令,确认其可用。
--helpRelated Skills
相关技能
- - Full project initialization
Skill(attune:project-init) - - PR preparation with CI checks
Skill(sanctum:pr-prep)
- - 完整项目初始化
Skill(attune:project-init) - - 包含CI检查的PR准备
Skill(sanctum:pr-prep)
Troubleshooting
故障排查
Common Issues
常见问题
Command not found
Ensure all dependencies are installed and in PATH
Permission errors
Check file permissions and run with appropriate privileges
Unexpected behavior
Enable verbose logging with flag
--verbose命令未找到
确保所有依赖已安装并在PATH中
权限错误
检查文件权限并使用适当权限运行
异常行为
添加参数启用详细日志
--verbose