Skip to content

Commit c68e112

Browse files
committed
ci: release configuration for improved changelog and versioning
1 parent e958ca7 commit c68e112

File tree

3 files changed

+196
-18
lines changed

3 files changed

+196
-18
lines changed

.github/workflows/go-releaser.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ jobs:
1818
- if: ${{ !startsWith(github.ref, 'refs/tags/v') }}
1919
run: echo "flags=--snapshot" >> $GITHUB_ENV
2020
- uses: actions/checkout@v5
21-
- uses: actions/setup-go@v3
2221
with:
23-
go-version: 1.21
22+
fetch-depth: 0 # 获取完整的 git 历史,用于生成 changelog
23+
- uses: actions/setup-go@v5
24+
with:
25+
go-version: '1.23'
2426
cache: true
2527
- uses: sigstore/[email protected]
2628
- uses: anchore/sbom-action/[email protected]
27-
- uses: goreleaser/goreleaser-action@v5
29+
- uses: goreleaser/goreleaser-action@v6
2830
with:
2931
distribution: goreleaser
30-
version: latest
32+
version: '~> v2' # 使用 v2.x 的最新版本
3133
args: release --clean ${{ env.flags }}
3234
env:
3335
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Create Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: '版本号 (如: 0.7.1, 1.0.0-beta.1)'
8+
required: true
9+
type: string
10+
prerelease:
11+
description: '是否为预发布版本'
12+
required: false
13+
type: boolean
14+
default: false
15+
16+
permissions:
17+
contents: write
18+
19+
jobs:
20+
create-release:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v5
25+
with:
26+
fetch-depth: 0
27+
token: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Validate version format
30+
run: |
31+
VERSION="${{ github.event.inputs.version }}"
32+
if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$'; then
33+
echo "❌ 错误: 无效的版本格式。请使用语义化版本 (如 1.2.3)"
34+
exit 1
35+
fi
36+
echo "✅ 版本格式验证通过: $VERSION"
37+
38+
- name: Check if tag exists
39+
run: |
40+
VERSION="${{ github.event.inputs.version }}"
41+
if git rev-parse "v$VERSION" >/dev/null 2>&1; then
42+
echo "❌ 错误: 标签 v$VERSION 已存在"
43+
exit 1
44+
fi
45+
echo "✅ 标签检查通过"
46+
47+
- name: Setup Git
48+
run: |
49+
git config user.name "github-actions[bot]"
50+
git config user.email "github-actions[bot]@users.noreply.github.com"
51+
52+
- name: Update version file
53+
run: |
54+
VERSION="${{ github.event.inputs.version }}"
55+
VERSION_FILE="internal/version.go"
56+
57+
echo "📝 更新版本文件: $VERSION_FILE"
58+
sed -i "s/const RuntimeVersion = \".*\"/const RuntimeVersion = \"$VERSION\"/" "$VERSION_FILE"
59+
60+
# 验证更新
61+
NEW_VERSION=$(grep 'const RuntimeVersion' "$VERSION_FILE" | sed 's/.*"\(.*\)".*/\1/')
62+
if [ "$NEW_VERSION" != "$VERSION" ]; then
63+
echo "❌ 错误: 版本更新失败"
64+
exit 1
65+
fi
66+
echo "✅ 版本已更新为: $VERSION"
67+
68+
- name: Commit and push version bump
69+
run: |
70+
VERSION="${{ github.event.inputs.version }}"
71+
git add internal/version.go
72+
git commit -m "chore: bump version to $VERSION"
73+
git push origin main
74+
75+
- name: Create and push tag
76+
run: |
77+
VERSION="${{ github.event.inputs.version }}"
78+
git tag -a "v$VERSION" -m "Release v$VERSION"
79+
git push origin "v$VERSION"
80+
echo "✅ 已创建并推送标签: v$VERSION"
81+
82+
- name: Wait for tag to be available
83+
run: |
84+
echo "⏳ 等待 tag 同步到 GitHub..."
85+
sleep 5
86+
echo "✅ Tag 应该已经可用,GoReleaser 即将开始工作"
87+
88+
- name: Summary
89+
run: |
90+
VERSION="${{ github.event.inputs.version }}"
91+
echo "### 🎉 版本发布已启动!" >> $GITHUB_STEP_SUMMARY
92+
echo "" >> $GITHUB_STEP_SUMMARY
93+
echo "**版本:** v$VERSION" >> $GITHUB_STEP_SUMMARY
94+
echo "**标签:** v$VERSION" >> $GITHUB_STEP_SUMMARY
95+
echo "" >> $GITHUB_STEP_SUMMARY
96+
echo "## 📋 后续自动流程" >> $GITHUB_STEP_SUMMARY
97+
echo "" >> $GITHUB_STEP_SUMMARY
98+
echo "1. ✅ 版本文件已更新 (\`internal/version.go\`)" >> $GITHUB_STEP_SUMMARY
99+
echo "2. ✅ Git 标签已创建并推送 (\`v$VERSION\`)" >> $GITHUB_STEP_SUMMARY
100+
echo "3. 🔄 [GoReleaser workflow](https://github.com/${{ github.repository }}/actions/workflows/go-releaser.yml) 正在构建..." >> $GITHUB_STEP_SUMMARY
101+
echo " - 构建所有平台的二进制文件" >> $GITHUB_STEP_SUMMARY
102+
echo " - 生成 checksums 和签名" >> $GITHUB_STEP_SUMMARY
103+
echo " - 创建 draft release 和 changelog" >> $GITHUB_STEP_SUMMARY
104+
echo " - 上传所有构建产物" >> $GITHUB_STEP_SUMMARY
105+
echo "4. 🔄 [Inno Setup workflow](https://github.com/${{ github.repository }}/actions/workflows/compile-inno-setup.yml) 将编译 Windows 安装包..." >> $GITHUB_STEP_SUMMARY
106+
echo "" >> $GITHUB_STEP_SUMMARY
107+
echo "## ⏭️ 下一步操作" >> $GITHUB_STEP_SUMMARY
108+
echo "" >> $GITHUB_STEP_SUMMARY
109+
echo "1. 等待 GoReleaser 和 Inno Setup workflows 完成(约 10-15 分钟)" >> $GITHUB_STEP_SUMMARY
110+
echo "2. 访问 [Releases 页面](https://github.com/${{ github.repository }}/releases)" >> $GITHUB_STEP_SUMMARY
111+
echo "3. 找到 \`v$VERSION\` 的 draft release" >> $GITHUB_STEP_SUMMARY
112+
echo "4. 检查 changelog 和所有附件是否完整" >> $GITHUB_STEP_SUMMARY
113+
echo "5. 点击 **Publish release** 正式发布" >> $GITHUB_STEP_SUMMARY
114+
echo "" >> $GITHUB_STEP_SUMMARY
115+
echo "---" >> $GITHUB_STEP_SUMMARY
116+
echo "" >> $GITHUB_STEP_SUMMARY
117+
echo "💡 **提示:** GoReleaser 会自动创建 draft release,你只需要最后点击发布按钮即可!" >> $GITHUB_STEP_SUMMARY
118+
119+
notify:
120+
needs: create-release
121+
runs-on: ubuntu-latest
122+
steps:
123+
- name: Summary
124+
run: |
125+
echo "### 🎉 发版流程已启动!" >> $GITHUB_STEP_SUMMARY
126+
echo "" >> $GITHUB_STEP_SUMMARY
127+
echo "**版本:** v${{ github.event.inputs.version }}" >> $GITHUB_STEP_SUMMARY
128+
echo "" >> $GITHUB_STEP_SUMMARY
129+
echo "**后续步骤:**" >> $GITHUB_STEP_SUMMARY
130+
echo "1. ✅ 版本号已更新" >> $GITHUB_STEP_SUMMARY
131+
echo "2. ✅ Git 标签已创建" >> $GITHUB_STEP_SUMMARY
132+
echo "3. 🔄 GoReleaser 正在构建资源..." >> $GITHUB_STEP_SUMMARY
133+
echo "4. 🔄 Inno Setup 将编译 Windows 安装包..." >> $GITHUB_STEP_SUMMARY
134+
echo "" >> $GITHUB_STEP_SUMMARY
135+
echo "**注意:** 请等待所有 workflow 完成后,在 [Releases](https://github.com/${{ github.repository }}/releases) 页面发布版本。" >> $GITHUB_STEP_SUMMARY

.goreleaser.yaml

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,24 +42,47 @@ changelog:
4242
filters:
4343
exclude:
4444
- "^test:"
45-
- "^chore"
45+
- "^chore:"
46+
- "^ci:"
47+
- "^style:"
4648
- "merge conflict"
4749
- Merge pull request
4850
- Merge remote-tracking branch
4951
- Merge branch
5052
- go mod tidy
5153
groups:
52-
- title: "New Features"
53-
regexp: '^feat:'
54-
order: 100
55-
- title: "Bug fixes"
56-
regexp: '^fix:'
57-
order: 200
58-
- title: "Documentation updates"
59-
regexp: '^doc:'
60-
order: 400
61-
- title: Other work
62-
order: 9999
54+
- title: "🚀 New Features"
55+
regexp: '^feat(\(.+\))?:'
56+
order: 0
57+
- title: "🐛 Bug Fixes"
58+
regexp: '^fix(\(.+\))?:'
59+
order: 1
60+
- title: "📝 Documentation"
61+
regexp: '^docs?(\(.+\))?:'
62+
order: 2
63+
- title: "⚡ Performance Improvements"
64+
regexp: '^perf(\(.+\))?:'
65+
order: 3
66+
- title: "♻️ Refactoring"
67+
regexp: '^refactor(\(.+\))?:'
68+
order: 4
69+
- title: "🎨 Styling"
70+
regexp: '^style(\(.+\))?:'
71+
order: 5
72+
- title: "🧪 Tests"
73+
regexp: '^test(\(.+\))?:'
74+
order: 6
75+
- title: "🔧 Chores"
76+
regexp: '^chore(\(.+\))?:'
77+
order: 7
78+
- title: "📦 Build & CI"
79+
regexp: '^(build|ci)(\(.+\))?:'
80+
order: 8
81+
- title: "⬆️ Dependencies"
82+
regexp: '^(deps|dep)(\(.+\))?:'
83+
order: 9
84+
- title: "Other Changes"
85+
order: 999
6386

6487
archives:
6588
- name_template: >-
@@ -178,8 +201,26 @@ signs:
178201
- --yes
179202

180203
release:
181-
draft: false
182-
prerelease: true
204+
# 先创建 draft,给你审查的机会
205+
draft: true
206+
# 自动检测是否为预发布版本(基于 tag 命名,如 v1.0.0-beta.1)
207+
prerelease: auto
183208
name_template: "v{{ .Version }}"
209+
# 如果设置为 true,会替换已存在的 release(用于重新发布)
210+
replace: false
211+
# 自动使用上面 changelog 配置生成的内容
212+
header: |
213+
## 🎉 What's Changed in v{{ .Version }}
214+
184215
footer: |
216+
217+
---
185218
**Full Changelog**: https://github.com/version-fox/vfox/compare/{{ .PreviousTag }}...{{ .Tag }}
219+
220+
## Installation
221+
222+
See [installation guide](https://vfox.dev/guides/quick-start.html) for more details.
223+
224+
## Thanks
225+
226+
Thanks to all contributors who made this release possible! 🎉

0 commit comments

Comments
 (0)