GitHub Actions CI Workflow

Automate Node project testing and build with a reusable GitHub Actions workflow.

Continuous integration helps catch issues early by running tests on every push or pull request. This GitHub Actions workflow installs dependencies, caches them, runs tests, and optionally builds your app. You can customize the Node version and commands to suit your project.

name: CI
on:
  push:
    branches: [main]
  pull_request:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x]
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}
          cache: "npm"
      - name: Install dependencies
        run: npm ci
      - name: Run tests
        run: npm test -- --ci
      - name: Build
        run: npm run build

This workflow triggers on pushes and pull requests to the main branch. It caches npm dependencies between runs, improving performance. Expand the steps to include linting, code coverage reporting, or deployment actions.