Skip to content
Latchkey

Node.js CI workflow

GitHub's official Node.js CI starter workflow, explained and hardened by Latchkey.

C

CI health: C - fair

The optimized version below adds run de-duplication, job timeouts.

Source: GitHub official starter workflowci/node.js.ymlLicense CC0-1.0View source

What it does

This is the Node.js continuous integration workflow GitHub offers by default. It checks out the repo, installs a matrix of Node versions, installs dependencies with npm ci, and runs the build and tests.

It is a solid starting point. Below, Latchkey adds the guardrails the starter leaves out.

The workflow

workflow (.yml)
name: Node.js CI

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

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x, 22.x]
    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 build --if-present
      - run: npm test

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Node.js CI on:  push:    branches: [ "main" ]  pull_request:    branches: [ "main" ] concurrency:  group: ${{ github.workflow }}-${{ github.ref }}  cancel-in-progress: true jobs:  build:    timeout-minutes: 30    runs-on: latchkey-small    strategy:      matrix:        node-version: [18.x, 20.x, 22.x]    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 build --if-present      - run: npm test 

What changed

  • Run on Latchkey managed runners with one line (runs-on), which apply the fixes below automatically and self-heal transient failures. This example uses latchkey-small; pick the runner size that fits the job.
  • Cancel superseded runs when a branch or PR gets a newer push.
  • Add a job timeout so a hung step cannot burn hours of runner time.

What Latchkey heals here

This workflow has steps that commonly fail on transient issues (network, registries, flaky browsers). On Latchkey managed runners they are detected, retried, and self-healed instead of failing your build:

  • Dependency installs

This workflow runs 1 job (3 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.

Actions used in this workflow

Frequently asked questions

What does the Node.js CI workflow workflow do?
This is the Node.js continuous integration workflow GitHub offers by default. It checks out the repo, installs a matrix of Node versions, installs dependencies with npm ci, and runs the build and tests.
What CI health grade does this workflow get?
This Node.js workflow grades C. Paste your own workflow into the Latchkey grader to see its grade and the exact fixes.
How can I improve this Node.js workflow?
Apply run de-duplication, job timeouts. Latchkey applies these automatically on managed runners when you point runs-on at Latchkey.

References