Node.js CI workflow (mcollina/autocannon)
The Node.js CI workflow from mcollina/autocannon, explained and optimized by Latchkey.
CI health: C - fair
Point runs-on at Latchkey and get caching, job timeouts, SHA-pinned actions, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Node.js CI workflow from the mcollina/autocannon repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
name: Node.js CI
on: [ push, pull_request ]
# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}"
cancel-in-progress: true
jobs:
test:
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [20, 22]
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: node --version
- run: npm --version
- run: npm install
- run: npm test
env:
CI: true
automerge:
if: >
github.event_name == 'pull_request' &&
github.event.pull_request.user.login == 'dependabot[bot]'
needs: test
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: write
steps:
- uses: fastify/github-action-merge-dependabot@v3
with:
exclude: 'chalk;pretty-bytes'
github-token: ${{ secrets.github_token }}
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.
name: Node.js CI on: [ push, pull_request ] # This allows a subsequently queued workflow run to interrupt previous runs concurrency: group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" cancel-in-progress: true jobs: test: timeout-minutes: 30 runs-on: ${{ matrix.os }} permissions: contents: read strategy: fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] node-version: [20, 22] steps: - uses: actions/checkout@v3 with: persist-credentials: false - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: cache: 'npm' node-version: ${{ matrix.node-version }} - run: node --version - run: npm --version - run: npm install - run: npm test env: CI: true automerge: timeout-minutes: 30 if: > github.event_name == 'pull_request' && github.event.pull_request.user.login == 'dependabot[bot]' needs: test runs-on: latchkey-small permissions: pull-requests: write contents: write steps: - uses: fastify/github-action-merge-dependabot@v3 with: exclude: 'chalk;pretty-bytes' github-token: ${{ secrets.github_token }}
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. - 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.
1 third-party action is referenced by a movable tag. Pin it to the commit SHA (Latchkey resolves and applies this automatically) so a repointed tag cannot change what runs.
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 2 jobs (7 with the matrix expanded) per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.