Skip to content

Commit 731fd56

Browse files
committed
chore: 改回合并
1 parent 72d1a14 commit 731fd56

File tree

2 files changed

+53
-63
lines changed

2 files changed

+53
-63
lines changed

.github/workflows/auto-tag.yml

-57
This file was deleted.

.github/workflows/release.yml

+53-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,62 @@ permissions:
44
contents: write
55

66
on:
7+
# 当对分支master进行push操作的时候,触发该条工作流
78
push:
8-
tags:
9-
- 'v*'
10-
create:
11-
tags:
12-
- 'v*'
9+
branches: [master]
10+
pull_request:
11+
branches: [master]
1312

1413
jobs:
14+
check:
15+
name: 检查并创建版本号
16+
runs-on: ubuntu-latest
17+
outputs:
18+
created: ${{ steps.create_tag.outputs.created }}
19+
steps:
20+
- name: 检出代码
21+
uses: actions/checkout@v4
22+
23+
- name: 配置 Node.js
24+
uses: actions/setup-node@v4
25+
26+
- name: 获取所有标签
27+
run: |
28+
git fetch --prune --unshallow
29+
30+
- name: 读取 package.json 版本号
31+
id: package_json
32+
run: |
33+
version=$(node -p "require('./package.json').version")
34+
echo "Package version is: $version"
35+
echo "version=$version" >> $GITHUB_OUTPUT
36+
37+
- name: 检查是否有重复的版本 tag
38+
id: check_version
39+
run: |
40+
package_version=v${{ steps.package_json.outputs.version }}
41+
if git tag -l "$package_version" | grep -q "$package_version"; then
42+
echo "::notice::版本 Tag '$package_version' 已存在。"
43+
echo "exists=true" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: 创建版本tag
47+
id: create_tag
48+
if: steps.check_version.outputs.exists != 'true'
49+
run: |
50+
set -e
51+
version_tag=v${{ steps.package_json.outputs.version }}
52+
echo "Creating new tag: $version_tag"
53+
git tag "$version_tag"
54+
git push origin "$version_tag"
55+
echo "created=true" >> $GITHUB_OUTPUT
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58+
1559
release:
1660
name: 构建并发版
61+
needs: check
62+
if: needs.check.outputs.created == 'true'
1763
runs-on: ubuntu-latest
1864
permissions:
1965
contents: write
@@ -145,7 +191,8 @@ jobs:
145191

146192
publish:
147193
name: 发布到 NPM
148-
needs: release
194+
needs: [check, release]
195+
if: needs.check.outputs.created == 'true'
149196
runs-on: ubuntu-latest
150197
permissions:
151198
id-token: write

0 commit comments

Comments
 (0)