Skip to content

Commit 4a37d32

Browse files
committed
Add npm version check to publish workflow
The GitHub Actions workflow now checks if the package version already exists on npm before publishing, preventing duplicate version errors. The CI/CD guide was updated to emphasize the need to bump the version before release and clarify the tagging process.
1 parent a295388 commit 4a37d32

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.github/workflows/publish.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ jobs:
2828
- name: Build package
2929
run: npm run build
3030

31+
- name: Check if version exists
32+
id: version-check
33+
run: |
34+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
35+
echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
36+
if npm view use-async-view@$PACKAGE_VERSION version 2>/dev/null; then
37+
echo "❌ Version $PACKAGE_VERSION already exists on npm"
38+
exit 1
39+
else
40+
echo "✅ Version $PACKAGE_VERSION is available"
41+
fi
42+
env:
43+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
44+
3145
- name: Publish to npm
3246
run: npm publish --provenance --access public
3347
env:

CI_CD_GUIDE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ This repository uses GitHub Actions to automatically publish to npm when you cre
2626

2727
### Automated Publishing (Recommended)
2828

29+
> ⚠️ **IMPORTANT**: You must bump the version before creating a release. npm doesn't allow publishing the same version twice.
30+
2931
1. **Update version in package.json**
3032
```bash
3133
npm version patch # 1.0.0 → 1.0.1 (bug fixes)
@@ -34,7 +36,7 @@ This repository uses GitHub Actions to automatically publish to npm when you cre
3436
# or
3537
npm version major # 1.0.0 → 2.0.0 (breaking changes)
3638
```
37-
This creates a git tag automatically.
39+
This creates a git tag automatically (e.g., `v1.0.1`).
3840

3941
2. **Push the tag to GitHub**
4042
```bash

0 commit comments

Comments
 (0)