-
Notifications
You must be signed in to change notification settings - Fork 30
fix: npm publish workflow #113
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
base: master
Are you sure you want to change the base?
Changes from all commits
324c756
3fb026d
9e7d005
3d737ba
04b0cb6
0ef57a1
31122dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| name: npm-publish | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| # tag_name grouping - queues actual releases for the same tag | ||
| # run_id - fallback value required for group as tag_name might not always be present (manual triggers) | ||
| group: npm-publish-${{ github.event.release.tag_name || github.run_id }} | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| validate: | ||
| name: Validate | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| ref: ${{ github.event.release.tag_name || github.ref }} | ||
| persist-credentials: false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do in this context? I don't think I have ever seen this be necessary, so just want to make sure I understand why it is here.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This removes the github access token after the repo is cloned |
||
|
|
||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: 22.x | ||
|
|
||
| - name: verify release version | ||
| if: github.event_name == 'release' | ||
| run: | | ||
| pkg_name=$(jq -r .name package.json) | ||
| pkg_version=$(jq -r .version package.json) | ||
| tag_version="${GITHUB_EVENT_RELEASE_TAG_NAME#v}" | ||
| if [ "$pkg_version" != "$tag_version" ]; then | ||
| echo "package.json version ($pkg_version) does not match release tag ($tag_version)" | ||
| exit 1 | ||
| fi | ||
| if npm view "${pkg_name}@${pkg_version}" version >/dev/null 2>&1; then | ||
| echo "${pkg_name}@${pkg_version} is already published" | ||
| exit 1 | ||
| fi | ||
| env: | ||
| GITHUB_EVENT_RELEASE_TAG_NAME: ${{ github.event.release.tag_name }} | ||
|
|
||
| - name: validate publish package contents | ||
| run: | | ||
| npm pack --dry-run 2>&1 | tee pack.log | ||
| grep -q 'lib/' pack.log | ||
| ! grep -qE '[[:space:]]test/' pack.log | ||
| ! grep -qE '[[:space:]]tools/' pack.log | ||
|
|
||
| publish: | ||
| name: publish | ||
| needs: validate | ||
| if: github.event_name == 'release' | ||
| runs-on: ubuntu-latest | ||
| environment: Publish | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/checkout@v7 | ||
| with: | ||
| ref: ${{ github.event.release.tag_name }} | ||
| persist-credentials: false | ||
|
|
||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: 22.x | ||
| registry-url: https://registry.npmjs.org | ||
|
|
||
| - name: publish to npm | ||
| run: npm publish --provenance | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| name: release-please | ||
| permissions: | ||
| contents: write | ||
| issues: write | ||
| pull-requests: write | ||
| jobs: | ||
| release-please: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: googleapis/release-please-action@v5 | ||
| with: | ||
| release-type: node |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ Thumbs.db | |
|
|
||
| /node_modules/ | ||
| npm-debug.log | ||
| package-lock.json | ||
| yarn.lock | ||
|
|
||
| # build task results for ci | ||
|
|
||
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.
Might be worth a comment on why we want these settings here. While I agree with it for the
tag_namecase, the fallback torun_idseems odd so I want to make sure I understand the goal.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.
grouprequires a value and I pickedrun_idas fallback whentag_nameis not present - this can happen on manual triggers, dry run/testing purposes.