Skip to content

Commit 24a4417

Browse files
committed
ci: skip npm publish when version already exists
1 parent 9ad66aa commit 24a4417

File tree

4 files changed

+84
-4
lines changed

4 files changed

+84
-4
lines changed

.github/workflows/npm-publish.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,34 @@ jobs:
2323
node-version: "22"
2424
registry-url: "https://registry.npmjs.org"
2525

26+
- name: Read package metadata
27+
id: pkg
28+
run: |
29+
echo "name=$(node -p \"require('./package.json').name\")" >> "$GITHUB_OUTPUT"
30+
echo "version=$(node -p \"require('./package.json').version\")" >> "$GITHUB_OUTPUT"
31+
2632
- name: Verify tag matches package version
2733
run: |
2834
TAG="${{ github.event.release.tag_name }}"
29-
VERSION="$(node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); process.stdout.write(pkg.version)")"
35+
VERSION="${{ steps.pkg.outputs.version }}"
3036
if [ "v$VERSION" != "$TAG" ]; then
3137
echo "Tag $TAG does not match package.json version $VERSION"
3238
exit 1
3339
fi
3440
41+
- name: Check whether version already exists on npm
42+
id: npm_exists
43+
run: |
44+
if npm view "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}" version >/dev/null 2>&1; then
45+
echo "exists=true" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "exists=false" >> "$GITHUB_OUTPUT"
48+
fi
49+
3550
- name: Publish to npm (trusted publisher / OIDC)
51+
if: steps.npm_exists.outputs.exists != 'true'
3652
run: npm publish --provenance
53+
54+
- name: Skip message (already published)
55+
if: steps.npm_exists.outputs.exists == 'true'
56+
run: echo "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }} already exists on npm; skipping publish."

deep-review/.github/workflows/npm-publish.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,34 @@ jobs:
2323
node-version: "22"
2424
registry-url: "https://registry.npmjs.org"
2525

26+
- name: Read package metadata
27+
id: pkg
28+
run: |
29+
echo "name=$(node -p \"require('./package.json').name\")" >> "$GITHUB_OUTPUT"
30+
echo "version=$(node -p \"require('./package.json').version\")" >> "$GITHUB_OUTPUT"
31+
2632
- name: Verify tag matches package version
2733
run: |
2834
TAG="${{ github.event.release.tag_name }}"
29-
VERSION="$(node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); process.stdout.write(pkg.version)")"
35+
VERSION="${{ steps.pkg.outputs.version }}"
3036
if [ "v$VERSION" != "$TAG" ]; then
3137
echo "Tag $TAG does not match package.json version $VERSION"
3238
exit 1
3339
fi
3440
41+
- name: Check whether version already exists on npm
42+
id: npm_exists
43+
run: |
44+
if npm view "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}" version >/dev/null 2>&1; then
45+
echo "exists=true" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "exists=false" >> "$GITHUB_OUTPUT"
48+
fi
49+
3550
- name: Publish to npm (trusted publisher / OIDC)
51+
if: steps.npm_exists.outputs.exists != 'true'
3652
run: npm publish --provenance
53+
54+
- name: Skip message (already published)
55+
if: steps.npm_exists.outputs.exists == 'true'
56+
run: echo "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }} already exists on npm; skipping publish."

pi-notify/.github/workflows/npm-publish.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,34 @@ jobs:
2323
node-version: "22"
2424
registry-url: "https://registry.npmjs.org"
2525

26+
- name: Read package metadata
27+
id: pkg
28+
run: |
29+
echo "name=$(node -p \"require('./package.json').name\")" >> "$GITHUB_OUTPUT"
30+
echo "version=$(node -p \"require('./package.json').version\")" >> "$GITHUB_OUTPUT"
31+
2632
- name: Verify tag matches package version
2733
run: |
2834
TAG="${{ github.event.release.tag_name }}"
29-
VERSION="$(node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); process.stdout.write(pkg.version)")"
35+
VERSION="${{ steps.pkg.outputs.version }}"
3036
if [ "v$VERSION" != "$TAG" ]; then
3137
echo "Tag $TAG does not match package.json version $VERSION"
3238
exit 1
3339
fi
3440
41+
- name: Check whether version already exists on npm
42+
id: npm_exists
43+
run: |
44+
if npm view "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}" version >/dev/null 2>&1; then
45+
echo "exists=true" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "exists=false" >> "$GITHUB_OUTPUT"
48+
fi
49+
3550
- name: Publish to npm (trusted publisher / OIDC)
51+
if: steps.npm_exists.outputs.exists != 'true'
3652
run: npm publish --provenance
53+
54+
- name: Skip message (already published)
55+
if: steps.npm_exists.outputs.exists == 'true'
56+
run: echo "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }} already exists on npm; skipping publish."

pi-system-theme/.github/workflows/npm-publish.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,34 @@ jobs:
2323
node-version: "22"
2424
registry-url: "https://registry.npmjs.org"
2525

26+
- name: Read package metadata
27+
id: pkg
28+
run: |
29+
echo "name=$(node -p \"require('./package.json').name\")" >> "$GITHUB_OUTPUT"
30+
echo "version=$(node -p \"require('./package.json').version\")" >> "$GITHUB_OUTPUT"
31+
2632
- name: Verify tag matches package version
2733
run: |
2834
TAG="${{ github.event.release.tag_name }}"
29-
VERSION="$(node -e "const fs=require('fs'); const pkg=JSON.parse(fs.readFileSync('package.json','utf8')); process.stdout.write(pkg.version)")"
35+
VERSION="${{ steps.pkg.outputs.version }}"
3036
if [ "v$VERSION" != "$TAG" ]; then
3137
echo "Tag $TAG does not match package.json version $VERSION"
3238
exit 1
3339
fi
3440
41+
- name: Check whether version already exists on npm
42+
id: npm_exists
43+
run: |
44+
if npm view "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }}" version >/dev/null 2>&1; then
45+
echo "exists=true" >> "$GITHUB_OUTPUT"
46+
else
47+
echo "exists=false" >> "$GITHUB_OUTPUT"
48+
fi
49+
3550
- name: Publish to npm (trusted publisher / OIDC)
51+
if: steps.npm_exists.outputs.exists != 'true'
3652
run: npm publish --provenance
53+
54+
- name: Skip message (already published)
55+
if: steps.npm_exists.outputs.exists == 'true'
56+
run: echo "${{ steps.pkg.outputs.name }}@${{ steps.pkg.outputs.version }} already exists on npm; skipping publish."

0 commit comments

Comments
 (0)