Isaac.

devops

GitHub Actions for CI/CD

Automate workflows with GitHub Actions.

By Emem IsaacMarch 15, 20232 min read
#github actions#ci/cd#automation#workflows
Share:

A Simple Analogy

GitHub Actions are like a helpful robot. Every time code changes, the robot automatically runs tests, builds, and deploys.


Why GitHub Actions?

  • Native: Built into GitHub
  • Free: Unlimited runs for public repos
  • Flexible: Run any code
  • Secrets: Secure credential management
  • Matrices: Test multiple configurations

Basic Workflow

name: CI

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

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Setup Node
      uses: actions/setup-node@v3
      with:
        node-version: '18'
    - name: Install dependencies
      run: npm ci
    - name: Run tests
      run: npm test
    - name: Upload coverage
      uses: codecov/codecov-action@v3

Deployment Workflow

name: Deploy

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - name: Deploy to production
      run: |
        echo "Deploying to Azure..."
        az appservice deployment source config-zip \
          --resource-group mygroup \
          --name myapp \
          --src-path ./app.zip
      env:
        AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}

Matrix Testing

jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [16.x, 18.x, 20.x]
        os: [ubuntu-latest, windows-latest]
    steps:
    - uses: actions/checkout@v3
    - uses: actions/setup-node@v3
      with:
        node-version: ${{ matrix.node-version }}
    - run: npm test

Secrets & Variables

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Deploy
      run: npm run deploy
      env:
        DATABASE_URL: ${{ secrets.DATABASE_URL }}
        API_KEY: ${{ secrets.API_KEY }}
        ENVIRONMENT: ${{ vars.DEPLOYMENT_ENV }}

Best Practices

  1. Cache dependencies: Speed up runs
  2. Fail fast: Run quick checks first
  3. Concurrency: Use matrix for speed
  4. Status checks: Required before merge
  5. Notifications: Alert on failures

Related Concepts

  • Azure Pipelines
  • GitLab CI
  • Jenkins
  • CircleCI

Summary

Use GitHub Actions to automate testing, building, and deployment. Leverage workflow files for CI/CD pipelines.

Share:

Written by Emem Isaac

Expert Software Engineer with 15+ years of experience building scalable enterprise applications. Specialized in ASP.NET Core, Azure, Docker, and modern web development. Passionate about sharing knowledge and helping developers grow.

Ready to Build Something Amazing?

Let's discuss your project and explore how my expertise can help you achieve your goals. Free consultation available.

💼 Trusted by 50+ companies worldwide | ⚡ Average response time: 24 hours