Skip to content

Commit d8bad5a

Browse files
committed
Support pre-release publishing in npm-publish workflow (#1464)
Add automatic dist-tag detection to the publish step. npm requires `--tag` when publishing pre-release versions to prevent them from becoming the default `latest` on the registry. The new `Determine dist-tag` step reads the version from `package.json` and extracts the pre-release label (e.g. `alpha`, `beta`, `rc`) if present, otherwise defaults to `latest`. This tag is passed to `npm publish --tag`. Examples: - `1.9.0-alpha.0` → `--tag alpha` - `1.9.0-beta.1` → `--tag beta` - `1.9.0-rc.0` → `--tag rc` - `1.9.0` → `--tag latest` Fix: #1459
1 parent d7a7b3e commit d8bad5a

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

.github/workflows/npm-publish.yml

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,31 @@ jobs:
6969
- name: Pack
7070
run: ./scripts/npm-pack.sh
7171

72+
- name: Determine dist-tag
73+
id: dist_tag
74+
run: |
75+
TAG=$(node -p "
76+
const v = require('./package.json').version;
77+
const pre = v.split('-')[1];
78+
!pre ? 'latest' : (pre.split('.')[0].replace(/[0-9]+$/, '') || 'next')
79+
")
80+
if [[ -z "$TAG" ]]; then
81+
echo "::error::Failed to determine dist-tag"
82+
exit 1
83+
fi
84+
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
85+
echo "Resolved dist-tag: $TAG"
86+
7287
- name: Publish
7388
run: |
89+
TAG="${{ steps.dist_tag.outputs.tag }}"
90+
if [[ -z "$TAG" ]]; then
91+
echo "::error::dist-tag is empty, aborting publish"
92+
exit 1
93+
fi
7494
if [[ "${{ inputs.dry_run }}" == "true" ]]; then
7595
echo "=== DRY RUN ==="
76-
npm publish --provenance --access public --dry-run ./dist/rclnodejs-*.tgz
96+
npm publish --provenance --access public --tag "$TAG" --dry-run ./dist/rclnodejs-*.tgz
7797
else
78-
npm publish --provenance --access public ./dist/rclnodejs-*.tgz
98+
npm publish --provenance --access public --tag "$TAG" ./dist/rclnodejs-*.tgz
7999
fi

0 commit comments

Comments
 (0)