NPM Publish workflow (koajs/koa)
The NPM Publish workflow from koajs/koa, 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 NPM Publish workflow from the koajs/koa 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: NPM Publish
# Trigger when tags matching semver format are pushed, or manually via workflow_dispatch.
# Manual triggers allow selecting a specific tag to publish (e.g. tags from the v2.x branch).
#
# Patterns match common semver formats:
# - v1.0.0 (standard)
# - v1.0.0-alpha (pre-release)
# - v1.0.0-beta.1 (pre-release with number)
#
# Note: GitHub Actions uses glob patterns (not full regex), which limits
# complex semver matching. These patterns cover most npm publishing scenarios.
# For complex dotted pre-releases (v1.0.0-alpha.beta.1), use simpler formats
# like v1.0.0-alphabeta1 or create the workflow manually.
"on":
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+'
- 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+.[0-9]+'
workflow_dispatch:
inputs:
tag:
description: 'Git tag to checkout and publish (e.g. v2.15.4)'
required: true
type: string
# Permissions for NPM trusted publishing with provenance
permissions:
contents: read
id-token: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v5
with:
ref: ${{ inputs.tag || github.ref }}
- name: Setup Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6
with:
node-version: 24
- name: Install dependencies
run: npm ci
- name: Publish to NPM
run: npm publish
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: NPM Publish # Trigger when tags matching semver format are pushed, or manually via workflow_dispatch. # Manual triggers allow selecting a specific tag to publish (e.g. tags from the v2.x branch). # # Patterns match common semver formats: # - v1.0.0 (standard) # - v1.0.0-alpha (pre-release) # - v1.0.0-beta.1 (pre-release with number) # # Note: GitHub Actions uses glob patterns (not full regex), which limits # complex semver matching. These patterns cover most npm publishing scenarios. # For complex dotted pre-releases (v1.0.0-alpha.beta.1), use simpler formats # like v1.0.0-alphabeta1 or create the workflow manually. "on": push: tags: - 'v[0-9]+.[0-9]+.[0-9]+' - 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+' - 'v[0-9]+.[0-9]+.[0-9]+-[a-zA-Z0-9]+.[0-9]+' workflow_dispatch: inputs: tag: description: 'Git tag to checkout and publish (e.g. v2.15.4)' required: true type: string # Permissions for NPM trusted publishing with provenance permissions: contents: read id-token: write concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: publish: timeout-minutes: 30 runs-on: latchkey-small steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v5 with: ref: ${{ inputs.tag || github.ref }} - name: Setup Node.js uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6 with: cache: 'npm' node-version: 24 - name: Install dependencies run: npm ci - name: Publish to NPM run: npm publish
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.
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 per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.