GitHub ActionsCI/CDDevOps

GitHub Actions: Automate Everything

Set up CI/CD pipelines with GitHub Actions for testing, building, and deploying.

5 min read

GitHub Actions: Automate Everything

GitHub Actions lets you automate your software development workflows directly in your repository.

Basic Workflow

Yaml
name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '20'
      - run: npm ci
      - run: npm test

Matrix Builds

Yaml
strategy:
  matrix:
    node: [18, 20, 22]
    os: [ubuntu-latest, macos-latest]

Deploy to Vercel

Yaml
deploy:
  needs: test
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v4
    - uses: amondnet/vercel-action@v25
      with:
        vercel-token: ${{ secrets.VERCEL_TOKEN }}
        vercel-org-id: ${{ secrets.ORG_ID }}
        vercel-project-id: ${{ secrets.PROJECT_ID }}

Best Practices

  1. Cache dependencies for faster builds
  2. Use secrets for sensitive data
  3. Run tests before deployment

Automate early and often!

Enjoyed this article? Show some love!

778 views

Comments