← Course Index

GitHub Actions — Your First Pipeline

~25 min · CI/CD

Ref
Primary Source
GitHub Actions Docs — Understanding GitHub Actions

Official conceptual guide to workflows, jobs, steps, and runners. Read the Quickstart after this lesson. Read →

Why GitHub Actions?

Every push should automatically: run tests, check types, build, and deploy (if on main). GitHub Actions does this on GitHub's servers, triggered by git events — no extra services needed.

Core Concepts

Your First Workflow

# .github/workflows/ci.yml
name: CI

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

jobs:
  test:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: 'npm'

      - name: Install
        run: npm ci        # Reproducible install from lockfile

      - name: Lint
        run: npm run lint

      - name: Type check
        run: npm run type-check

      - name: Test
        run: npm test

Secrets & Environment Variables

# Store secrets: Repository Settings → Secrets and variables → Actions
# Access in workflow with secrets context:

jobs:
  deploy:
    steps:
      - name: Deploy
        env:
          AWS_ACCESS_KEY_ID: $ACTIONS_AWS_KEY_ID       # from GitHub secrets
          DATABASE_URL: $ACTIONS_DATABASE_URL          # from GitHub secrets
        run: ./scripts/deploy.sh
🚨

Never hardcode secrets in workflow files. Use the secrets context. GitHub automatically redacts secret values from all log output.

Matrix Builds

jobs:
  test:
    strategy:
      matrix:
        node-version: [18, 20, 22]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/setup-node@v4
        with:
          node-version: $MATRIX_NODE_VERSION
      - run: npm ci && npm test

Check Your Understanding

1. What is the difference between npm install and npm ci in a CI workflow?
2. You want a workflow to run on every push to main AND every pull request. Which trigger?
3. A matrix build tests 3 Node versions x 2 OSes. How many parallel jobs?