Script Valley
Git and GitHub Complete Course: From Beginner to Advanced
GitHub Actions and CI/CD AutomationLesson 5.2

Writing CI Workflows: Lint and Test

CI workflow, checkout action, setup-node, npm test, matrix strategy, caching dependencies, status checks

Writing CI Workflows: Lint and Test

The most common use of GitHub Actions is Continuous Integration (CI) — automatically running tests and code quality checks on every push and pull request. This ensures that broken code never reaches the main branch.

DiagramCI Workflow Matrix Strategy

IMAGE PROMPT (replace this block with your generated image):

Flat annotated YAML + result diagram on white background. Title: CI Workflow with Matrix Strategy. Left half: a YAML code block (monospace, light gray background) showing the key parts of a Node.js CI workflow: on: push/pull_request, jobs: test:, runs-on: ubuntu-latest, strategy: matrix: node-version: [18, 20, 22], steps: checkout, setup-node with matrix.node-version, npm ci, npm run lint, npm test. Key lines highlighted: matrix definition in #3A5EFF, uses: actions in green, run: commands in amber. Right half: a matrix result grid. Rows: Node 18, Node 20, Node 22. Columns: Lint, Tests, Status. Each cell shows green checkmark (pass) or red X (fail). All cells green in this example. Three parallel runner boxes below labeled 3 Jobs Run in Parallel with ubuntu icons. Caching badge: cache: npm → faster subsequent runs with lightning bolt icon. White background, brand color #3A5EFF for matrix highlighting.

A Node.js CI Workflow

name: Node.js CI

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

jobs:
  test:
    runs-on: ubuntu-latest

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

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

      - name: Install dependencies
        run: npm ci

      - name: Run linter
        run: npm run lint

      - name: Run tests
        run: npm test

Key Actions Explained

actions/checkout@v4 clones your repository into the runner. actions/setup-node@v4 installs Node.js. The cache: 'npm' option caches the npm dependency cache between runs, dramatically speeding up subsequent workflow executions.

Matrix Strategy

Run tests on multiple Node.js versions simultaneously:

strategy:
  matrix:
    node-version: [18, 20, 22]

steps:
  - uses: actions/setup-node@v4
    with:
      node-version: ${{ matrix.node-version }}

This creates three parallel jobs, one for each Node.js version.

Up next

Secrets, Environment Variables, and Contexts

Sign in to track progress