-
-
Notifications
You must be signed in to change notification settings - Fork 185
feat: enable auto-publishing on NPM after a GitHub release #1051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0f795be
feat: enable auto-publishing on NPM after a GitHub release
phoenix-ru 2323a91
chore: address review
phoenix-ru ef36a22
chore: specify PNPM version and bump Node version in CI
phoenix-ru 9a6d11d
chore: remove redundant version due to a CI error
phoenix-ru 7c88083
chore: simplify publish workflow
phoenix-ru 3629dc2
temp: dry-run
phoenix-ru 8a458fe
temp: add mock tag for dry-run of NPM publish
phoenix-ru 1d367c3
Revert "temp: add mock tag for dry-run of NPM publish"
phoenix-ru 1fcd911
Revert "temp: dry-run"
phoenix-ru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
name: Release on NPM | ||
|
||
on: | ||
release: | ||
types: [published] # runs when a GitHub Release is published | ||
|
||
permissions: | ||
contents: read | ||
id-token: write # required for npm provenance | ||
|
||
env: | ||
NODE_VER: 22.18 | ||
CI: true | ||
|
||
jobs: | ||
publish: | ||
name: Publish package from release tag | ||
# Run only when tag is in the format `vX.Y.Z` produced by `npm version` | ||
if: startsWith(github.event.release.tag_name, 'v') | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out the tag referenced by this release | ||
uses: actions/checkout@v5 | ||
with: | ||
ref: ${{ github.event.release.tag_name }} | ||
fetch-depth: 0 | ||
|
||
- name: Install pnpm | ||
uses: pnpm/action-setup@v4 | ||
with: | ||
run_install: false | ||
|
||
- name: Setup Node.js and pnpm | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: ${{ env.NODE_VER }} | ||
cache: 'pnpm' | ||
# This is required for `setup-node` to generate the registry URL into .npmrc | ||
# See https://github.com/actions/setup-node/blob/5e2628c959b9ade56971c0afcebbe5332d44b398/action.yml#L17-L18 | ||
registry-url: 'https://registry.npmjs.org/' | ||
|
||
- name: Verify tag matches package.json version | ||
run: | | ||
TAG="${{ github.event.release.tag_name }}" | ||
PKG_VERSION=$(node -p "require('./package.json').version") | ||
if [ "v$PKG_VERSION" != "$TAG" ]; then | ||
echo "::error ::Tag ($TAG) does not match package.json version (v$PKG_VERSION)" | ||
exit 1 | ||
fi | ||
|
||
- name: Install deps | ||
run: | | ||
pnpm --version | ||
BracketJohn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pnpm install --frozen-lockfile | ||
pnpm dev:prepare | ||
|
||
# Note: no build step because npm publish would run `prepack` script which builds the module | ||
|
||
- name: Publish to npm with provenance | ||
env: | ||
# Environment variable used by `setup-node` action | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: | | ||
TAG="${{ github.event.release.tag_name }}" | ||
|
||
# Stable release (vX.Y.Z) | ||
if echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+$'; then | ||
npm publish --provenance --access public | ||
|
||
# Pre-release (vX.Y.Z-*) | ||
elif echo "$TAG" | grep -Eq '^v[0-9]+\.[0-9]+\.[0-9]+-'; then | ||
npm publish --provenance --access public --tag next | ||
|
||
else | ||
echo "Not a valid release tag ($TAG), skipping publish." | ||
fi | ||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we specify the exact version of pnpm we want to use, to ensure consistent/stable builds?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PNPM is already using a correct version, see: https://github.com/sidebase/nuxt-auth/actions/runs/17260489231/job/48980590409
Another piece of evidence:
9.6.0
, it was correctly installed10.15.0
, it was also correctly picked upThis means that the presence of
packageManager
field insidepackage.json
is beneficial for both Corepack flow (keep the version consistent across contributors) and CI (use single source of truth) πI checked the action source and it is in fact true that the action reads the version (also documented): https://github.com/pnpm/action-setup/blob/f2b2b233b538f500472c7274c7012f57857d8ce0/src/install-pnpm/run.ts#L54-L56