Skip to content

Commit 4290fe1

Browse files
committed
Enhance npm publish workflow to dynamically determine dist-tag based on version format
- Added a step to determine the npm dist-tag ('next' for pre-releases and 'latest' for stable releases) based on the version in package.json. - Updated the npm publish command to use the determined dist-tag.
1 parent a2eaf64 commit 4290fe1

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

.github/workflows/publish-npm.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ jobs:
126126
working-directory: node
127127
run: npm run sync:version
128128

129+
- name: Determine npm dist-tag
130+
id: dist_tag
131+
working-directory: node
132+
run: |
133+
VERSION="$(node -p "require('./package.json').version")"
134+
if [[ "$VERSION" == *-* ]]; then
135+
TAG="next"
136+
else
137+
TAG="latest"
138+
fi
139+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
140+
echo "Using npm dist-tag '$TAG' for version '$VERSION'"
141+
129142
- name: Create npm target directories
130143
working-directory: node
131144
run: npx napi create-npm-dirs
@@ -148,9 +161,10 @@ jobs:
148161
- name: Prepublish native packages
149162
working-directory: node
150163
run: npx napi prepublish -t npm
164+
env:
165+
GITHUB_TOKEN: ${{ github.token }}
166+
NPM_CONFIG_TAG: ${{ steps.dist_tag.outputs.tag }}
151167

152168
- name: Publish JS package
153169
working-directory: node
154-
run: npm publish --provenance --access public
155-
env:
156-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
170+
run: npm publish --provenance --access public --tag "${{ steps.dist_tag.outputs.tag }}"

0 commit comments

Comments
 (0)