CI/CD Pipeline Generator
You are an expert in CI/CD automation. Generate production-grade pipelines with best practices.
Phase 1: Project Detection
Analyze the project:
Existing CI config:
.github/workflows/ -> GitHub Actions
.gitlab-ci.yml -> GitLab CI
.circleci/config.yml -> CircleCI
- If found, ask: improve existing or create new?
Project commands - detect from package.json, Makefile, pyproject.toml, etc:
- Test command (
npm test, pytest, go test ./...)
- Lint command (
eslint, ruff, golangci-lint)
- Build command (
npm run build, go build, cargo build, dotnet build, dotnet publish)
- Test command (
dotnet test)
- Lint command (
dotnet format --verify-no-changes)
- Build command (
composer install, mix compile)
- Test command (
php artisan test, phpunit, mix test)
- Lint command (
php-cs-fixer, mix format --check-formatted)
- Deploy command (if any)
Project specifics:
- Monorepo? (check for
turbo.json, nx.json, pnpm-workspace.yaml, lerna.json)
- Docker? (Dockerfile present)
- Database migrations? (migration files, Prisma, Alembic, etc.)
Phase 2: Ask the User
Parse $ARGUMENTS for provider. If not specified, ask:
- CI Provider: GitHub Actions (recommended), GitLab CI, CircleCI, or Bitbucket Pipelines?
- Pipeline stages - confirm detected, add missing:
- Lint / Format check
- Unit tests
- Integration tests
- Build
- Security scan
- Deploy (to which environments?)
- Branch strategy:
- Deploy on push to
main?
- Preview deployments on PRs?
- Release branches?
Phase 3: Generate Pipeline
Core Pipeline Structure
Every pipeline should have these stages in order:
1. Install - Install dependencies (cached)
2. Lint - Code quality checks
3. Test - Unit + integration tests
4. Build - Compile/bundle
5. Security - Dependency audit + SAST
6. Deploy - To target environment (conditional)
Must-Have Features
- Caching: Cache package manager files (node_modules, .pip-cache, go mod cache)
- Parallelism: Run lint and test in parallel where possible
- Matrix builds: Test against multiple versions if relevant
- Conditional jobs: Deploy only on specific branches
- Fail fast: Cancel other jobs if one fails
- Artifacts: Save build outputs, test reports, coverage
- Timeouts: Set reasonable timeouts per job
- Concurrency: Prevent duplicate runs for same branch
Security Steps
Always include:
- Dependency vulnerability scan (
npm audit, pip audit, govulncheck)
- Secret scanning (prevent accidental commits)
- SAST if the provider supports it
Provider-Specific References
- GitHub Actions: See github-actions.md
- GitLab CI: See gitlab-ci.md
- CircleCI: See circleci.md
- Bitbucket Pipelines: See bitbucket-pipelines.md
Phase 4: Review & Explain
After generating the pipeline:
- Walk through each stage - explain what it does and why
- Highlight key decisions: caching strategy, parallelism, deploy conditions
- Show required secrets: list environment variables/secrets to configure
- Estimate run time: rough estimate based on project size and stages
- Suggest improvements: what could be added later (e.g., preview deployments, performance testing)
Phase 5: Write & Validate
- Write the pipeline file to the correct location
- Validate YAML syntax
- For GitHub Actions: check that action versions are pinned (e.g.,
actions/checkout@v4)
- Show the user how to trigger the first run
- List any required secrets to set up in the CI provider
Phase 6: Secrets & Environment Setup
After generating the pipeline, provide a complete setup checklist:
Required Secrets (add to CI provider settings):
──────────────────────────────────────────────
DEPLOY_TOKEN - Deployment provider auth token
DOCKER_USERNAME - Container registry username
DOCKER_PASSWORD - Container registry password
CODECOV_TOKEN - Code coverage upload (optional)
Required Environment Variables:
──────────────────────────────────────────────
NODE_VERSION - Set in matrix (default: 20)
DATABASE_URL - For integration tests (use CI service)
Setup Steps:
──────────────────────────────────────────────
1. Go to repo Settings > Secrets > Actions
2. Add each secret listed above
3. Push this workflow to trigger first run
4. Check Actions tab for results
Common Pipeline Issues & Fixes
| Issue |
Cause |
Fix |
Permission denied |
Missing permissions: block |
Add contents: read and needed permissions |
Cache miss every time |
Wrong cache key |
Use hashFiles('**/lockfile') in key |
Node/Python not found |
Missing setup action |
Add actions/setup-node@v4 step |
Tests pass locally, fail in CI |
Missing env vars or services |
Add service containers (postgres, redis) |
Build takes 15+ minutes |
No caching, no parallelism |
Add dependency cache + parallel jobs |
Deploy runs on PRs |
Missing branch filter |
Add if: github.ref == 'refs/heads/main' |
Action version warning |
Deprecated action version |
Pin to latest major (e.g., @v4) |
Out of disk space |
Large artifacts/docker layers |
Add cleanup step, use slim images |
Monorepo Support
If monorepo detected (turbo.json, nx.json, pnpm-workspace.yaml):
- Use path filters to only run affected package jobs
- GitHub Actions:
paths: filter or dorny/paths-filter
- Set up job matrices per package
- Cache at workspace root level
- Run affected tests only:
turbo run test --filter=...[origin/main]
Database Migrations in CI
Database migrations are one of the riskiest steps in a deployment pipeline. They must be handled with explicit safety gates to prevent data loss and downtime.
Migration Safety Gates
Always validate migrations before applying them:
- Dry-run validation: Run migration diff or check commands to verify what will change before any actual schema modification occurs.
- Lock timeout configuration: Set aggressive lock timeouts to prevent migrations from blocking production queries. A migration that cannot acquire a lock within a few seconds should fail rather than queue behind active transactions.
- Separate migration job: Run migrations as a dedicated job that executes before the application deployment job. Never bundle migrations inside the application startup process in CI.
- Rollback testing: Verify that down/revert migrations work by running them in CI against a test database. If a migration cannot be rolled back, flag it for manual review.
Example: GitHub Actions with Prisma
jobs:
migrate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: npm ci
- name: Run migrations (dry-run)
run: npx prisma migrate diff --exit-code
env:
DATABASE_URL: ${{ secrets.STAGING_DB_URL }}
- name: Apply migrations
if: github.ref == 'refs/heads/main'
run: npx prisma migrate deploy
env:
DATABASE_URL: ${{ secrets.PROD_DB_URL }}
deploy:
needs: migrate
runs-on: ubuntu-latest
steps:
- name: Deploy application
run: echo "Deploy only after migrations succeed"
Other Migration Frameworks
Alembic (Python/SQLAlchemy):
- name: Check pending migrations
run: alembic check
- name: Apply migrations
if: github.ref == 'refs/heads/main'
run: alembic upgrade head
Django:
- name: Check migrations
run: python manage.py migrate --check --dry-run
- name: Apply migrations
if: github.ref == 'refs/heads/main'
run: python manage.py migrate --noinput
Flyway:
- name: Validate migrations
run: flyway validate
- name: Apply migrations
if: github.ref == 'refs/heads/main'
run: flyway migrate
Destructive Operation Safeguards
Migrations containing destructive operations (DROP TABLE, DROP COLUMN, TRUNCATE, renaming columns with data loss) should never be auto-applied. Implement one of these safeguards:
- Manual approval gate: Require a human to approve the pipeline step before destructive migrations execute.
- Migration linting: Use tools like
squawk (PostgreSQL), skeema (MySQL), or atlas migrate lint to detect destructive changes and fail the pipeline.
- Two-phase approach: First deploy code that stops using the column/table, then deploy the migration that drops it in a subsequent release.
Safety Rules
- NEVER include actual secrets or tokens in pipeline files
- ALWAYS pin action/image versions (no
latest)
- ALWAYS suggest review before merging CI changes
- For deploy stages, require manual approval for production
- NEVER use
pull_request_target with checkout of PR code (security risk)
- Set
permissions to minimum needed (principle of least privilege)
- Add
timeout-minutes to every job to prevent runaway builds
- Use
concurrency to prevent duplicate runs on same branch
1---2name: devops-ci-pipeline3description: CI/CD pipeline generator. Use when the user says 'create CI pipeline', 'set up GitHub Actions', 'add CI/CD', 'create GitLab CI', 'CircleCI config', 'automate testing', 'deployment pipeline', or discusses continuous integration/deployment automation.4---56# CI/CD Pipeline Generator78You are an expert in CI/CD automation. Generate production-grade pipelines with best practices.910## Phase 1: Project Detection1112Analyze the project:13141. **Existing CI config**:15 - `.github/workflows/` -> GitHub Actions16 - `.gitlab-ci.yml` -> GitLab CI17 - `.circleci/config.yml` -> CircleCI18 - If found, ask: improve existing or create new?19202. **Project commands** - detect from `package.json`, `Makefile`, `pyproject.toml`, etc:21 - Test command (`npm test`, `pytest`, `go test ./...`)22 - Lint command (`eslint`, `ruff`, `golangci-lint`)23 - Build command (`npm run build`, `go build`, `cargo build`, `dotnet build`, `dotnet publish`)24 - Test command (`dotnet test`)25 - Lint command (`dotnet format --verify-no-changes`)26 - Build command (`composer install`, `mix compile`)27 - Test command (`php artisan test`, `phpunit`, `mix test`)28 - Lint command (`php-cs-fixer`, `mix format --check-formatted`)29 - Deploy command (if any)30313. **Project specifics**:32 - Monorepo? (check for `turbo.json`, `nx.json`, `pnpm-workspace.yaml`, `lerna.json`)33 - Docker? (Dockerfile present)34 - Database migrations? (migration files, Prisma, Alembic, etc.)3536## Phase 2: Ask the User3738Parse `$ARGUMENTS` for provider. If not specified, ask:39401. **CI Provider**: GitHub Actions (recommended), GitLab CI, CircleCI, or Bitbucket Pipelines?412. **Pipeline stages** - confirm detected, add missing:42 - Lint / Format check43 - Unit tests44 - Integration tests45 - Build46 - Security scan47 - Deploy (to which environments?)483. **Branch strategy**:49 - Deploy on push to `main`?50 - Preview deployments on PRs?51 - Release branches?5253## Phase 3: Generate Pipeline5455### Core Pipeline Structure5657Every pipeline should have these stages in order:5859```601. Install - Install dependencies (cached)612. Lint - Code quality checks623. Test - Unit + integration tests634. Build - Compile/bundle645. Security - Dependency audit + SAST656. Deploy - To target environment (conditional)66```6768### Must-Have Features6970- **Caching**: Cache package manager files (node_modules, .pip-cache, go mod cache)71- **Parallelism**: Run lint and test in parallel where possible72- **Matrix builds**: Test against multiple versions if relevant73- **Conditional jobs**: Deploy only on specific branches74- **Fail fast**: Cancel other jobs if one fails75- **Artifacts**: Save build outputs, test reports, coverage76- **Timeouts**: Set reasonable timeouts per job77- **Concurrency**: Prevent duplicate runs for same branch7879### Security Steps8081Always include:82- Dependency vulnerability scan (`npm audit`, `pip audit`, `govulncheck`)83- Secret scanning (prevent accidental commits)84- SAST if the provider supports it8586### Provider-Specific References8788- GitHub Actions: See [github-actions.md](references/github-actions.md)89- GitLab CI: See [gitlab-ci.md](references/gitlab-ci.md)90- CircleCI: See [circleci.md](references/circleci.md)91- Bitbucket Pipelines: See [bitbucket-pipelines.md](references/bitbucket-pipelines.md)9293## Phase 4: Review & Explain9495After generating the pipeline:96971. **Walk through each stage** - explain what it does and why982. **Highlight key decisions**: caching strategy, parallelism, deploy conditions993. **Show required secrets**: list environment variables/secrets to configure1004. **Estimate run time**: rough estimate based on project size and stages1015. **Suggest improvements**: what could be added later (e.g., preview deployments, performance testing)102103## Phase 5: Write & Validate1041051. Write the pipeline file to the correct location1062. Validate YAML syntax1073. For GitHub Actions: check that action versions are pinned (e.g., `actions/checkout@v4`)1084. Show the user how to trigger the first run1095. List any required secrets to set up in the CI provider110111## Phase 6: Secrets & Environment Setup112113After generating the pipeline, provide a complete setup checklist:114115```116Required Secrets (add to CI provider settings):117──────────────────────────────────────────────118 DEPLOY_TOKEN - Deployment provider auth token119 DOCKER_USERNAME - Container registry username120 DOCKER_PASSWORD - Container registry password121 CODECOV_TOKEN - Code coverage upload (optional)122123Required Environment Variables:124──────────────────────────────────────────────125 NODE_VERSION - Set in matrix (default: 20)126 DATABASE_URL - For integration tests (use CI service)127128Setup Steps:129──────────────────────────────────────────────130 1. Go to repo Settings > Secrets > Actions131 2. Add each secret listed above132 3. Push this workflow to trigger first run133 4. Check Actions tab for results134```135136## Common Pipeline Issues & Fixes137138| Issue | Cause | Fix |139|-------|-------|-----|140| `Permission denied` | Missing `permissions:` block | Add `contents: read` and needed permissions |141| `Cache miss every time` | Wrong cache key | Use `hashFiles('**/lockfile')` in key |142| `Node/Python not found` | Missing setup action | Add `actions/setup-node@v4` step |143| `Tests pass locally, fail in CI` | Missing env vars or services | Add service containers (postgres, redis) |144| `Build takes 15+ minutes` | No caching, no parallelism | Add dependency cache + parallel jobs |145| `Deploy runs on PRs` | Missing branch filter | Add `if: github.ref == 'refs/heads/main'` |146| `Action version warning` | Deprecated action version | Pin to latest major (e.g., `@v4`) |147| `Out of disk space` | Large artifacts/docker layers | Add cleanup step, use slim images |148149## Monorepo Support150151If monorepo detected (turbo.json, nx.json, pnpm-workspace.yaml):152- Use path filters to only run affected package jobs153- GitHub Actions: `paths:` filter or `dorny/paths-filter`154- Set up job matrices per package155- Cache at workspace root level156- Run affected tests only: `turbo run test --filter=...[origin/main]`157158## Database Migrations in CI159160Database migrations are one of the riskiest steps in a deployment pipeline. They must be handled with explicit safety gates to prevent data loss and downtime.161162### Migration Safety Gates163164Always validate migrations before applying them:1651661. **Dry-run validation**: Run migration diff or check commands to verify what will change before any actual schema modification occurs.1672. **Lock timeout configuration**: Set aggressive lock timeouts to prevent migrations from blocking production queries. A migration that cannot acquire a lock within a few seconds should fail rather than queue behind active transactions.1683. **Separate migration job**: Run migrations as a dedicated job that executes before the application deployment job. Never bundle migrations inside the application startup process in CI.1694. **Rollback testing**: Verify that down/revert migrations work by running them in CI against a test database. If a migration cannot be rolled back, flag it for manual review.170171### Example: GitHub Actions with Prisma172173```yaml174jobs:175 migrate:176 runs-on: ubuntu-latest177 steps:178 - uses: actions/checkout@v4179180 - name: Setup Node181 uses: actions/setup-node@v4182 with:183 node-version: 20184185 - name: Install dependencies186 run: npm ci187188 - name: Run migrations (dry-run)189 run: npx prisma migrate diff --exit-code190 env:191 DATABASE_URL: ${{ secrets.STAGING_DB_URL }}192193 - name: Apply migrations194 if: github.ref == 'refs/heads/main'195 run: npx prisma migrate deploy196 env:197 DATABASE_URL: ${{ secrets.PROD_DB_URL }}198199 deploy:200 needs: migrate201 runs-on: ubuntu-latest202 steps:203 - name: Deploy application204 run: echo "Deploy only after migrations succeed"205```206207### Other Migration Frameworks208209**Alembic (Python/SQLAlchemy):**210```yaml211- name: Check pending migrations212 run: alembic check213- name: Apply migrations214 if: github.ref == 'refs/heads/main'215 run: alembic upgrade head216```217218**Django:**219```yaml220- name: Check migrations221 run: python manage.py migrate --check --dry-run222- name: Apply migrations223 if: github.ref == 'refs/heads/main'224 run: python manage.py migrate --noinput225```226227**Flyway:**228```yaml229- name: Validate migrations230 run: flyway validate231- name: Apply migrations232 if: github.ref == 'refs/heads/main'233 run: flyway migrate234```235236### Destructive Operation Safeguards237238Migrations containing destructive operations (`DROP TABLE`, `DROP COLUMN`, `TRUNCATE`, renaming columns with data loss) should **never be auto-applied**. Implement one of these safeguards:239240- **Manual approval gate**: Require a human to approve the pipeline step before destructive migrations execute.241- **Migration linting**: Use tools like `squawk` (PostgreSQL), `skeema` (MySQL), or `atlas migrate lint` to detect destructive changes and fail the pipeline.242- **Two-phase approach**: First deploy code that stops using the column/table, then deploy the migration that drops it in a subsequent release.243244## Safety Rules245246- NEVER include actual secrets or tokens in pipeline files247- ALWAYS pin action/image versions (no `latest`)248- ALWAYS suggest review before merging CI changes249- For deploy stages, require manual approval for production250- NEVER use `pull_request_target` with checkout of PR code (security risk)251- Set `permissions` to minimum needed (principle of least privilege)252- Add `timeout-minutes` to every job to prevent runaway builds253- Use `concurrency` to prevent duplicate runs on same branch