@@ -77,14 +77,19 @@ jobs:
77
77
- name : 更新版本号 (手动触发时)
78
78
if : github.event_name == 'workflow_dispatch'
79
79
run : |
80
- npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
81
- git config --local user.email "[email protected] "
82
- git config --local user.name "GitHub Action"
83
- git add package.json
84
- git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
85
- git tag ${{ steps.get_version.outputs.tag_name }}
86
- git push origin HEAD:${{ github.ref_name }}
87
- git push origin ${{ steps.get_version.outputs.tag_name }}
80
+ # 检查 tag 是否已经存在
81
+ if git show-ref --tags --verify --quiet "refs/tags/${{ steps.get_version.outputs.tag_name }}"; then
82
+ echo "⚠️ Tag ${{ steps.get_version.outputs.tag_name }} 已存在,跳过创建"
83
+ else
84
+ npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
85
+ git config --local user.email "[email protected] "
86
+ git config --local user.name "GitHub Action"
87
+ git add package.json
88
+ git commit -m "chore: bump version to ${{ steps.get_version.outputs.version }}"
89
+ git tag ${{ steps.get_version.outputs.tag_name }}
90
+ git push origin HEAD:${{ github.ref_name }}
91
+ git push origin ${{ steps.get_version.outputs.tag_name }}
92
+ fi
88
93
89
94
- name : 生成变更日志
90
95
id : changelog
@@ -94,14 +99,28 @@ jobs:
94
99
GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
95
100
96
101
- name : 发布到 npm
97
- run : pnpm publish --no-git-checks
102
+ run : |
103
+ # 检查版本是否已经发布到 npm
104
+ PACKAGE_NAME=$(node -p "require('./package.json').name")
105
+ CURRENT_VERSION=$(node -p "require('./package.json').version")
106
+
107
+ # 尝试获取 npm 上的版本信息
108
+ if npm view "${PACKAGE_NAME}@${CURRENT_VERSION}" version 2>/dev/null; then
109
+ echo "⚠️ 版本 ${CURRENT_VERSION} 已存在于 npm,跳过发布"
110
+ else
111
+ echo "📦 发布版本 ${CURRENT_VERSION} 到 npm..."
112
+ pnpm publish --no-git-checks
113
+ fi
98
114
env :
99
115
NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
100
116
101
117
- name : Create GitHub Release
102
118
uses : ncipollo/release-action@v1
103
119
with :
104
120
generateReleaseNotes : " true"
121
+ allowUpdates : true
122
+ skipIfReleaseExists : false
123
+ omitBodyDuringUpdate : false
105
124
106
125
- name : 通知发布成功
107
126
run : |
0 commit comments