Publish to npm workflow (melonjs/melonJS)
The Publish to npm workflow from melonjs/melonJS, 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 Publish to npm workflow from the melonjs/melonJS 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: Publish to npm
on:
workflow_dispatch:
inputs:
package:
description: "Package to publish"
required: true
type: choice
options:
- melonjs
- debug-plugin
- tiled-inflate-plugin
- spine-plugin
- matter-adapter
- planck-adapter
- capacitor-plugin
- create-melonjs
dry-run:
description: "Dry run (skip actual publish)"
required: false
type: boolean
default: false
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
environment: npm
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
registry-url: "https://registry.npmjs.org"
- uses: pnpm/action-setup@v5
- name: Install dependencies
run: pnpm install
- name: Lint & check
run: |
pnpm lint
pnpm biome check
- name: Set package directory
id: pkg
run: |
if [ "${{ inputs.package }}" = "melonjs" ]; then
echo "dir=packages/melonjs" >> "$GITHUB_OUTPUT"
echo "build_cmd=pnpm dist:publish" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.package }}" = "debug-plugin" ]; then
echo "dir=packages/debug-plugin" >> "$GITHUB_OUTPUT"
echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.package }}" = "tiled-inflate-plugin" ]; then
echo "dir=packages/tiled-inflate-plugin" >> "$GITHUB_OUTPUT"
echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.package }}" = "spine-plugin" ]; then
echo "dir=packages/spine-plugin" >> "$GITHUB_OUTPUT"
echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.package }}" = "matter-adapter" ]; then
echo "dir=packages/matter-adapter" >> "$GITHUB_OUTPUT"
echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.package }}" = "planck-adapter" ]; then
echo "dir=packages/planck-adapter" >> "$GITHUB_OUTPUT"
echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.package }}" = "capacitor-plugin" ]; then
echo "dir=packages/capacitor-plugin" >> "$GITHUB_OUTPUT"
echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT"
elif [ "${{ inputs.package }}" = "create-melonjs" ]; then
echo "dir=packages/create-melonjs" >> "$GITHUB_OUTPUT"
echo "build_cmd=echo 'No build step needed'" >> "$GITHUB_OUTPUT"
fi
- name: Build & test
working-directory: ${{ steps.pkg.outputs.dir }}
run: ${{ steps.pkg.outputs.build_cmd }}
- name: Publish to npm
if: ${{ !inputs.dry-run }}
working-directory: ${{ steps.pkg.outputs.dir }}
run: npm publish --access=public --provenance
- name: Publish (dry run)
if: ${{ inputs.dry-run }}
working-directory: ${{ steps.pkg.outputs.dir }}
run: npm publish --access=public --dry-run
- name: Create GitHub release
if: ${{ !inputs.dry-run && inputs.package == 'melonjs' }}
run: pnpm tsx scripts/release.ts ${{ inputs.package }}
env:
GH_TOKEN: ${{ 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: Publish to npm on: workflow_dispatch: inputs: package: description: "Package to publish" required: true type: choice options: - melonjs - debug-plugin - tiled-inflate-plugin - spine-plugin - matter-adapter - planck-adapter - capacitor-plugin - create-melonjs dry-run: description: "Dry run (skip actual publish)" required: false type: boolean default: false jobs: publish: timeout-minutes: 30 runs-on: latchkey-small permissions: contents: write id-token: write environment: npm steps: - uses: actions/checkout@v5 with: fetch-depth: 0 - name: Setup Node.js uses: actions/setup-node@v6 with: cache: 'npm' node-version: 24 registry-url: "https://registry.npmjs.org" - uses: pnpm/action-setup@v5 - name: Install dependencies run: pnpm install - name: Lint & check run: | pnpm lint pnpm biome check - name: Set package directory id: pkg run: | if [ "${{ inputs.package }}" = "melonjs" ]; then echo "dir=packages/melonjs" >> "$GITHUB_OUTPUT" echo "build_cmd=pnpm dist:publish" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.package }}" = "debug-plugin" ]; then echo "dir=packages/debug-plugin" >> "$GITHUB_OUTPUT" echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.package }}" = "tiled-inflate-plugin" ]; then echo "dir=packages/tiled-inflate-plugin" >> "$GITHUB_OUTPUT" echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.package }}" = "spine-plugin" ]; then echo "dir=packages/spine-plugin" >> "$GITHUB_OUTPUT" echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.package }}" = "matter-adapter" ]; then echo "dir=packages/matter-adapter" >> "$GITHUB_OUTPUT" echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.package }}" = "planck-adapter" ]; then echo "dir=packages/planck-adapter" >> "$GITHUB_OUTPUT" echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.package }}" = "capacitor-plugin" ]; then echo "dir=packages/capacitor-plugin" >> "$GITHUB_OUTPUT" echo "build_cmd=pnpm clean && pnpm build" >> "$GITHUB_OUTPUT" elif [ "${{ inputs.package }}" = "create-melonjs" ]; then echo "dir=packages/create-melonjs" >> "$GITHUB_OUTPUT" echo "build_cmd=echo 'No build step needed'" >> "$GITHUB_OUTPUT" fi - name: Build & test working-directory: ${{ steps.pkg.outputs.dir }} run: ${{ steps.pkg.outputs.build_cmd }} - name: Publish to npm if: ${{ !inputs.dry-run }} working-directory: ${{ steps.pkg.outputs.dir }} run: npm publish --access=public --provenance - name: Publish (dry run) if: ${{ inputs.dry-run }} working-directory: ${{ steps.pkg.outputs.dir }} run: npm publish --access=public --dry-run - name: Create GitHub release if: ${{ !inputs.dry-run && inputs.package == 'melonjs' }} run: pnpm tsx scripts/release.ts ${{ inputs.package }} env: GH_TOKEN: ${{ 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 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.