From 966f10d9efc8f2007a44635aaa0b2882524fa45b Mon Sep 17 00:00:00 2001 From: Haitao Pan Date: Tue, 5 May 2026 11:19:32 +0800 Subject: [PATCH] Skip already published npm versions --- .github/workflows/publish.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 559114a..90fbc4c 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -37,7 +37,22 @@ jobs: - name: Typecheck run: pnpm typecheck + - name: Check published version + id: published + shell: bash + run: | + set -euo pipefail + name="$(node -p "require('./package.json').name")" + version="$(node -p "require('./package.json').version")" + if npm view "${name}@${version}" version >/dev/null 2>&1; then + echo "exists=true" >> "$GITHUB_OUTPUT" + echo "${name}@${version} is already published; skipping npm publish." + else + echo "exists=false" >> "$GITHUB_OUTPUT" + fi + - name: Publish + if: steps.published.outputs.exists != 'true' run: npm publish --provenance env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}