Fix attempt to delete nonexistent npm tag (#4374)

(cherry picked from commit 9fa550c62f)
This commit is contained in:
Francisco
2023-06-20 13:06:39 -03:00
committed by Francisco Giordano
parent fd81a96f01
commit 17c1a3a458

View File

@ -2,19 +2,25 @@
set -euo pipefail set -euo pipefail
PACKAGE_JSON_NAME="$(tar xfO "$TARBALL" package/package.json | jq -r .name)"
PACKAGE_JSON_VERSION="$(tar xfO "$TARBALL" package/package.json | jq -r .version)"
# Intentionally escape $ to avoid interpolation and writing the token to disk # Intentionally escape $ to avoid interpolation and writing the token to disk
echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc echo "//registry.npmjs.org/:_authToken=\${NPM_TOKEN}" > .npmrc
# Actual publish # Actual publish
npm publish "$TARBALL" --tag "$TAG" npm publish "$TARBALL" --tag "$TAG"
# Clean up tags
delete_tag() { delete_tag() {
PACKAGE_JSON_NAME="$(tar xfO "$TARBALL" package/package.json | jq -r .name)"
npm dist-tag rm "$PACKAGE_JSON_NAME" "$1" npm dist-tag rm "$PACKAGE_JSON_NAME" "$1"
} }
if [ "$TAG" = tmp ]; then if [ "$TAG" = tmp ]; then
delete_tag "$TAG" delete_tag "$TAG"
elif [ "$TAG" = latest ]; then elif [ "$TAG" = latest ]; then
delete_tag next # Delete the next tag if it exists and is a prerelease for what is currently being published
if npm dist-tag ls "$PACKAGE_JSON_NAME" | grep -q "next: $PACKAGE_JSON_VERSION"; then
delete_tag next
fi
fi fi