Skip to content
Latchkey

publish to npmjs workflow (sverweij/dependency-cruiser)

The publish to npmjs workflow from sverweij/dependency-cruiser, explained and optimized by Latchkey.

C

CI health: C - fair

Point runs-on at Latchkey and get caching, job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.

Grade your own workflow free or run it on Latchkey →
Source: sverweij/dependency-cruiser.github/workflows/release.ymlLicense MITView source

What it does

This is the publish to npmjs workflow from the sverweij/dependency-cruiser 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

workflow (.yml)
name: publish to npmjs
on:
  release:
    # it is simpler to have separate release.yml and prerelease.yml workflows,
    # however, on npm you can only associate one workflow as trusted (or however
    # it's called exactly) - so we need to combine both in one workflow, with
    # the if conditions on the steps.
    types: [released, prereleased]

jobs:
  publish:
    environment: npm
    if: github.repository == 'sverweij/dependency-cruiser'
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          node-version: 26.x
          registry-url: https://registry.npmjs.org
      # staged publishing works as of npm@11.15.0. Until that or higher is
      # shipped with nodejs by default we need to install it manually.
      - run: npm install -g npm@^11.15.0
      - run: |
          node --version
          npm --version
      # legacy peer deps because otherwise typescript-eslint hard-complains
      # as it can't find a suitable typescript compiler (we're on 6 now, 
      # ts-eslint isn't yet)
      - run: npm clean-install --legacy-peer-deps
      - name: publish as latest
        run: npm stage publish --provenance --access public
        if: github.event.release.prerelease == false
      - name: publish as beta
        run: npm stage publish --provenance --access public --tag beta
        if: github.event.release.prerelease == true

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: publish to npmjs
on:
  release:
    # it is simpler to have separate release.yml and prerelease.yml workflows,
    # however, on npm you can only associate one workflow as trusted (or however
    # it's called exactly) - so we need to combine both in one workflow, with
    # the if conditions on the steps.
    types: [released, prereleased]
 
jobs:
  publish:
    timeout-minutes: 30
    environment: npm
    if: github.repository == 'sverweij/dependency-cruiser'
    runs-on: latchkey-small
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-node@v6
        with:
          cache: 'npm'
          node-version: 26.x
          registry-url: https://registry.npmjs.org
      # staged publishing works as of npm@11.15.0. Until that or higher is
      # shipped with nodejs by default we need to install it manually.
      - run: npm install -g npm@^11.15.0
      - run: |
          node --version
          npm --version
      # legacy peer deps because otherwise typescript-eslint hard-complains
      # as it can't find a suitable typescript compiler (we're on 6 now, 
      # ts-eslint isn't yet)
      - run: npm clean-install --legacy-peer-deps
      - name: publish as latest
        run: npm stage publish --provenance --access public
        if: github.event.release.prerelease == false
      - name: publish as beta
        run: npm stage publish --provenance --access public --tag beta
        if: github.event.release.prerelease == true
 

What changed

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:

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

Actions used in this workflow