2121
2222 steps :
2323 - name : 检出代码
24- uses : actions/checkout@v4
24+ uses : actions/checkout@v5
2525 with :
2626 fetch-depth : 0
2727
@@ -77,14 +77,19 @@ jobs:
7777 - name : 更新版本号 (手动触发时)
7878 if : github.event_name == 'workflow_dispatch'
7979 run : |
80- npm version ${{ steps.get_version.outputs.version }} --no-git-tag-version
81- git config --local user.email "action@github.com"
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 "action@github.com"
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
8893
8994 - name : 生成变更日志
9095 id : changelog
@@ -94,20 +99,28 @@ jobs:
9499 GITHUB_TOKEN : ${{secrets.GITHUB_TOKEN}}
95100
96101 - 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
98114 env :
99115 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
100116
101- - name : 创建 GitHub Release
102- uses : actions/create-release@v1
103- env :
104- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
117+ - name : Create GitHub Release
118+ uses : ncipollo/release-action@v1
105119 with :
106- tag_name : ${{ steps.get_version.outputs.tag_name }}
107- release_name : Release ${{ steps.get_version.outputs.tag_name }}
108- body_path : ${{ steps.changelog.outputs.changelog_file }}
109- draft : false
110- prerelease : false
120+ generateReleaseNotes : " true"
121+ allowUpdates : true
122+ skipIfReleaseExists : false
123+ omitBodyDuringUpdate : false
111124
112125 - name : 通知发布成功
113126 run : |
0 commit comments