Skill v1.0.1
currentAutomated scan100/1001 files
version: "1.0.1" name: ci-cd-pipeline description: Set up and maintain continuous integration and continuous deployment pipelines with GitHub Actions, GitLab CI, Jenkins, or similar tools to automate testing, building, and deployment. Use when configuring automated builds, setting up test automation, implementing deployment automation, creating release workflows, managing environment deployments, configuring build caching, implementing blue-green deployments, setting up rollback strategies, or automating the entire software delivery pipeline.
CI/CD Pipeline - Automating Build, Test, and Deployment
Package Manager Detection
IMPORTANT: Before creating CI/CD configurations, detect the project's package manager by checking for lockfiles and adapt all commands accordingly.
Detection Order (first match wins):
bun.lockb→ Use bunpnpm-lock.yaml→ Use pnpmyarn.lock→ Use yarnpackage-lock.json→ Use npm
Command Mapping - Adapt examples in this skill to use the detected package manager:
| Action | npm | yarn | pnpm | bun | |
|---|---|---|---|---|---|
| Install (CI) | npm ci | yarn install --frozen-lockfile | pnpm install --frozen-lockfile | bun install --frozen-lockfile | |
| Run script | npm run <script> | yarn <script> | pnpm <script> | bun run <script> | |
| Execute bin | npx <cmd> | yarn dlx <cmd> | pnpm dlx <cmd> | bunx <cmd> | |
| Cache key | package-lock.json | yarn.lock | pnpm-lock.yaml | bun.lockb | |
| Cache path | ~/.npm | ~/.yarn/cache | ~/.pnpm-store | ~/.bun/install/cache |
Note: The examples below use npm by default. When implementing, replace with the appropriate commands for your detected package manager.
When to use this skill
- Setting up GitHub Actions or GitLab CI workflows
- Automating test execution on every commit
- Implementing automated builds and deployments
- Creating release and versioning workflows
- Managing staging and production deployments
- Configuring build caching for faster pipelines
- Implementing blue-green or canary deployments
- Setting up automatic rollback on failures
- Running linting and type checking in CI
- Automating database migrations in pipelines
- Implementing security scanning in CI
- Creating deployment approval workflows
When to use this skill
- Setting up continuous integration, automating deployments, configuring build pipelines, or implementing DevOps workflows.
- When working on related tasks or features
- During development that requires this expertise
Use when: Setting up continuous integration, automating deployments, configuring build pipelines, or implementing DevOps workflows.
Core Principles
- Automate Everything - Manual steps are error-prone
- Fail Fast - Catch issues early in the pipeline
- Test Before Deploy - Never deploy untested code
- Reproducible Builds - Same inputs = same outputs
- Zero-Downtime Deployments - Users never affected
GitHub Actions
1. Basic CI Workflow
# .github/workflows/ci.ymlname: CIon:push:branches: [main, develop]pull_request:branches: [main]jobs:test:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Setup Node.jsuses: actions/setup-node@v4with:node-version: '20'cache: 'npm'- name: Install dependenciesrun: npm ci- name: Run linterrun: npm run lint- name: Run type checkrun: npm run typecheck- name: Run testsrun: npm test -- --coverage- name: Upload coverageuses: codecov/codecov-action@v3with:files: ./coverage/lcov.info
2. Matrix Testing
# Test across multiple versionsjobs:test:runs-on: ${{ matrix.os }}strategy:matrix:os: [ubuntu-latest, windows-latest, macos-latest]node-version: [18, 20, 21]steps:- uses: actions/checkout@v4- name: Setup Node.js ${{ matrix.node-version }}uses: actions/setup-node@v4with:node-version: ${{ matrix.node-version }}- run: npm ci- run: npm test
3. Deploy Workflow
# .github/workflows/deploy.ymlname: Deployon:push:branches: [main]jobs:deploy:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Setup Node.jsuses: actions/setup-node@v4with:node-version: '20'- run: npm ci- run: npm run build- name: Deploy to Verceluses: amondnet/vercel-action@v25with:vercel-token: ${{ secrets.VERCEL_TOKEN }}vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}vercel-args: '--prod'
4. Docker Build & Push
name: Dockeron:push:tags: ['v*']jobs:build:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Set up Docker Buildxuses: docker/setup-buildx-action@v3- name: Login to Docker Hubuses: docker/login-action@v3with:username: ${{ secrets.DOCKER_USERNAME }}password: ${{ secrets.DOCKER_PASSWORD }}- name: Extract metadataid: metauses: docker/metadata-action@v5with:images: myorg/myapptags: |type=semver,pattern={{version}}type=semver,pattern={{major}}.{{minor}}- name: Build and pushuses: docker/build-push-action@v5with:context: .push: truetags: ${{ steps.meta.outputs.tags }}cache-from: type=registry,ref=myorg/myapp:buildcachecache-to: type=registry,ref=myorg/myapp:buildcache,mode=max
5. E2E Testing
name: E2E Testson:pull_request:jobs:e2e:runs-on: ubuntu-latestservices:postgres:image: postgres:15env:POSTGRES_PASSWORD: postgresoptions: >---health-cmd pg_isready--health-interval 10s--health-timeout 5s--health-retries 5steps:- uses: actions/checkout@v4- name: Setup Node.jsuses: actions/setup-node@v4with:node-version: '20'- run: npm ci- name: Install Playwrightrun: npx playwright install --with-deps- name: Run E2E testsrun: npm run test:e2eenv:DATABASE_URL: postgresql://postgres:postgres@localhost:5432/test- name: Upload test resultsif: always()uses: actions/upload-artifact@v3with:name: playwright-reportpath: playwright-report/
GitLab CI
# .gitlab-ci.ymlstages:- lint- test- build- deployvariables:NODE_VERSION: "20"lint:stage: lintimage: node:${NODE_VERSION}script:- npm ci- npm run lint- npm run typechecktest:stage: testimage: node:${NODE_VERSION}services:- postgres:15variables:POSTGRES_DB: testPOSTGRES_USER: postgresPOSTGRES_PASSWORD: postgresscript:- npm ci- npm test -- --coveragecoverage: '/All files[^|]*\|[^|]*\s+([\d\.]+)/'artifacts:reports:coverage_report:coverage_format: coberturapath: coverage/cobertura-coverage.xmlbuild:stage: buildimage: node:${NODE_VERSION}script:- npm ci- npm run buildartifacts:paths:- dist/deploy:production:stage: deployimage: node:${NODE_VERSION}script:- npm install -g vercel- vercel --prod --token=$VERCEL_TOKENonly:- main
Deployment Strategies
1. Blue-Green Deployment
# Deploy to staging slot first- name: Deploy to stagingrun: |az webapp deployment slot create \--name myapp \--resource-group mygroup \--slot stagingaz webapp deployment source config-zip \--name myapp \--resource-group mygroup \--slot staging \--src ./dist.zip# Run smoke tests against staging- name: Smoke testsrun: npm run test:smoke -- --url=https://myapp-staging.azurewebsites.net# Swap staging to production (instant cutover)- name: Swap to productionrun: |az webapp deployment slot swap \--name myapp \--resource-group mygroup \--slot staging \--target-slot production
2. Canary Deployment
# Deploy to 10% of servers first- name: Deploy canaryrun: |kubectl set image deployment/myapp \myapp=myapp:${{ github.sha }} \--recordkubectl patch deployment myapp \-p '{"spec":{"replicas":1}}'# Monitor for 10 minutes- name: Monitor canaryrun: |sleep 600ERROR_RATE=$(kubectl logs -l app=myapp --tail=1000 | grep ERROR | wc -l)if [ $ERROR_RATE -gt 10 ]; thenecho "High error rate, rolling back"kubectl rollout undo deployment/myappexit 1fi# Scale to 100% if healthy- name: Full deploymentrun: kubectl scale deployment myapp --replicas=5
3. Rolling Deployment
# Kubernetes rolling update (zero downtime)apiVersion: apps/v1kind: Deploymentmetadata:name: myappspec:replicas: 5strategy:type: RollingUpdaterollingUpdate:maxSurge: 1 # Max 1 extra pod during updatemaxUnavailable: 1 # Max 1 pod down at a timetemplate:spec:containers:- name: myappimage: myapp:latestreadinessProbe:httpGet:path: /healthport: 3000initialDelaySeconds: 5periodSeconds: 5
Pipeline Best Practices
1. Caching
# Cache dependencies- name: Cache node modulesuses: actions/cache@v3with:path: ~/.npmkey: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}restore-keys: |${{ runner.os }}-node-# Cache build outputs- name: Cache builduses: actions/cache@v3with:path: .next/cachekey: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }}
2. Secrets Management
# ✅ Store secrets in CI/CD platformjobs:deploy:steps:- name: Deployenv:API_KEY: ${{ secrets.API_KEY }}DATABASE_URL: ${{ secrets.DATABASE_URL }}run: |echo "API_KEY is set: ${API_KEY:+yes}"npm run deploy# ✅ Use vault for sensitive data- name: Import secretsuses: hashicorp/vault-action@v2with:url: https://vault.example.comtoken: ${{ secrets.VAULT_TOKEN }}secrets: |secret/data/prod api_key | API_KEY ;secret/data/prod db_url | DATABASE_URL
3. Quality Gates
jobs:quality-check:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v4- name: Run tests with coveragerun: npm test -- --coverage- name: Check coverage thresholdrun: |COVERAGE=$(cat coverage/coverage-summary.json | jq '.total.lines.pct')if (( $(echo "$COVERAGE < 80" | bc -l) )); thenecho "Coverage $COVERAGE% is below 80%"exit 1fi- name: SonarQube Scanuses: sonarsource/sonarcloud-github-action@masterenv:GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}- name: Check quality gaterun: |STATUS=$(curl -u $SONAR_TOKEN: \"https://sonarcloud.io/api/qualitygates/project_status?projectKey=myproject" \| jq -r '.projectStatus.status')if [ "$STATUS" != "OK" ]; thenecho "Quality gate failed"exit 1fi
4. Notifications
jobs:notify:runs-on: ubuntu-latestif: always()needs: [test, build, deploy]steps:- name: Slack notificationuses: 8398a7/action-slack@v3with:status: ${{ job.status }}text: 'Deployment ${{ job.status }}'webhook_url: ${{ secrets.SLACK_WEBHOOK }}- name: Email notificationif: failure()uses: dawidd6/action-send-mail@v3with:server_address: smtp.gmail.comserver_port: 465username: ${{ secrets.MAIL_USERNAME }}password: ${{ secrets.MAIL_PASSWORD }}subject: 'CI/CD Failed: ${{ github.workflow }}'body: 'Build failed on ${{ github.ref }}'to: team@example.com
CI/CD Checklist
Build Pipeline:□ Automated on every commit□ Runs linting and type checking□ Executes all tests□ Generates code coverage reports□ Builds production artifacts□ Caches dependencies for speedQuality Gates:□ Minimum code coverage threshold (e.g., 80%)□ No critical vulnerabilities (npm audit, Snyk)□ Code quality checks (SonarQube)□ No linting errors□ All tests passingDeployment:□ Automated deployment to staging□ Manual approval for production□ Health checks before traffic switch□ Rollback capability□ Zero-downtime strategy (blue-green, canary, rolling)Security:□ Secrets stored securely (not in code)□ Dependency scanning (Dependabot)□ Container vulnerability scanning□ SAST/DAST security scans□ Signed commits requiredMonitoring:□ Build status notifications (Slack, email)□ Deployment notifications□ Error rate monitoring post-deploy□ Automatic rollback on errors□ Audit logs maintained
Resources
Remember: Great CI/CD pipelines are fast, reliable, and give developers confidence to deploy frequently.