From 7ac837050f524657f571d08a6e538d2000fa7c6a Mon Sep 17 00:00:00 2001 From: pomelo-nwu Date: Tue, 22 Jul 2025 17:54:55 +0800 Subject: [PATCH] fix: improve GitHub Actions workflow to handle duplicate tags and npm versions - Add tag existence check to avoid duplicate git tag creation - Add npm version existence check to avoid duplicate publishing - Improve error handling and logging output - Optimize npm authentication configuration --- .github/workflows/npm-publish.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml index 04c349a..86a982e 100644 --- a/.github/workflows/npm-publish.yml +++ b/.github/workflows/npm-publish.yml @@ -37,8 +37,14 @@ jobs: run: | git config --local user.email "${{ github.actor }}@users.noreply.github.com" git config --local user.name "${{ github.actor }}" - git tag v${{ steps.version.outputs.version }} - git push origin v${{ steps.version.outputs.version }} + TAG_NAME="v${{ steps.version.outputs.version }}" + if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then + echo "Tag $TAG_NAME already exists, skipping tag creation" + else + echo "Creating tag $TAG_NAME" + git tag "$TAG_NAME" + git push origin "$TAG_NAME" + fi - name: Publish env: @@ -46,4 +52,12 @@ jobs: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: | echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc - npm publish + npm publish || { + if [[ $? -eq 1 && $(npm view @dashscope-js/claude-code-config@${{ steps.version.outputs.version }} version 2>/dev/null) == "${{ steps.version.outputs.version }}" ]]; then + echo "Version ${{ steps.version.outputs.version }} already exists on npm, skipping publish" + exit 0 + else + echo "Publish failed with error code $?" + exit 1 + fi + }