ci-cd February 10, 2026 2 min read

CI/CD with GitHub Actions

Set up continuous integration and deployment pipelines using GitHub Actions for automated testing and deployments.

CI/CD with GitHub Actions

GitHub Actions provides a powerful CI/CD platform directly integrated with your GitHub repositories.

Basic Workflow

Create .github/workflows/ci.yml:

name: CI Pipeline

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'
      
      - name: Install dependencies
        run: npm ci
      
      - name: Run linter
        run: npm run lint
      
      - name: Run tests
        run: npm test
      
      - name: Build
        run: npm run build

Key Concepts

Triggers

  • push: Trigger on push events
  • pull_request: Trigger on PR events
  • schedule: Cron-based triggers
  • workflow_dispatch: Manual triggers

Jobs and Steps

Jobs run in parallel by default. Steps within a job run sequentially.

Secrets

Store sensitive data securely:

env:
  API_KEY: ${{ secrets.API_KEY }}

Deployment Example

deploy:
  needs: test
  runs-on: ubuntu-latest
  if: github.ref == 'refs/heads/main'
  
  steps:
    - uses: actions/checkout@v4
    
    - name: Deploy to production
      run: |
        echo "Deploying to production..."
        # Your deployment commands here

Best Practices

  1. Cache dependencies for faster builds
  2. Use matrix builds for testing across versions
  3. Keep secrets out of workflow files
  4. Use reusable workflows to reduce duplication
  5. Set up branch protection rules with required checks

Related Articles