From 274e1f097f3299948f8d867d84f9084e3f961efa Mon Sep 17 00:00:00 2001 From: Huakun Shen Date: Sat, 18 Jan 2025 03:00:18 -0500 Subject: [PATCH] ci: Enhance npm publish workflow to check for existing version in registry --- .github/workflows/npm-publish.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index daaab3e..048b272 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -31,6 +31,20 @@ jobs: with: node-version: 22 registry-url: https://registry.npmjs.org/ - - run: npm publish --provenance --access public + - run: | + PACKAGE_NAME=$(jq -r '.name' package.json) + PACKAGE_VERSION=$(jq -r '.version' package.json) + + # Get the version from npm registry + REGISTRY_VERSION=$(npm show "$PACKAGE_NAME" version) + + # Compare versions + if [ "$PACKAGE_VERSION" == "$REGISTRY_VERSION" ]; then + echo "Version $PACKAGE_VERSION already exists in the npm registry." + exit 0 + else + echo "Version $PACKAGE_VERSION does not exist in the npm registry. Proceeding..." + npm publish --provenance --access public + fi env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}