Publish Package workflow (jonobr1/two.js)
The Publish Package workflow from jonobr1/two.js, 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 Publish Package workflow from the jonobr1/two.js 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 Package
on:
push:
tags:
- 'v*'
permissions: read-all
jobs:
publish:
runs-on: ubuntu-latest
permissions:
id-token: write # Required for OIDC (npm provenance + GitHub attestation)
contents: write # Required to create GitHub releases and upload assets
attestations: write # Required for actions/attest-build-provenance
steps:
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6
- uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
# Ensure npm 11.5.1 or later is installed
- name: Update npm
run: npm install -g npm@11.5.1
- run: npm ci
- run: npm run build
- name: Generate SLSA provenance attestation
id: attest
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
with:
subject-path: |
build/two.js
build/two.module.js
build/two.min.js
- name: Stage provenance bundle for release
env:
BUNDLE_PATH: ${{ steps.attest.outputs.bundle-path }}
TAG: ${{ github.ref_name }}
run: cp "$BUNDLE_PATH" "two.js-${TAG}.intoto.jsonl"
- name: Upload provenance bundle as artifact
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: provenance-bundle-${{ github.ref_name }}
path: two.js-${{ github.ref_name }}.intoto.jsonl
- name: Publish to npm with provenance
run: npm publish --provenance
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ github.ref_name }}
run: |
gh release create "$TAG" \
--title "Official Stable Release of $TAG" \
--generate-notes \
build/two.js \
build/two.module.js \
build/two.min.js \
"two.js-${TAG}.intoto.jsonl"
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 Package on: push: tags: - 'v*' permissions: read-all concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: publish: timeout-minutes: 30 runs-on: latchkey-small permissions: id-token: write # Required for OIDC (npm provenance + GitHub attestation) contents: write # Required to create GitHub releases and upload assets attestations: write # Required for actions/attest-build-provenance steps: - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6 - uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6 with: cache: 'npm' node-version: '20' registry-url: 'https://registry.npmjs.org' # Ensure npm 11.5.1 or later is installed - name: Update npm run: npm install -g npm@11.5.1 - run: npm ci - run: npm run build - name: Generate SLSA provenance attestation id: attest uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0 with: subject-path: | build/two.js build/two.module.js build/two.min.js - name: Stage provenance bundle for release env: BUNDLE_PATH: ${{ steps.attest.outputs.bundle-path }} TAG: ${{ github.ref_name }} run: cp "$BUNDLE_PATH" "two.js-${TAG}.intoto.jsonl" - name: Upload provenance bundle as artifact uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 with: name: provenance-bundle-${{ github.ref_name }} path: two.js-${{ github.ref_name }}.intoto.jsonl - name: Publish to npm with provenance run: npm publish --provenance - name: Create GitHub Release env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} TAG: ${{ github.ref_name }} run: | gh release create "$TAG" \ --title "Official Stable Release of $TAG" \ --generate-notes \ build/two.js \ build/two.module.js \ build/two.min.js \ "two.js-${TAG}.intoto.jsonl"
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.