Conversation
Member
Copilot
AI
changed the title
[WIP] Refactor GitHub Actions to create reusable npm publish workflow
Refactor: extract npm publish into a dedicated reusable workflow with trusted publishing
Apr 7, 2026
Member
|
@copilot also handle the same on the patch release yaml |
Contributor
Author
maxkfranz
added a commit
that referenced
this pull request
Apr 10, 2026
…ns-release-workflow Refactor: extract npm publish into a dedicated reusable workflow with trusted publishing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The inline
npm publishstep infeature-release.ymlandpatch-release.ymlused a long-livedNPM_TOKENsecret, which is no longer viable. This refactors it into a dedicated reusable workflow using npm trusted publishing (OIDC/provenance) instead.Changes
New
.github/workflows/npm-publish.yml— reusable workflow (on: workflow_call) that:masternpm publish --provenance(noNODE_AUTH_TOKEN/NPM_TOKEN)permissions: { contents: read, id-token: write }for OIDC-based auth.github/workflows/feature-release.ymlPublish Package To npmjsstep and itsNODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}env varnpm_publishjob that fires afterfeature-releasecompletes, calling the reusable workflow:.github/workflows/patch-release.ymlPublish Package To npmjsstep and itsNODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}env varnpm_publishjob that fires afterpatch-releasecompletes, calling the same reusable workflow:Required follow-up
Register
npm-publish.ymlas the trusted publisher workflow for thecytoscapepackage on npmjs.com to complete the OIDC trust setup.Original prompt
Refactor the GitHub Actions release workflow in repository
cytoscape/cytoscape.jsso that the npm publish logic is moved out of.github/workflows/feature-release.ymlinto its own dedicated reusable workflow file under.github/workflows/.Context:
.github/workflows/feature-release.ymlon branchunstable.Publish Package To npmjsthat runsnpm publishusingNODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}.masterafter the existing merge/release preparation completes.NPM_TOKENfrom the refactor.feature-release.yml, publish frommaster, removeNPM_TOKEN.Requirements:
.github/workflows/npm-publish.yml(exact filename can be chosen if a better repository-consistent name exists)..github/workflows/feature-release.ymlto call the reusable workflow as a separate job after the existing release-preparation job succeeds.masterbefore publishing.NODE_AUTH_TOKENNPM_TOKENid-token: writeandcontents: readif needed.npm publishinvocation for trusted publishing/provenance if appropriate.VERSIONor other values need to be shared between jobs/workflows, implement a minimal robust mechanism.Please inspect the repository as needed to make the refactor correct and minimal. Then create a pull request with the changes.
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Could this step be separated into another yaml file and "called" from this yaml file somehow? I want to use the trusted publishing from npm with github actions and there needs to be just one yaml file with the npm publish part
Assistant: Yes — you can separate the npm publish logic into another YAML file and call it from the main workflow by using a reusable workflow (
workflow_call). That’s the GitHub Actions feature designed for exactly this kind of sharing. Publishing Node.js packagesFor your case, that means you can keep your existing
feature-release.ymlfor release orchestration, and move the npm publish job into a single dedicated workflow file such as.github/workflows/npm-publish.yml. Thenfeature-release.ymlcan call that reusable workflow. This is the cleanest way to keep one canonical npm publishing workflow while still triggering it from another workflow. Publishing Node.js packagesA few important caveats:
Reusable workflows are called at the job level, not step level.
So if by “this step” you literally mean one
steps:entry, you can’tuses:another YAML file from insidesteps:unless it’s a composite action. If you want another workflow YAML to be called, you must move that logic into its own job/workflow and call it withuses: ./.github/workflows/npm-publish.yml. Publishing Node.js packagesFor npm publishing with provenance / trusted publishing, GitHub’s Node publishing example requires at least:
contents: readid-token: writeThose permissions need to be present in the job that does the publish. Publishing Node.js packages
GitHub’s publishing example for npm still shows
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}along withnpm publish --provenance. If you are specifically switching to npm trusted publishing to avoid long-lived npm tokens, you’ll want the publish workflow to be the only place where the npm publish happens, and then configure npm trusted publishing on the npm side to trust that GitHub Actions workflow identity. The GitHub docs confirm theid-token: writerequirement for provenance-related publishing. Publishing Node.js packagesA typical structure would look like this:
feature-release.yml