File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ name: Publish npm Package
33on :
44 push :
55 tags :
6- - " v *.*.*"
6+ - " *.*.*"
77
88permissions :
99 contents : read
3030 shell : bash
3131 run : |
3232 PACKAGE_VERSION="$(node -p "require('./package.json').version")"
33- if [ "v ${PACKAGE_VERSION}" != "${GITHUB_REF_NAME}" ]; then
34- echo "Tag ${GITHUB_REF_NAME} does not match package.json version v ${PACKAGE_VERSION}"
33+ if [ "${PACKAGE_VERSION}" != "${GITHUB_REF_NAME}" ]; then
34+ echo "Tag ${GITHUB_REF_NAME} does not match package.json version ${PACKAGE_VERSION}"
3535 exit 1
3636 fi
3737
4141 - name : Verify package contents
4242 run : npm run release:check
4343
44+ - name : Check whether version already exists on npm
45+ id : npm_version
46+ shell : bash
47+ run : |
48+ PACKAGE_NAME="$(node -p "require('./package.json').name")"
49+ PACKAGE_VERSION="$(node -p "require('./package.json').version")"
50+ if npm view "${PACKAGE_NAME}@${PACKAGE_VERSION}" version >/dev/null 2>&1; then
51+ echo "published=true" >> "$GITHUB_OUTPUT"
52+ echo "Version ${PACKAGE_VERSION} is already published. Skipping npm publish."
53+ else
54+ echo "published=false" >> "$GITHUB_OUTPUT"
55+ fi
56+
4457 - name : Publish package to npm
58+ if : steps.npm_version.outputs.published != 'true'
4559 run : npm publish --access public
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ npm publishing is automated by GitHub Actions in [`.github/workflows/publish-npm
88
99Normal pushes to ` main ` do not publish.
1010
11- Only a pushed version tag such as ` v0 .3.1` triggers a release.
11+ Only a pushed version tag such as ` 0 .3.1` triggers a release.
1212
1313## Standard Release Flow
1414
@@ -67,15 +67,15 @@ npm run release:smoke
6767After the version bump is committed on ` main ` , create and push the matching tag:
6868
6969``` bash
70- git tag vX .Y.Z
71- git push origin vX .Y.Z
70+ git tag X .Y.Z
71+ git push origin X .Y.Z
7272```
7373
7474Example:
7575
7676``` bash
77- git tag v0 .3.1
78- git push origin v0 .3.1
77+ git tag 0 .3.1
78+ git push origin 0 .3.1
7979```
8080
8181The workflow rejects the release if the Git tag does not exactly match ` package.json ` .
You can’t perform that action at this time.
0 commit comments