Skip to content

Commit 3731ef7

Browse files
committed
chore: 更新依赖项和 GitHub Actions 工作流,添加版本检查和发布逻辑
1 parent 9dcc1b6 commit 3731ef7

File tree

4 files changed

+245
-35
lines changed

4 files changed

+245
-35
lines changed

.github/workflows/release.yml

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
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 "[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
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: |

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"lint:write": "biome check . --write",
4848
"prepare": "simple-git-hooks && npm run build",
4949
"test": "playwright test",
50-
"bump": "npx bumpp"
50+
"bump": "bumpp"
5151
},
5252
"simple-git-hooks": {
5353
"pre-commit": "npm run lint:write"
@@ -59,6 +59,7 @@
5959
"@rslib/core": "^0.10.4",
6060
"@types/node": "^22.15.34",
6161
"@winner-fed/winjs": "*",
62+
"bumpp": "10.2.3",
6263
"playwright": "^1.53.2",
6364
"simple-git-hooks": "^2.13.0",
6465
"typescript": "^5.8.3"

0 commit comments

Comments
 (0)