Skip to content

Commit 0751b80

Browse files
committed
chore: 更新发布工作流,添加手动触发支持并优化版本管理
1 parent ced6cfe commit 0751b80

File tree

1 file changed

+96
-14
lines changed

1 file changed

+96
-14
lines changed

.github/workflows/release.yml

Lines changed: 96 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,117 @@
11
name: Release
22

3-
permissions:
4-
id-token: write
5-
contents: write
6-
73
on:
84
push:
95
tags:
10-
- v*
6+
- 'v*'
7+
workflow_dispatch:
8+
inputs:
9+
version:
10+
description: '发布版本 (例如: 1.0.0)'
11+
required: true
12+
type: string
1113

1214
jobs:
1315
release:
1416
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
packages: write
20+
id-token: write
21+
1522
steps:
16-
- uses: actions/checkout@v5
23+
- name: 检出代码
24+
uses: actions/checkout@v4
1725
with:
1826
fetch-depth: 0
1927

20-
- uses: pnpm/action-setup@v4
28+
- name: 设置 Node.js
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: 22
32+
registry-url: 'https://registry.npmjs.org'
33+
34+
- name: 安装 pnpm
35+
uses: pnpm/action-setup@v4
36+
with:
37+
version: 10
38+
39+
- name: 获取 pnpm store 目录
40+
shell: bash
41+
run: |
42+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
2143
22-
- uses: actions/setup-node@v4
44+
- name: 设置 pnpm 缓存
45+
uses: actions/cache@v4
2346
with:
24-
node-version: lts/*
25-
registry-url: https://registry.npmjs.org/
26-
cache: pnpm
47+
path: ${{ env.STORE_PATH }}
48+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
49+
restore-keys: |
50+
${{ runner.os }}-pnpm-store-
51+
52+
- name: 安装依赖
53+
run: |
54+
# 尝试使用 frozen lockfile,如果失败则更新 lockfile
55+
pnpm install --frozen-lockfile || {
56+
echo "⚠️ Lockfile 不匹配,正在更新..."
57+
pnpm install --no-frozen-lockfile
58+
}
59+
60+
- name: 格式检查
61+
run: pnpm run lint
2762

28-
- run: pnpm install
63+
- name: 构建项目
64+
run: pnpm run build
2965

30-
- run: npx changelogithub
66+
- name: 获取版本号
67+
id: get_version
68+
run: |
69+
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
70+
echo "version=${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
71+
echo "tag_name=v${{ github.event.inputs.version }}" >> $GITHUB_OUTPUT
72+
else
73+
echo "version=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
74+
echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
75+
fi
76+
77+
- name: 更新版本号 (手动触发时)
78+
if: github.event_name == 'workflow_dispatch'
79+
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 }}
88+
89+
- name: 生成变更日志
90+
id: changelog
91+
run: npx changelogithub
3192
continue-on-error: true
3293
env:
3394
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
3495

35-
- run: npm i -g npm && pnpm publish --no-git-checks --provenance
96+
- name: 发布到 npm
97+
run: pnpm publish --no-git-checks
98+
env:
99+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
100+
101+
- name: 创建 GitHub Release
102+
uses: actions/create-release@v1
103+
env:
104+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
105+
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
111+
112+
- name: 通知发布成功
113+
run: |
114+
echo "🎉 发布成功!"
115+
echo "📦 版本: ${{ steps.get_version.outputs.version }}"
116+
echo "🏷️ 标签: ${{ steps.get_version.outputs.tag_name }}"
117+
echo "📝 npm: https://www.npmjs.com/package/@winner-fed/plugin-antdv"

0 commit comments

Comments
 (0)