CI workflow (npm/node-semver)
The CI workflow from npm/node-semver, explained and optimized by Latchkey.
CI health: D - needs work
Point runs-on at Latchkey and get caching, run de-duplication, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the CI workflow from the npm/node-semver repository, a real project running GitHub Actions. It is shown here with attribution under its ISC license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
# This file is automatically added by @npmcli/template-oss. Do not edit.
name: CI
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
- release/v*
schedule:
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
- cron: "0 9 * * 1"
permissions:
contents: read
jobs:
lint:
name: Lint
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v6
id: node
with:
node-version: 26.x
check-latest: contains('26.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Lint
run: npm run lint --ignore-scripts
- name: Post Lint
run: npm run postlint --ignore-scripts
test:
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
if: github.repository_owner == 'npm'
strategy:
fail-fast: false
matrix:
platform:
- name: Linux
os: ubuntu-latest
shell: bash
- name: macOS
os: macos-latest
shell: bash
- name: macOS
os: macos-15-intel
shell: bash
- name: Windows
os: windows-latest
shell: cmd
node-version:
- 10.0.0
- 10.x
- 12.x
- 14.x
- 16.x
- 18.x
- 20.x
- 22.x
- 24.x
- 26.x
exclude:
- platform: { name: macOS, os: macos-latest, shell: bash }
node-version: 10.0.0
- platform: { name: macOS, os: macos-latest, shell: bash }
node-version: 10.x
- platform: { name: macOS, os: macos-latest, shell: bash }
node-version: 12.x
- platform: { name: macOS, os: macos-latest, shell: bash }
node-version: 14.x
- platform: { name: macOS, os: macos-15-intel, shell: bash }
node-version: 16.x
- platform: { name: macOS, os: macos-15-intel, shell: bash }
node-version: 18.x
- platform: { name: macOS, os: macos-15-intel, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-15-intel, shell: bash }
node-version: 22.x
- platform: { name: macOS, os: macos-15-intel, shell: bash }
node-version: 24.x
- platform: { name: macOS, os: macos-15-intel, shell: bash }
node-version: 26.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v6
id: node
with:
node-version: ${{ matrix.node-version }}
check-latest: contains(matrix.node-version, '.x')
- name: Install Latest npm
if: ${{ !startsWith(matrix.node-version, '22.') }}
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
run: npm test --ignore-scripts
The same workflow, on Latchkey
Estimated ~20% faster on cache hits, plus fewer wasted runs and a safer supply chain. Added and changed lines are highlighted.
# This file is automatically added by @npmcli/template-oss. Do not edit. name: CI on: workflow_dispatch: pull_request: push: branches: - main - release/v* schedule: # "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1 - cron: "0 9 * * 1" permissions: contents: read concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: lint: timeout-minutes: 30 name: Lint if: github.repository_owner == 'npm' runs-on: latchkey-small defaults: run: shell: bash steps: - name: Checkout uses: actions/checkout@v6 - name: Setup Git User run: | git config --global user.email "npm-cli+bot@github.com" git config --global user.name "npm CLI robot" - name: Setup Node uses: actions/setup-node@v6 id: node with: cache: 'npm' node-version: 26.x check-latest: contains('26.x', '.x') - name: Install Latest npm uses: ./.github/actions/install-latest-npm with: node: ${{ steps.node.outputs.node-version }} - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Lint run: npm run lint --ignore-scripts - name: Post Lint run: npm run postlint --ignore-scripts test: timeout-minutes: 30 name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }} if: github.repository_owner == 'npm' strategy: fail-fast: false matrix: platform: - name: Linux os: ubuntu-latest shell: bash - name: macOS os: macos-latest shell: bash - name: macOS os: macos-15-intel shell: bash - name: Windows os: windows-latest shell: cmd node-version: - 10.0.0 - 10.x - 12.x - 14.x - 16.x - 18.x - 20.x - 22.x - 24.x - 26.x exclude: - platform: { name: macOS, os: macos-latest, shell: bash } node-version: 10.0.0 - platform: { name: macOS, os: macos-latest, shell: bash } node-version: 10.x - platform: { name: macOS, os: macos-latest, shell: bash } node-version: 12.x - platform: { name: macOS, os: macos-latest, shell: bash } node-version: 14.x - platform: { name: macOS, os: macos-15-intel, shell: bash } node-version: 16.x - platform: { name: macOS, os: macos-15-intel, shell: bash } node-version: 18.x - platform: { name: macOS, os: macos-15-intel, shell: bash } node-version: 20.x - platform: { name: macOS, os: macos-15-intel, shell: bash } node-version: 22.x - platform: { name: macOS, os: macos-15-intel, shell: bash } node-version: 24.x - platform: { name: macOS, os: macos-15-intel, shell: bash } node-version: 26.x runs-on: ${{ matrix.platform.os }} defaults: run: shell: ${{ matrix.platform.shell }} steps: - name: Checkout uses: actions/checkout@v6 - name: Setup Git User run: | git config --global user.email "npm-cli+bot@github.com" git config --global user.name "npm CLI robot" - name: Setup Node uses: actions/setup-node@v6 id: node with: cache: 'npm' node-version: ${{ matrix.node-version }} check-latest: contains(matrix.node-version, '.x') - name: Install Latest npm if: ${{ !startsWith(matrix.node-version, '22.') }} uses: ./.github/actions/install-latest-npm with: node: ${{ steps.node.outputs.node-version }} - name: Install Dependencies run: npm i --ignore-scripts --no-audit --no-fund - name: Add Problem Matcher run: echo "::add-matcher::.github/matchers/tap.json" - name: Test run: npm test --ignore-scripts
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 useslatchkey-small; pick the runner size that fits the job. - Cancel superseded runs when a branch or PR gets a newer push.
- Cache dependency installs on the setup step so they are served from cache.
- Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 2 jobs (41 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.