ci-cd-pipeline-builder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCI/CD Pipeline Builder
CI/CD 流水线构建工具
Tier: POWERFUL
Category: Engineering
Domain: DevOps / Automation
Category: Engineering
Domain: DevOps / Automation
层级: POWERFUL
分类: 工程类
领域: DevOps / 自动化
分类: 工程类
领域: DevOps / 自动化
Overview
概述
Use this skill to generate pragmatic CI/CD pipelines from detected project stack signals, not guesswork. It focuses on fast baseline generation, repeatable checks, and environment-aware deployment stages.
使用此技能可根据检测到的项目栈信号生成务实的CI/CD流水线,而非凭空猜测。它专注于快速生成基线、可重复检查以及感知环境的部署阶段。
Core Capabilities
核心能力
- Detect language/runtime/tooling from repository files
- Recommend CI stages (,
lint,test,build)deploy - Generate GitHub Actions or GitLab CI starter pipelines
- Include caching and matrix strategy based on detected stack
- Emit machine-readable detection output for automation
- Keep pipeline logic aligned with project lockfiles and build commands
- 从仓库文件中检测语言/运行时/工具链
- 推荐CI阶段(、
lint、test、build)deploy - 生成GitHub Actions或GitLab CI初始流水线
- 根据检测到的栈配置缓存和矩阵策略
- 输出机器可读的检测结果用于自动化流程
- 保持流水线逻辑与项目锁文件及构建命令一致
When to Use
使用场景
- Bootstrapping CI for a new repository
- Replacing brittle copied pipeline files
- Migrating between GitHub Actions and GitLab CI
- Auditing whether pipeline steps match actual stack
- Creating a reproducible baseline before custom hardening
- 为新仓库快速搭建CI流程
- 替换脆弱的复制粘贴式流水线文件
- 在GitHub Actions与GitLab CI之间迁移流水线
- 审计流水线步骤是否与实际技术栈匹配
- 在自定义强化前创建可复现的基线
Key Workflows
关键工作流程
1. Detect Stack
1. 检测技术栈
bash
python3 scripts/stack_detector.py --repo . --format text
python3 scripts/stack_detector.py --repo . --format json > detected-stack.jsonSupports input via stdin or file for offline analysis payloads.
--inputbash
python3 scripts/stack_detector.py --repo . --format text
python3 scripts/stack_detector.py --repo . --format json > detected-stack.json支持通过标准输入或文件传入离线分析数据。
--input2. Generate Pipeline From Detection
2. 根据检测结果生成流水线
bash
python3 scripts/pipeline_generator.py \
--input detected-stack.json \
--platform github \
--output .github/workflows/ci.yml \
--format textOr end-to-end from repo directly:
bash
python3 scripts/pipeline_generator.py --repo . --platform gitlab --output .gitlab-ci.ymlbash
python3 scripts/pipeline_generator.py \
--input detected-stack.json \
--platform github \
--output .github/workflows/ci.yml \
--format text或直接从仓库端到端生成:
bash
python3 scripts/pipeline_generator.py --repo . --platform gitlab --output .gitlab-ci.yml3. Validate Before Merge
3. 合并前验证
- Confirm commands exist in project (,
test,lint).build - Run generated pipeline locally where possible.
- Ensure required secrets/env vars are documented.
- Keep deploy jobs gated by protected branches/environments.
- 确认项目中存在对应命令(、
test、lint)。build - 尽可能在本地运行生成的流水线。
- 确保所需密钥/环境变量已记录。
- 部署作业需受保护分支/环境限制。
4. Add Deployment Stages Safely
4. 安全添加部署阶段
- Start with CI-only ().
lint/test/build - Add staging deploy with explicit environment context.
- Add production deploy with manual gate/approval.
- Keep rollout/rollback commands explicit and auditable.
- 先从仅CI阶段开始()。
lint/test/build - 添加带有明确环境上下文的预发布部署。
- 添加需手动确认/审批的生产环境部署。
- 回滚/发布命令需明确且可审计。
Script Interfaces
脚本接口
python3 scripts/stack_detector.py --help- Detects stack signals from repository files
- Reads optional JSON input from stdin/
--input
python3 scripts/pipeline_generator.py --help- Generates GitHub/GitLab YAML from detection payload
- Writes to stdout or
--output
python3 scripts/stack_detector.py --help- 从仓库文件中检测技术栈信号
- 支持从标准输入/读取可选JSON输入
--input
python3 scripts/pipeline_generator.py --help- 根据检测数据生成GitHub/GitLab YAML文件
- 可输出到标准输出或指定路径
--output
Common Pitfalls
常见陷阱
- Copying a Node pipeline into Python/Go repos
- Enabling deploy jobs before stable tests
- Forgetting dependency cache keys
- Running expensive matrix builds for every trivial branch
- Missing branch protections around prod deploy jobs
- Hardcoding secrets in YAML instead of CI secret stores
- 将Node流水线直接复制到Python/Go仓库
- 在测试稳定前启用部署作业
- 忘记配置依赖缓存键
- 对每个小分支都运行耗时的矩阵构建
- 生产部署作业缺少分支保护
- 在YAML中硬编码密钥而非使用CI密钥存储
Best Practices
最佳实践
- Detect stack first, then generate pipeline.
- Keep generated baseline under version control.
- Add one optimization at a time (cache, matrix, split jobs).
- Require green CI before deployment jobs.
- Use protected environments for production credentials.
- Regenerate pipeline when stack changes significantly.
- 先检测技术栈,再生成流水线。
- 将生成的基线纳入版本控制。
- 逐步添加优化项(缓存、矩阵、拆分作业)。
- 部署作业需依赖CI流程执行成功。
- 为生产环境凭证使用受保护环境。
- 当技术栈发生重大变化时重新生成流水线。
References
参考资料
- references/github-actions-templates.md
- references/gitlab-ci-templates.md
- references/deployment-gates.md
- README.md
- references/github-actions-templates.md
- references/gitlab-ci-templates.md
- references/deployment-gates.md
- README.md
Detection Heuristics
检测规则
The stack detector prioritizes deterministic file signals over heuristics:
- Lockfiles determine package manager preference
- Language manifests determine runtime families
- Script commands (if present) drive lint/test/build commands
- Missing scripts trigger conservative placeholder commands
技术栈检测器优先使用确定性文件信号而非启发式规则:
- 锁文件决定包管理器优先级
- 语言清单文件决定运行时类型
- 脚本命令(若存在)决定lint/test/build命令
- 缺失脚本时生成保守的占位命令
Generation Strategy
生成策略
Start with a minimal, reliable pipeline:
- Checkout and setup runtime
- Install dependencies with cache strategy
- Run lint, test, build in separate steps
- Publish artifacts only after passing checks
Then layer advanced behavior (matrix builds, security scans, deploy gates).
从最小化的可靠流水线开始:
- 拉取代码并配置运行时
- 带缓存策略安装依赖
- 分步骤运行lint、test、build
- 仅在检查通过后发布制品
之后再添加高级功能(矩阵构建、安全扫描、部署闸门)。
Platform Decision Notes
平台选择说明
- GitHub Actions for tight GitHub ecosystem integration
- GitLab CI for integrated SCM + CI in self-hosted environments
- Keep one canonical pipeline source per repo to reduce drift
- GitHub Actions:适合与GitHub生态深度集成
- GitLab CI:适合自托管环境下的一体化SCM + CI
- 每个仓库保留一个标准流水线源以减少差异
Validation Checklist
验证清单
- Generated YAML parses successfully.
- All referenced commands exist in the repo.
- Cache strategy matches package manager.
- Required secrets are documented, not embedded.
- Branch/protected-environment rules match org policy.
- 生成的YAML可成功解析。
- 所有引用的命令在仓库中存在。
- 缓存策略与包管理器匹配。
- 所需密钥已记录,未嵌入文件。
- 分支/受保护环境规则符合组织策略。
Scaling Guidance
扩展指南
- Split long jobs by stage when runtime exceeds 10 minutes.
- Introduce test matrix only when compatibility truly requires it.
- Separate deploy jobs from CI jobs to keep feedback fast.
- Track pipeline duration and flakiness as first-class metrics.
- 当作业运行时间超过10分钟时,按阶段拆分长作业。
- 仅在确实需要兼容性验证时引入测试矩阵。
- 将部署作业与CI作业分离以保持快速反馈。
- 将流水线时长和不稳定率作为核心指标跟踪。