<< All versions
Skill v1.0.0
currentAutomated scan100/100chavangorakh1999/sde-skills/ci-cd-pipeline
──Details
PublishedNovember 20, 2026 at 10:33 PM
Content Hashsha256:c73d2c466c93747e...
Git SHA89ddaddb9288
──Files
Files (1 file, 8.2 KB)
SKILL.md8.2 KBactive
SKILL.md · 293 lines · 8.2 KB
name: ci-cd-pipeline description: "CI/CD pipeline design with GitHub Actions: test stages, build, Docker image, deployment strategies, branch protection, and rollback. Use when designing or debugging a CI/CD pipeline." metadata: version: "1.0.0"
CI/CD Pipeline Design
Context
Pipeline requirement or problem: $ARGUMENTS
Pipeline Principles
Fast feedback: PRs get test results in < 5 minutesDeterministic: same code always produces same resultProgressive: fast checks run first, slow checks lastSafe: production deployments require all checks + manual approval (or auto with canary)Traceable: every deployment links to a commit and deployment log
GitHub Actions — Full Pipeline
yaml
# .github/workflows/ci-cd.ymlname: CI/CD Pipelineon:push:branches: [main, develop]pull_request:branches: [main]concurrency:group: ${{ github.workflow }}-${{ github.ref }}cancel-in-progress: true # cancel stale PR runs when new commit pushedenv:REGISTRY: ghcr.ioIMAGE_NAME: ${{ github.repository }}NODE_VERSION: '20'jobs:# ── Stage 1: Code Quality (fast, ~2min) ──────────────────────────────quality:name: Lint & Type Checkruns-on: ubuntu-lateststeps:- uses: actions/checkout@v4- uses: actions/setup-node@v4with:node-version: ${{ env.NODE_VERSION }}cache: 'npm'- run: npm ci- run: npm run lint- run: npm run typecheck # tsc --noEmit if using TypeScript- run: npm run format:check # prettier --check# ── Stage 2: Unit Tests (fast, ~3min) ────────────────────────────────unit-tests:name: Unit Testsruns-on: ubuntu-lateststeps:- uses: actions/checkout@v4- uses: actions/setup-node@v4with:node-version: ${{ env.NODE_VERSION }}cache: 'npm'- run: npm ci- run: npm run test:unit -- --coverage- uses: codecov/codecov-action@v4with:flags: unittoken: ${{ secrets.CODECOV_TOKEN }}# ── Stage 3: Integration Tests (~5min) ───────────────────────────────integration-tests:name: Integration Testsruns-on: ubuntu-latestservices:mongodb:image: mongo:7ports: ['27017:27017']options: >---health-cmd "mongosh --eval 'db.adminCommand(\"ping\")'"--health-interval 10s --health-timeout 5s --health-retries 5redis:image: redis:7-alpineports: ['6379:6379']options: >---health-cmd "redis-cli ping"--health-interval 10s --health-timeout 5s --health-retries 5steps:- uses: actions/checkout@v4- uses: actions/setup-node@v4with:node-version: ${{ env.NODE_VERSION }}cache: 'npm'- run: npm ci- name: Run integration testsrun: npm run test:integrationenv:MONGODB_URI: mongodb://localhost:27017/testREDIS_URL: redis://localhost:6379JWT_ACCESS_SECRET: ${{ secrets.TEST_JWT_ACCESS_SECRET }}JWT_REFRESH_SECRET: ${{ secrets.TEST_JWT_REFRESH_SECRET }}# ── Stage 4: Build & Push Docker Image ───────────────────────────────build:name: Build Docker Imageneeds: [quality, unit-tests, integration-tests]runs-on: ubuntu-latestif: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop'permissions:contents: readpackages: writeoutputs:image-tag: ${{ steps.meta.outputs.tags }}digest: ${{ steps.build.outputs.digest }}steps:- uses: actions/checkout@v4- uses: docker/login-action@v3with:registry: ${{ env.REGISTRY }}username: ${{ github.actor }}password: ${{ secrets.GITHUB_TOKEN }}- uses: docker/metadata-action@v5id: metawith:images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}tags: |type=sha,prefix=sha-type=ref,event=branchtype=raw,value=latest,enable={{is_default_branch}}- uses: docker/build-push-action@v5id: buildwith:context: .push: truetags: ${{ steps.meta.outputs.tags }}labels: ${{ steps.meta.outputs.labels }}cache-from: type=ghacache-to: type=gha,mode=maxbuild-args: |GIT_SHA=${{ github.sha }}BUILD_DATE=${{ github.event.head_commit.timestamp }}# ── Stage 5: Deploy to Staging ───────────────────────────────────────deploy-staging:name: Deploy to Stagingneeds: buildruns-on: ubuntu-latestenvironment:name: stagingurl: https://staging.example.comsteps:- uses: actions/checkout@v4- name: Deploy to staginguses: appleboy/ssh-action@v1with:host: ${{ secrets.STAGING_HOST }}username: ${{ secrets.STAGING_USER }}key: ${{ secrets.STAGING_SSH_KEY }}script: |docker pull ${{ needs.build.outputs.image-tag }}docker stop app || truedocker run -d --rm --name app \-p 3000:3000 \--env-file /etc/app/staging.env \${{ needs.build.outputs.image-tag }}# ── Stage 6: E2E Tests on Staging (~10min) ───────────────────────────e2e-tests:name: E2E Testsneeds: deploy-stagingruns-on: ubuntu-lateststeps:- uses: actions/checkout@v4- uses: actions/setup-node@v4with:node-version: ${{ env.NODE_VERSION }}cache: 'npm'- run: npm ci- run: npx playwright install --with-deps chromium- name: Run E2E tests against stagingrun: npx playwright testenv:BASE_URL: https://staging.example.comTEST_USER_EMAIL: ${{ secrets.TEST_USER_EMAIL }}TEST_USER_PASSWORD: ${{ secrets.TEST_USER_PASSWORD }}- uses: actions/upload-artifact@v4if: always()with:name: playwright-reportpath: playwright-report/# ── Stage 7: Deploy to Production (manual approval) ──────────────────deploy-production:name: Deploy to Productionneeds: e2e-testsruns-on: ubuntu-latestenvironment:name: production # requires approval in GitHub Environments settingsurl: https://app.example.comsteps:- name: Deploy to productionrun: |# Canary: deploy to 10% traffic first# Then promote to 100% after health checkecho "Deploying ${{ needs.build.outputs.image-tag }}"
Branch Protection Rules
main branch:- Require PR with at least 1 review- Require all status checks to pass (quality, unit-tests, integration-tests)- Require branches to be up to date before merging- Restrict who can push directlydevelop branch:- Require PR with at least 1 review- Require quality + unit-tests to pass
Pipeline Optimization
yaml
# Cache node_modules across jobs — don't reinstall every time- uses: actions/setup-node@v4with:cache: 'npm' # caches ~/.npm, restores automatically# Run independent jobs in paralleljobs:quality: # parallelunit-tests: # parallelintegration-tests: # parallelbuild:needs: [quality, unit-tests, integration-tests] # waits for all# Skip CI for docs-only changeson:push:paths-ignore:- '**.md'- 'docs/**'
Rollback Strategy
bash
# Quick rollback: re-deploy previous image tagdocker pull ghcr.io/org/app:sha-abc123 # previous SHAdocker stop appdocker run -d --name app --env-file /etc/app/prod.env ghcr.io/org/app:sha-abc123# Or via GitHub Actions: re-run the deploy job with previous SHA# gh run rerun <run-id> --job deploy-production