File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -175,11 +175,55 @@ jobs:
175175 run : |
176176 set -euo pipefail
177177 for pkg in npm/*; do
178- (cd "$pkg" && npm publish --access public --ignore-scripts)
178+ (
179+ cd "$pkg"
180+ NAME="$(node -p "require('./package.json').name")"
181+ VERSION="$(node -p "require('./package.json').version")"
182+ if npm view "${NAME}@${VERSION}" version >/dev/null 2>&1; then
183+ echo "${NAME}@${VERSION} already exists on npm, skipping."
184+ exit 0
185+ fi
186+
187+ set +e
188+ OUTPUT="$(npm publish --access public --ignore-scripts 2>&1)"
189+ STATUS=$?
190+ set -e
191+ echo "$OUTPUT"
192+
193+ if [ "$STATUS" -ne 0 ]; then
194+ if echo "$OUTPUT" | grep -Eqi "previously published|cannot publish over|already exists"; then
195+ echo "${NAME}@${VERSION} was already published, treating as success."
196+ exit 0
197+ fi
198+ exit "$STATUS"
199+ fi
200+ )
179201 done
180202
181203 - name : Publish to npm
182204 working-directory : sdk/node
183205 env :
184206 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
185- run : npm publish --access public --ignore-scripts
207+ shell : bash
208+ run : |
209+ set -euo pipefail
210+ NAME="$(node -p "require('./package.json').name")"
211+ VERSION="$(node -p "require('./package.json').version")"
212+ if npm view "${NAME}@${VERSION}" version >/dev/null 2>&1; then
213+ echo "${NAME}@${VERSION} already exists on npm, skipping."
214+ exit 0
215+ fi
216+
217+ set +e
218+ OUTPUT="$(npm publish --access public --ignore-scripts 2>&1)"
219+ STATUS=$?
220+ set -e
221+ echo "$OUTPUT"
222+
223+ if [ "$STATUS" -ne 0 ]; then
224+ if echo "$OUTPUT" | grep -Eqi "previously published|cannot publish over|already exists"; then
225+ echo "${NAME}@${VERSION} was already published, treating as success."
226+ exit 0
227+ fi
228+ exit "$STATUS"
229+ fi
You can’t perform that action at this time.
0 commit comments