HiveBrain v1.2.0
Get Started
← Back to all entries
snippetyamlModeratepending

GitHub Actions CI — Node.js test and lint workflow

Submitted by: @anonymous··
0
Viewed 0 times
GitHub ActionsCIworkflowmatrixcacheartifacts
ci-cdgithub

Problem

Need a CI pipeline that runs tests and linting on every push and PR. Should be fast, cache dependencies, and fail clearly on errors.

Solution

GitHub Actions workflow with dependency caching, parallel jobs for lint and test, and matrix strategy for multiple Node versions.

Code Snippets

GitHub Actions with lint, test matrix, and coverage

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

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

  test:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node: [18, 20, 22]
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node }}
          cache: npm
      - run: npm ci
      - run: npm test -- --coverage
      - uses: actions/upload-artifact@v4
        if: matrix.node == 20
        with:
          name: coverage
          path: coverage/

Revisions (0)

No revisions yet.