Skip to content

Commit def6af8

Browse files
committed
Address publish workflow review feedback
1 parent 5c8b9a2 commit def6af8

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ permissions:
1313
jobs:
1414
publish:
1515
name: publish to npmjs
16+
if: github.event.release.prerelease == false
1617
runs-on: ubuntu-latest
1718

1819
steps:
@@ -44,7 +45,22 @@ jobs:
4445
- name: verify runtime dependency tree
4546
run: npm ls --omit=dev --all
4647

48+
- name: check npm package version
49+
id: npm_version
50+
run: |
51+
package_name="$(node -p "require('./package.json').name")"
52+
package_version="$(node -p "require('./package.json').version")"
53+
54+
if npm view "${package_name}@${package_version}" version --json >/dev/null 2>&1; then
55+
echo "exists=true" >> "$GITHUB_OUTPUT"
56+
else
57+
echo "exists=false" >> "$GITHUB_OUTPUT"
58+
fi
59+
60+
echo "package=${package_name}@${package_version}" >> "$GITHUB_OUTPUT"
61+
4762
- name: pack package
63+
if: steps.npm_version.outputs.exists == 'false'
4864
id: pack
4965
run: |
5066
mkdir -p dist
@@ -54,18 +70,21 @@ jobs:
5470
echo "tarball=$tarball" >> "$GITHUB_OUTPUT"
5571
5672
- name: attest npm package artifact
73+
if: steps.npm_version.outputs.exists == 'false'
5774
uses: actions/attest@v4
5875
with:
5976
subject-path: ${{ steps.pack.outputs.tarball }}
6077

6178
- name: upload npm package artifact
79+
if: steps.npm_version.outputs.exists == 'false'
6280
uses: actions/upload-artifact@v4
6381
with:
6482
name: npm-package
6583
path: ${{ steps.pack.outputs.tarball }}
6684
if-no-files-found: error
6785

6886
- name: publish package
87+
if: steps.npm_version.outputs.exists == 'false'
6988
run: npm publish "$TARBALL" --provenance --access public
7089
env:
7190
TARBALL: ${{ steps.pack.outputs.tarball }}

0 commit comments

Comments
 (0)