GitHub Actions CI/CD Pipeline

CI/CD Made Simple

GitHub Actions brings automation directly into your repository. No external services neededβ€”your pipelines live alongside your code.

Why GitHub Actions?

  • πŸ†“ Free for public repos - Generous free tier for private repos too
  • πŸ”— Native integration - Triggers on push, PR, issues, schedules, and more
  • πŸ“¦ Marketplace - Thousands of pre-built actions ready to use
  • 🐳 Container support - Run jobs in Docker containers

Your First Workflow

Create .github/workflows/ci.yml:

name: CI Pipeline

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

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        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 tests
        run: npm test

      - name: Build application
        run: npm run build

Advanced Patterns

Matrix Builds

Test across multiple versions:

strategy:
  matrix:
    node-version: [18, 20, 22]
    os: [ubuntu-latest, windows-latest]

Secrets Management

Never hardcode credentials:

- name: Deploy to AWS
  env:
    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  run: aws s3 sync ./dist s3://my-bucket

Conditional Jobs

deploy:
  needs: build
  if: github.ref == 'refs/heads/main'
  runs-on: ubuntu-latest
  steps:
    - name: Deploy to production
      run: ./deploy.sh

Real-World Example: Full CI/CD

name: Full CI/CD Pipeline

on:
  push:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm test

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm ci
      - run: npm run build
      - uses: actions/upload-artifact@v4
        with:
          name: build
          path: dist/

  deploy:
    needs: build
    runs-on: ubuntu-latest
    environment: production
    steps:
      - uses: actions/download-artifact@v4
        with:
          name: build
      - name: Deploy to S3
        run: aws s3 sync . s3://${{ secrets.S3_BUCKET }}

Pro Tips

  • ⚑ Cache dependencies - Speed up builds by 60%+
  • πŸ”„ Reusable workflows - DRY principle for pipelines
  • πŸ“Š Add status badges - Show build status in README
  • πŸ” Use environments - Require approvals for production

GitHub Actions is the glue that holds modern DevOps together. Start automating today!