Install
$ agentstack add skill-schalkneethling-claude-toolkit-npm-trusted-publishing-github-workflow ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
NPM Trusted Publish
Goal
Implement the same hardened npm trusted publishing pattern every time, without rediscovering the details from CI logs.
Related skills
This skill generates and debugs the publish workflow file. For the surrounding security posture — account and repository 2FA, branch protection, GitHub publish environments, release-strategy choice, and sole-maintainer risk — use the npm-package-publishing skill. The two are complementary: npm-package-publishing decides how publishing should be set up, this skill writes and fixes the YAML that does it.
One number to keep consistent between the two: both skills use Node 24.8.0 or higher as the publish-step floor. Node 24.8.0 bundles npm 11.6.0, which already exceeds the npm CLI 11.5.1 minimum that trusted publishing requires, so on that floor no manual npm upgrade is needed. If a project must publish on an older Node, it has to upgrade npm to 11.5.1 or later first — the publish job retains a guard step for exactly that case.
Workflow
- Inspect
package.json,.npmrc, lockfiles, and existing.github/workflows/*.yml. - Resolve every workflow dependency to its latest stable version at the moment the file is created, and pin each to the full-length commit SHA of that version. Never leave third-party or GitHub-owned actions pinned to tag-based refs such as
@v4,@v6, or@v7in the final workflow; tag refs weaken supply-chain integrity and violate pinned-action policy. The SHAs in this skill's template are placeholders that will be out of date; never copy them verbatim. See "Pinning actions to current SHAs" below for the procedure. - Preserve pinned action SHAs when they already exist; annotate each with a version comment so Dependabot can bump it.
- Drive the test and build jobs' Node version from the project's existing target, not from a number invented for this workflow. Read it from the repo's current
devEngines.runtime,.nvmrc,.node-version,volta.node, or CI config; if none exists, ask the developer rather than guessing. For pnpm projects, preferpnpm/setupand either let it readdevEngines.runtimefrompackage.jsonor set itsruntimeinput to the resolved existing target, such asnode@22. Do not point runtime selection atengines.node, which is the consumer compatibility range — an unbounded range like>=20can float CI away from the version developers actually run. - Never raise the project's Node version, create a new
.nvmrc, or overwrite an existing one to "match" the publish step. The publish step's Node 24.8.0 (step 11) is an isolated requirement of the publish action and must not propagate to.nvmrc, toengines.node, or to the test and build jobs. A project that targets Node 22 keeps testing and building on Node 22; only the finalnpm publishinvocation runs on 24.8.0, and it does not rebuild the artifact. Conflating these two numbers is the most likely way this skill is misapplied — do not do it. - Ensure every job that reads the repo (including any reading
.nvmrc) runsactions/checkoutfirst. - For pnpm workflows, use
pnpm/setupfrom the GitHub Marketplace instead of combiningpnpm/action-setupwithactions/setup-node. It installs pnpm from@pnpm/exeand installs the requested JavaScript runtime throughpnpm runtime setin one step. Pin it to a full commit SHA like every other action. - Set
install: falseonpnpm/setupin release/publish workflows, then runpnpm install --frozen-lockfile --ignore-scriptsexplicitly. The action can auto-install by default, but release workflows should keep install flags visible and hardened. - Do not use Corepack in release workflows: it is still marked experimental and downloads the package manager from the network on first use, which is an avoidable failure surface in a release pipeline.
- Set
persist-credentials: falseon everyactions/checkoutstep. Never rely on checkout's default credential persistence. If a workflow genuinely must push to git, use an explicit, narrowly scoped credential only for that push step. - Target Node 24.8.0 or higher in the publish step. That floor bundles npm 11.6.0, which already exceeds the npm CLI 11.5.1 minimum trusted publishing requires, so no manual npm upgrade is needed there. Keep a guard step that upgrades npm only when the resolved Node ships an npm below 11.5.1, so the workflow stays correct if a project pins an older Node. An npm that is too old silently falls back to token auth or fails to attempt OIDC at all.
- Pack into a dedicated artifact directory, usually
package/*.tgz. - In the publish job, download the artifact to
package, find the.tgz, and publish its resolved path. - Use GitHub OIDC trusted publishing, not npm tokens. Provenance is generated automatically under trusted publishing, so the
--provenanceflag is not required. - Add a
concurrencygroup keyed on the release so two tag pushes cannot race into overlapping publishes.
GitHub Token Permissions
Every GitHub Actions workflow this skill creates or edits must declare explicit least-privilege GITHUB_TOKEN permissions. Add a top-level permissions: block that grants the workflow-wide minimum, usually contents: read, then add job-level permissions: only where a job needs more.
For trusted npm publishing, only the publish job should receive id-token: write; test and build jobs should stay at contents: read. If a project genuinely needs another scope, grant it only to the specific job that requires it and document why in the workflow review notes. Never rely on GitHub's repository default token permissions.
Every actions/checkout step must include persist-credentials: false, including jobs that build or upload artifacts. Persisted checkout credentials unnecessarily leave GITHUB_TOKEN available to later build, test, packaging, and artifact steps.
Package Metadata
Three different Node versions live in three different places, and keeping them separate is deliberate — conflating them is the main way this workflow goes wrong. engines.node in package.json is the consumer floor: the only one that constrains people who install the package, and it should reflect what the package actually supports (npm warns, but does not hard-fail, when a consumer is outside it). The test and build jobs run on the project's own target version, read from devEngines.runtime or the existing .nvmrc/.node-version/volta.node/CI config; these are development and CI targets, so they do not leak into the consumer contract. The publish step pins Node 24.8.0 or higher independently, purely because that floor bundles an npm new enough for OIDC. These three are not meant to agree: a repo can develop and test on Node 22, keep engines.node at its true support range, and still publish on Node 24 — all without affecting consumers, and without changing what the project builds and tests against.
The publish-step version must never be copied into the other two. Do not raise engines.node to 24.8.0, and do not set or bump .nvmrc or devEngines.runtime to 24, to "make things consistent". Doing so would move the test and build jobs onto Node 24, so the package would be validated against a version above its actual target and a Node-22 incompatibility could ship uncaught. The publish job runs npm publish on the already-built tarball with scripts ignored, so its Node version never rebuilds or retests the code; it plays no role in building the artifact.
{
"engines": {
"node": ">=20"
},
"packageManager": "pnpm@11.0.4",
"devEngines": {
"runtime": { "name": "node", "version": "^22.0.0", "onFail": "download" }
},
"repository": {
"type": "git",
"url": "git+https://github.com/OWNER/REPO.git"
}
}
The engines.node value above is the consumer floor and should reflect what the package actually supports; >=20 is only an example, and a bounded upper limit is sensible if the package genuinely needs one. Do not raise it to 24.8.0 to satisfy CI — the publish step pins its own Node version, and the test and build jobs read theirs from devEngines.runtime or another existing project target, so the trusted-publishing requirement never leaks into the consumer contract.
For pnpm projects, prefer declaring the development runtime in devEngines.runtime so pnpm/setup can read the runtime and version from package.json. If the repo already uses .nvmrc, .node-version, volta.node, or existing CI config instead, keep that source of truth and set pnpm/setup's runtime input to the same resolved version. Do not default to the publish step's 24.8.0.
The repository.url field is not cosmetic. Provenance verification runs through Sigstore, which compares the repository in the OIDC token against package.json. A mismatch fails the publish with a 422 error that the user-facing npm docs do not explain. Make sure the owner/name in repository.url matches the repository actually running the workflow.
Do not add npm auth tokens for trusted publishing.
Workflow Template
Use this shape for pnpm packages, adapting only names, test commands, and existing pinned action SHAs. The @ values below are placeholders: before writing the file, resolve each action to its latest stable release and replace the placeholder with that release's full-length commit SHA, keeping the # vX.Y.Z comment accurate. Do not copy the example SHAs — see "Pinning actions to current SHAs".
# NOTE: every action SHA below is a PLACEHOLDER and is almost certainly out of date.
# Re-resolve each action to its latest stable release and pin to that SHA before use.
# See "Pinning actions to current SHAs".
name: Publish
on:
release:
types: [published]
permissions:
contents: read
concurrency:
group: publish-${{ github.event.release.tag_name }}
cancel-in-progress: false
jobs:
test:
name: Test
runs-on: ubuntu-latest
timeout-minutes: 60
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 — PLACEHOLDER SHA, re-resolve before use
with:
persist-credentials: false
- name: Setup pnpm and Node.js
uses: pnpm/setup@1111111111111111111111111111111111111111 # v1.0.0 — PLACEHOLDER SHA, re-resolve before use
with:
# Runtime is read from devEngines.runtime when present. If the project uses
# .nvmrc/.node-version/volta instead, set runtime to that exact target
# (for example, runtime: node@22). Do not use engines.node here.
install: false
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Check package
run: pnpm run package:check
- name: Run tests
run: pnpm test
build:
name: Pack package
needs: test
runs-on: ubuntu-latest
timeout-minutes: 10
permissions:
contents: read
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 — PLACEHOLDER SHA, re-resolve before use
with:
persist-credentials: false
- name: Setup pnpm and Node.js
uses: pnpm/setup@1111111111111111111111111111111111111111 # v1.0.0 — PLACEHOLDER SHA, re-resolve before use
with:
# Runtime is read from devEngines.runtime when present. If the project uses
# .nvmrc/.node-version/volta instead, set runtime to that exact target
# (for example, runtime: node@22). Do not use engines.node here.
install: false
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Create package directory
run: mkdir package
- name: Create package tarball
run: pnpm pack --pack-destination package
- name: Upload package tarball
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1 — PLACEHOLDER SHA, re-resolve before use
with:
name: npm-package
path: package/*.tgz
if-no-files-found: error
retention-days: 7
publish:
name: Publish to npm
needs: build
runs-on: ubuntu-latest
timeout-minutes: 10
environment: publish
permissions:
contents: read
id-token: write
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.2.2 — PLACEHOLDER SHA, re-resolve before use
with:
persist-credentials: false
- name: Setup pnpm and Node.js
uses: pnpm/setup@1111111111111111111111111111111111111111 # v1.0.0 — PLACEHOLDER SHA, re-resolve before use
with:
# Pinned for the publish step only. 24.8.0 bundles npm 11.6.0, new enough
# for OIDC; this is independent of engines.node, the consumer floor.
runtime: node@24.8.0
install: false
- name: Ensure npm is new enough for trusted publishing
# No-op on Node >= 24.8.0; the guard only matters if Node is pinned lower.
run: |
required="11.5.1"
current="$(npm --version)"
if npx -y semver -r " /dev/null 2>&1; then
echo "npm $current is below $required; upgrading."
npm install -g npm@latest
fi
npm --version
- name: Download package tarball
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4.1.9 — PLACEHOLDER SHA, re-resolve before use
with:
name: npm-package
path: package
- name: Publish to npm
run: |
tarball="$(find package -type f -name '*.tgz' -print -quit)"
if [ -z "$tarball" ]; then
echo "No package tarball found in downloaded artifact."
find package -maxdepth 3 -type f -print
exit 1
fi
npm publish "$(realpath "$tarball")" --ignore-scripts --access public --registry https://registry.npmjs.org
Pinning actions to current SHAs
The template's SHAs are stale by design. Action versions and their commit SHAs change over time, so resolve them fresh whenever a publish.yml is created or reviewed. Pin to the full-length commit SHA, never a tag or branch, because a tag can be moved to point at malicious code after you have reviewed it. Tag-based refs such as @v4, @v6, and @v7 are acceptable only as temporary input to a pinning tool; they must not survive in committed workflow YAML.
There are two reliable ways to produce current pins.
The preferred approach is to let tooling resolve and pin for you. Write the workflow first using human-readable tags only in the temporary draft consumed by the tool (for example actions/checkout@v4), then run npx actions-up in the repository to rewrite every uses: reference to the latest stable release pinned to its commit SHA, with a version comment appended. This is the same tool the npm-package-publishing skill recommends, and it removes the chance of a hand-typed SHA being wrong. After it runs, confirm each line carries a @ # vX.Y.Z form.
If resolving manually, for each action find the latest stable release tag, then read the exact commit that tag points to and pin that commit:
# Latest stable release tag for an action (skips pre-releases)
gh release view --repo actions/checkout --json tagName --jq .tagName
# The commit SHA that the tag resolves to — pin THIS value
gh api repos/actions/checkout/git/refs/tags/v4.2.2 --jq .object.sha
For an annotated tag the first lookup may return a tag object rather than a commit; dereference it with gh api repos///git/tags/ --jq .object.sha to reach the underlying commit. Pin the commit SHA, not the tag SHA.
Keep the pins current after creation by letting Dependabot manage action updates. This is why every uses: line carries a # vX.Y.Z comment: Dependabot reads the comment to
…
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: schalkneethling
- Source: schalkneethling/claude-toolkit
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.