yamlbeginner

GitHub Actions — Node.js CI Pipeline

Complete CI workflow for Node.js: install, lint, test, build on every push and PR with caching.

yaml
name: Node.js CI

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

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18, 20, 22]

    steps:
      - uses: actions/checkout@v4

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: npm

      - run: npm ci
      - run: npm run lint
      - run: npm test -- --coverage
      - run: npm run build

      - name: Upload coverage
        if: matrix.node-version == 20
        uses: actions/upload-artifact@v4
        with:
          name: coverage-report
          path: coverage/

Sponsored

GitHub

Use Cases

  • Automated testing on every push and PR
  • Matrix testing across Node.js versions
  • CI pipeline for open-source Node.js projects

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.