Skip to content

Commit 71049c3

Browse files
committed
fix: 改进 GitHub Actions 工作流,处理重复 tag 和 npm 版本问题
- 添加 tag 存在性检查,避免重复创建 git tag - 添加 npm 版本存在性检查,避免重复发布 - 改进错误处理和日志输出 - 优化 npm 认证配置
1 parent 3eac5b4 commit 71049c3

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

.github/workflows/npm-publish.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,27 @@ jobs:
3737
run: |
3838
git config --local user.email "${{ github.actor }}@users.noreply.github.com"
3939
git config --local user.name "${{ github.actor }}"
40-
git tag v${{ steps.version.outputs.version }}
41-
git push origin v${{ steps.version.outputs.version }}
40+
TAG_NAME="v${{ steps.version.outputs.version }}"
41+
if git rev-parse "$TAG_NAME" >/dev/null 2>&1; then
42+
echo "Tag $TAG_NAME already exists, skipping tag creation"
43+
else
44+
echo "Creating tag $TAG_NAME"
45+
git tag "$TAG_NAME"
46+
git push origin "$TAG_NAME"
47+
fi
4248
4349
- name: Publish
4450
env:
4551
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4652
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
4753
run: |
4854
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
49-
npm publish
55+
npm publish || {
56+
if [[ $? -eq 1 && $(npm view @dashscope-js/claude-code-config@${{ steps.version.outputs.version }} version 2>/dev/null) == "${{ steps.version.outputs.version }}" ]]; then
57+
echo "Version ${{ steps.version.outputs.version }} already exists on npm, skipping publish"
58+
exit 0
59+
else
60+
echo "Publish failed with error code $?"
61+
exit 1
62+
fi
63+
}

0 commit comments

Comments
 (0)