ci: fix npm upgrade in publish job + add workflow_dispatch fallback#3
Merged
ci: fix npm upgrade in publish job + add workflow_dispatch fallback#3
Conversation
`npm install -g npm@latest` is broken on Node 22.22.2's bundled npm (missing 'promise-retry'), which broke the 0.1.3 publish. Switch to `npx -y npm@11.5.2 publish` — pinned for Trusted Publisher OIDC, no broken global install needed. Also add a workflow_dispatch trigger with a `tag` input so a publish can be re-run for an existing tag (e.g. v0.1.3) when CI flaked, without having to bump versions.
| id-token: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: |
There was a problem hiding this comment.
In workflow_dispatch, inputs.tag is passed directly to actions/checkout as ref, which can be any branch/commit/ref string, not necessarily a release tag. This makes it possible to accidentally (or intentionally) publish arbitrary code to npm instead of an immutable release tag.
Suggested change
| with: | |
| ref: refs/tags/${{ inputs.tag }} |
Fix prompt (copy to your AI agent)
Update `.github/workflows/release.yml` so manual publish only accepts real tags: use `ref: refs/tags/${{ inputs.tag }}` (not raw input), and add a validation step before publish that fails unless `inputs.tag` matches your release pattern (for example `^v[0-9]+\.[0-9]+\.[0-9]+$`) and exists in `refs/tags/`.
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.
Summary
npm install -g npm@lateststep (Node 22.22.2's bundled npm corrupts itself mid-install withCannot find module 'promise-retry') withnpx -y npm@11.5.2 publish --provenance --access public. This still satisfies the Trusted Publisher OIDC requirement of npm >= 11.5.1 without trying to upgrade the global npm.workflow_dispatchtrigger with ataginput so a failed publish can be re-run against an existing tag (e.g.v0.1.3) without having to bump versions.Why
npm install -g npm@latest, leaving the tag created on git but never pushed to npm. Once this lands, dispatching the workflow withtag=v0.1.3will publish 0.1.3 to npm.Test plan
gh workflow run release.yml -f tag=v0.1.3and confirmnpm view @squidcode/timebook versionreports0.1.3.