From 08a87b31281d63624ad24913a11d44caff8136bd Mon Sep 17 00:00:00 2001 From: ZacharyZcR <2903735704@qq.com> Date: Mon, 1 Jun 2026 08:42:17 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E5=AE=8C=E5=96=84=E5=8F=91=E7=89=88?= =?UTF-8?q?=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - release workflow 自动读取 .github/release-notes/.md 覆盖 body - 移除手动 prerelease input(goreleaser auto 模式根据 tag 后缀判断) - 新增 RELEASE.md 发版流程文档 --- .github/RELEASE.md | 64 +++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 37 +++++++++++++++++--- 2 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 .github/RELEASE.md diff --git a/.github/RELEASE.md b/.github/RELEASE.md new file mode 100644 index 0000000..be3d4fb --- /dev/null +++ b/.github/RELEASE.md @@ -0,0 +1,64 @@ +# 发版流程 + +## 预检查 + +```bash +# 1. 确认 CI 通过 +gh run list --branch dev --limit 3 + +# 2. 全平台 dry-run(手动触发 snapshot 模式) +gh workflow run release.yml -f snapshot=true + +# 3. 确认版本号一致 +grep "version" common/globals.go +grep "版本" README.md +``` + +## 发版 + +```bash +# 1. 确认 release notes 已就绪 +cat .github/release-notes/v.md + +# 2. 打 tag(在 dev 分支打 RC,在 main 分支打正式版) +git tag v +git push origin v + +# CI 自动执行: +# - goreleaser 全平台构建 + UPX 压缩 +# - 创建 GitHub Release(RC 自动标记 pre-release) +# - 用 .github/release-notes/ 下的文件覆盖 release body +``` + +## 版本号规范 + +| 场景 | 格式 | 分支 | 示例 | +|------|------|------|------| +| 正式版 | `vX.Y.Z` | main | `v2.2.0` | +| 预发布 | `vX.Y.Z-rc` | dev | `v2.2.0-rc` | +| 热修复 | `vX.Y.Z` | main | `v2.2.1` | + +## Release Notes 模板 + +放在 `.github/release-notes/.md`,格式参考 `v2.2.0-rc.md`。 + +如果文件不存在,goreleaser 会自动生成基于 commit 的 changelog。 + +## 正式版发布(RC → 正式) + +```bash +# 1. 合并 dev 到 main +git checkout main +git merge dev +git push + +# 2. 更新版本号去掉 -rc +# common/globals.go, README.md, README_EN.md + +# 3. 准备正式版 release notes +# .github/release-notes/v2.2.0.md + +# 4. 打 tag +git tag v2.2.0 +git push origin v2.2.0 +``` diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a601997..6562fbd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,10 +14,6 @@ on: description: '创建草稿发布' type: boolean default: false - prerelease: - description: '标记为预发布' - type: boolean - default: false permissions: contents: write @@ -36,10 +32,41 @@ jobs: with: fetch-depth: 0 + - name: 准备 Release Notes + if: ${{ !inputs.snapshot }} + run: | + TAG="${GITHUB_REF_NAME}" + NOTES_FILE=".github/release-notes/${TAG}.md" + + if [ -f "$NOTES_FILE" ]; then + echo "📝 找到版本 Release Notes: $NOTES_FILE" + cp "$NOTES_FILE" /tmp/release-notes.md + else + echo "⚠️ 未找到 $NOTES_FILE,使用自动生成的 changelog" + echo "" > /tmp/release-notes.md + fi + + echo "RELEASE_NOTES_FILE=/tmp/release-notes.md" >> $GITHUB_ENV + - name: 构建和发布 uses: ./.github/actions/build-release with: mode: ${{ inputs.snapshot && 'snapshot' || 'release' }} go-version: '1.20' retention-days: '90' - release-args: ${{ inputs.draft && '--draft' || '' }} ${{ inputs.prerelease && '--prerelease' || '' }} + release-args: ${{ inputs.draft && '--draft' || '' }} + + - name: 更新 Release Notes + if: ${{ !inputs.snapshot && env.RELEASE_NOTES_FILE != '' }} + env: + GH_TOKEN: ${{ github.token }} + run: | + TAG="${GITHUB_REF_NAME}" + NOTES_FILE="${RELEASE_NOTES_FILE}" + + if [ -s "$NOTES_FILE" ]; then + echo "📝 更新 Release Notes..." + # 用版本特定的 notes 替换 goreleaser 生成的 body + gh release edit "$TAG" --notes-file "$NOTES_FILE" + echo "✅ Release Notes 已更新" + fi