Skip to content

Commit 901965d

Browse files
committed
Use pinned npm publish status action
1 parent 38835c4 commit 901965d

1 file changed

Lines changed: 65 additions & 8 deletions

File tree

.github/workflows/publish.yml

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
if: github.event.release.prerelease == false
1717
runs-on: ubuntu-latest
1818
outputs:
19-
should_publish: ${{ steps.npm_version.outputs.should_publish }}
19+
should_publish: ${{ steps.publish_status.outputs.exists == '0' }}
2020

2121
steps:
2222
- name: checkout
@@ -29,21 +29,25 @@ jobs:
2929
registry-url: https://registry.npmjs.org
3030

3131
- name: check npm package version
32-
id: npm_version
32+
id: publish_status
33+
uses: tehpsalmist/npm-publish-status-action@01cb25946b194a7a5468f22c8e74db04c283f121
34+
35+
- name: report npm package version status
3336
run: |
3437
package_name="$(node -p "require('./package.json').name")"
3538
package_version="$(node -p "require('./package.json').version")"
3639
37-
if npm view "${package_name}@${package_version}" version --json >/dev/null 2>&1; then
40+
if [ "${{ steps.publish_status.outputs.exists }}" = "1" ]; then
3841
echo "${package_name}@${package_version} is already published; exiting without publishing."
39-
echo "should_publish=false" >> "$GITHUB_OUTPUT"
40-
else
42+
elif [ "${{ steps.publish_status.outputs.exists }}" = "0" ]; then
4143
echo "${package_name}@${package_version} is not published yet; continuing."
42-
echo "should_publish=true" >> "$GITHUB_OUTPUT"
44+
else
45+
echo "::error::Unexpected npm publish status: ${{ steps.publish_status.outputs.exists }}"
46+
exit 1
4347
fi
4448
45-
publish:
46-
name: publish to npmjs
49+
verify:
50+
name: verify package
4751
needs: check
4852
if: needs.check.outputs.should_publish == 'true'
4953
runs-on: ubuntu-latest
@@ -71,6 +75,59 @@ jobs:
7175
- name: verify runtime dependency tree
7276
run: npm ls --omit=dev --all
7377

78+
prepublish_check:
79+
name: check npm package version before publish
80+
needs: verify
81+
if: github.event.release.prerelease == false
82+
runs-on: ubuntu-latest
83+
outputs:
84+
should_publish: ${{ steps.publish_status.outputs.exists == '0' }}
85+
86+
steps:
87+
- name: checkout
88+
uses: actions/checkout@v6
89+
90+
- name: setup node 24
91+
uses: actions/setup-node@v6
92+
with:
93+
node-version: 24
94+
registry-url: https://registry.npmjs.org
95+
96+
- name: check npm package version
97+
id: publish_status
98+
uses: tehpsalmist/npm-publish-status-action@01cb25946b194a7a5468f22c8e74db04c283f121
99+
100+
- name: report npm package version status
101+
run: |
102+
package_name="$(node -p "require('./package.json').name")"
103+
package_version="$(node -p "require('./package.json').version")"
104+
105+
if [ "${{ steps.publish_status.outputs.exists }}" = "1" ]; then
106+
echo "${package_name}@${package_version} was published while this workflow was verifying; exiting without publishing."
107+
elif [ "${{ steps.publish_status.outputs.exists }}" = "0" ]; then
108+
echo "${package_name}@${package_version} is still not published; continuing."
109+
else
110+
echo "::error::Unexpected npm publish status: ${{ steps.publish_status.outputs.exists }}"
111+
exit 1
112+
fi
113+
114+
publish:
115+
name: publish to npmjs
116+
needs: prepublish_check
117+
if: needs.prepublish_check.outputs.should_publish == 'true'
118+
runs-on: ubuntu-latest
119+
120+
steps:
121+
- name: checkout
122+
uses: actions/checkout@v6
123+
124+
- name: setup node 24
125+
uses: actions/setup-node@v6
126+
with:
127+
node-version: 24
128+
registry-url: https://registry.npmjs.org
129+
cache: npm
130+
74131
- name: pack package
75132
id: pack
76133
run: |

0 commit comments

Comments
 (0)