Setting Up a Modern CI/CD Pipeline with GitHub Actions
DevOps

Setting Up a Modern CI/CD Pipeline with GitHub Actions

Learn how to automate your deployment workflow with GitHub Actions, including testing, building, and deploying to production.

Romeo Mukulah

Romeo Mukulah

Jan 19, 20267 min
4626

Setting Up a Modern CI/CD Pipeline with GitHub Actions

Automate everything! Let's build a production-ready CI/CD pipeline.

Why CI/CD?

  • Automated testing on every commit
  • Consistent builds
  • Fast, reliable deployments
  • Reduced human error

Basic Workflow

Create .github/workflows/deploy.yml:

name: Deploy

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

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: npm install
      - name: Run tests
        run: npm test
      
  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Build
        run: npm run build
      - name: Upload artifacts
        uses: actions/upload-artifact@v3
        with:
          name: dist
          path: dist/
  
  deploy:
    needs: build
    runs-on: ubuntu-latest
    if: github.ref == 'refs/heads/main'
    steps:
      - name: Deploy to production
        run: |
          echo "Deploying to prod..."

Best Practices

  1. Test First: Always run tests before deployment
  2. Environment Variables: Use GitHub Secrets
  3. Conditional Deploys: Only deploy from main branch
  4. Rollback Strategy: Keep previous versions

Conclusion

GitHub Actions makes CI/CD accessible to everyone. Start simple and iterate!

Comments (6)

No comments yet. Be the first to comment!

Quick Actions