|
| 1 | +--- |
| 2 | +name: "create-release-note" |
| 3 | +description: "从 PR/commit 中自动生成结构化的 Release Notes,并可选创建 GitHub Draft Release" |
| 4 | +usage: "/create-release-note <version> [prev-version]" |
| 5 | +--- |
| 6 | + |
| 7 | +# Create Release Note Command |
| 8 | + |
| 9 | +## 功能说明 |
| 10 | + |
| 11 | +自动从 PR、commit 和 Issue 中收集变更信息,按模块和类型分类,生成符合项目格式的 Release Notes。支持创建 GitHub Draft Release。 |
| 12 | + |
| 13 | +## 用法 |
| 14 | + |
| 15 | +```bash |
| 16 | +/release-notes <version> # 自动推断上一版本 |
| 17 | +/release-notes <version> <prev-version> # 手动指定版本范围 |
| 18 | +``` |
| 19 | + |
| 20 | +例如: |
| 21 | +```bash |
| 22 | +/create-release-note 3.6.3 # 自动推断上一版本为 3.6.2 |
| 23 | +/create-release-note 3.6.3 3.6.2 # 手动指定范围 |
| 24 | +``` |
| 25 | + |
| 26 | +## 参数说明 |
| 27 | + |
| 28 | +- `<version>`: 当前发布版本号,格式为 `X.Y.Z`(必需) |
| 29 | +- `<prev-version>`: 上一版本号,格式为 `X.Y.Z`(可选,不提供则自动推断) |
| 30 | + |
| 31 | +参数来源:`$ARGUMENTS` |
| 32 | + |
| 33 | +## 执行步骤 |
| 34 | + |
| 35 | +### 步骤 1:解析参数 |
| 36 | + |
| 37 | +从 `$ARGUMENTS` 中提取参数。支持两种形式: |
| 38 | +- 单参数:`<version>` — 当前版本号 |
| 39 | +- 双参数:`<version> <prev-version>` — 当前版本号和上一版本号 |
| 40 | + |
| 41 | +**版本号格式验证**: |
| 42 | +- 必须匹配 `X.Y.Z` 格式(X、Y、Z 均为非负整数) |
| 43 | +- 如果格式不正确,报错退出:`错误:版本号格式不正确,期望格式为 X.Y.Z(例如 3.6.3)` |
| 44 | + |
| 45 | +### 步骤 2:确定版本范围 |
| 46 | + |
| 47 | +**当前版本 tag**: `v<version>`(如 `v3.6.3`) |
| 48 | + |
| 49 | +**上一版本 tag 推断逻辑**(仅当未指定 `<prev-version>` 时): |
| 50 | + |
| 51 | +```bash |
| 52 | +# 获取所有已排序的 tag |
| 53 | +git tag --sort=-v:refname |
| 54 | +``` |
| 55 | + |
| 56 | +- 如果 PATCH > 0(如 `3.6.3`):查找同一 minor 系列中的前一个 tag(如 `v3.6.2`) |
| 57 | +- 如果 PATCH == 0(如 `3.6.0`):查找前一个 minor 系列的最后一个 tag(如 `v3.5.x` 中最大的) |
| 58 | + |
| 59 | +**验证 tag 存在**: |
| 60 | + |
| 61 | +```bash |
| 62 | +git rev-parse v<version> |
| 63 | +git rev-parse v<prev-version> |
| 64 | +``` |
| 65 | + |
| 66 | +如果任一 tag 不存在,报错退出:`错误:Tag v<version> 不存在,请确认 tag 已创建` |
| 67 | + |
| 68 | +### 步骤 3:收集合并的 PR |
| 69 | + |
| 70 | +**主要数据源** — 获取两个 tag 之间的日期范围,然后用 `gh` CLI 查询合并的 PR: |
| 71 | + |
| 72 | +```bash |
| 73 | +# 获取两个 tag 的日期 |
| 74 | +git log v<prev-version> --format=%aI -1 |
| 75 | +git log v<version> --format=%aI -1 |
| 76 | + |
| 77 | +# 获取目标分支(从当前版本号推断,如 3.6.x) |
| 78 | +# 分支名格式: X.Y.x |
| 79 | + |
| 80 | +# 获取合并到目标分支的 PR |
| 81 | +gh pr list --state merged --base <branch> \ |
| 82 | + --json number,title,body,author,labels,mergedAt,url \ |
| 83 | + --limit 200 --search "merged:YYYY-MM-DD..YYYY-MM-DD" |
| 84 | +``` |
| 85 | + |
| 86 | +**补充数据源** — 获取没有关联 PR 的直接 commit: |
| 87 | + |
| 88 | +```bash |
| 89 | +git log v<prev-version>..v<version> --format="%H %s" --no-merges |
| 90 | +``` |
| 91 | + |
| 92 | +对比 PR 列表和 commit 列表,找出没有关联 PR 的 commit(这些 commit 也应纳入 release notes)。 |
| 93 | + |
| 94 | +### 步骤 4:收集关联的 Issue |
| 95 | + |
| 96 | +从每个 PR 的 body 中提取关联的 Issue: |
| 97 | +- 匹配模式:`Closes #N`、`Fixes #N`、`Resolves #N`(不区分大小写) |
| 98 | +- 也匹配:`close #N`、`fix #N`、`resolve #N` 及其复数形式 |
| 99 | + |
| 100 | +对每个提取到的 Issue 编号: |
| 101 | + |
| 102 | +```bash |
| 103 | +gh issue view <N> --json number,title,labels,url |
| 104 | +``` |
| 105 | + |
| 106 | +收集 Issue 详情用于丰富 release notes 的描述。 |
| 107 | + |
| 108 | +### 步骤 5:分类 — 按模块分组 |
| 109 | + |
| 110 | +根据以下**优先级**判断每个 PR/commit 所属模块: |
| 111 | + |
| 112 | +| 优先级 | 判断依据 | 示例 | |
| 113 | +|--------|----------|------| |
| 114 | +| 1 | PR title 中的模块标签 `[fit]`, `[FEL]`, `[waterflow]` | `[fit] 修复空指针` → FIT | |
| 115 | +| 2 | Conventional commit scope `feat(fit):`, `fix(waterflow):` | `feat(waterflow): xxx` → Waterflow | |
| 116 | +| 3 | PR 变更文件路径(使用 `gh pr view <N> --json files`) | `framework/fel/**` → FEL | |
| 117 | +| 4 | 默认归入 FIT Function Platform | | |
| 118 | + |
| 119 | +**模块到平台的映射**: |
| 120 | + |
| 121 | +| 关键词 / 路径 | 平台名称 | |
| 122 | +|---------------|----------| |
| 123 | +| `fit`, `python`, `docker`, `fit-launcher`, `framework/fit/**` | **FIT Function Platform** | |
| 124 | +| `fel`, `FEL`, `framework/fel/**` | **FIT Expression for LLM** | |
| 125 | +| `waterflow`, `framework/waterflow/**` | **Waterflow Flow Scheduling Platform** | |
| 126 | +| `claude`, `.claude/`, `.ai-agents/`, AI 相关配置 | **🤖 AI Development Configuration** | |
| 127 | + |
| 128 | +### 步骤 6:分类 — 按类型分组 |
| 129 | + |
| 130 | +根据 PR title 的 conventional commit type 分类: |
| 131 | + |
| 132 | +| PR Title 前缀 / 特征 | 分类 | |
| 133 | +|----------------------|------| |
| 134 | +| `feat`, `perf`, `refactor`, `chore(deps)`, 依赖升级 | ✨ Enhancement | |
| 135 | +| `fix` | ✅ Bugfix | |
| 136 | +| `docs` | 📚 Documentation(如果条目少于 3 个,并入 Enhancement) | |
| 137 | + |
| 138 | +### 步骤 7:判断发布级别 |
| 139 | + |
| 140 | +根据变更数量和性质判断输出详细程度: |
| 141 | + |
| 142 | +- **Major release**(PATCH == 0 或合并 PR > 15 个): |
| 143 | + - 生成 `🌟 Overview` 总结段落(2-3 句话概括本次发布的核心主题) |
| 144 | + - 每个平台生成 `🚀 Features Overview` 要点列表 |
| 145 | +- **Regular release**: |
| 146 | + - 直接列出 Enhancement / Bugfix 条目,不加 Overview |
| 147 | + |
| 148 | +### 步骤 8:生成 Release Notes |
| 149 | + |
| 150 | +按照项目已有格式输出 markdown。完整模板: |
| 151 | + |
| 152 | +```markdown |
| 153 | +## FIT Function Platform |
| 154 | + |
| 155 | +### ✨ Enhancement |
| 156 | + |
| 157 | +- [fit] 描述内容 by @author1 and @author2 in [#123](url) |
| 158 | +- Upgrade xxx from v1 to v2 by @author in [#456](url) |
| 159 | + |
| 160 | +### ✅ Bugfix |
| 161 | + |
| 162 | +- [fit] 修复xxx问题 by @author in [#100](issue-url) and [#789](pr-url) |
| 163 | + |
| 164 | +## FIT Expression for LLM |
| 165 | + |
| 166 | +### ✨ Enhancement |
| 167 | + |
| 168 | +- [FEL] 描述内容 by @author in [#234](url) |
| 169 | + |
| 170 | +## Waterflow Flow Scheduling Platform |
| 171 | + |
| 172 | +### ✨ Enhancement |
| 173 | + |
| 174 | +- [waterflow] 描述内容 by @author in [#345](url) |
| 175 | + |
| 176 | +## 🤖 AI Development Configuration |
| 177 | + |
| 178 | +### ✨ Enhancement |
| 179 | + |
| 180 | +- 描述内容 by @author in [#567](url) |
| 181 | + |
| 182 | +## ❤️ Contributors |
| 183 | + |
| 184 | +@contributor1, @contributor2, @contributor3 |
| 185 | +``` |
| 186 | + |
| 187 | +**格式规则**(从现有 release notes 中提炼): |
| 188 | + |
| 189 | +1. **条目格式**: `- [module] 描述 by @author1 and @author2 in [#N](url)` |
| 190 | +2. **关联 Issue 和 PR**: `in [#Issue](issue-url) and [#PR](pr-url)` |
| 191 | +3. **没有关联 PR 的 commit**: 省略 `in [#N]` 部分,直接写描述 |
| 192 | +4. **描述内容**: 优先使用 PR title,去掉 `type(scope):` 前缀,首字母大写 |
| 193 | +5. **贡献者列表**: 去重,按贡献量(PR 数量)降序排列 |
| 194 | +6. **空平台**: 如果某个平台没有任何变更,不输出该平台的章节 |
| 195 | +7. **多作者**: 如果 PR 有多个 co-author,用 `and` 连接:`by @a and @b` |
| 196 | + |
| 197 | +### 步骤 9:展示并确认 |
| 198 | + |
| 199 | +将生成的 release notes **完整输出**给用户查看。 |
| 200 | + |
| 201 | +然后询问用户: |
| 202 | +1. 是否需要调整内容(修改描述、调整分类、增删条目等) |
| 203 | +2. 是否创建 GitHub Draft Release |
| 204 | + |
| 205 | +如果用户要求调整,根据反馈修改后重新输出。 |
| 206 | + |
| 207 | +### 步骤 10:创建 Draft Release |
| 208 | + |
| 209 | +用户确认后,将 release notes 写入临时文件,然后创建 Draft Release: |
| 210 | + |
| 211 | +```bash |
| 212 | +gh release create v<version> \ |
| 213 | + --title "v<version>" \ |
| 214 | + --notes-file /tmp/release-notes-v<version>.md \ |
| 215 | + --target <release-branch-or-tag> \ |
| 216 | + --draft |
| 217 | +``` |
| 218 | + |
| 219 | +输出结果: |
| 220 | +``` |
| 221 | +✅ Draft Release 已创建 |
| 222 | +
|
| 223 | +- Release URL: <draft-release-url> |
| 224 | +- 版本: v<version> |
| 225 | +- 状态: Draft(草稿) |
| 226 | +
|
| 227 | +⚠️ 请在 GitHub 上最终审核并发布: |
| 228 | +1. 打开上述 URL |
| 229 | +2. 检查 Release Notes 内容 |
| 230 | +3. 确认无误后点击 "Publish release" |
| 231 | +``` |
| 232 | + |
| 233 | +## 注意事项 |
| 234 | + |
| 235 | +1. **需要 `gh` CLI**:本命令依赖 GitHub CLI(`gh`),请确保已安装并认证 |
| 236 | +2. **Tag 必须已存在**:运行本命令前,确保 `v<version>` 和上一版本的 tag 已创建(通常由 `/release` 命令完成) |
| 237 | +3. **Draft 模式**:创建的是草稿 Release,不会自动发布,需要人工审核后在 GitHub 上发布 |
| 238 | +4. **PR 搜索范围**:基于日期范围搜索,可能包含少量超出范围的 PR,命令会尽力过滤 |
| 239 | +5. **模块分类准确性**:自动分类基于 title/scope/文件路径推断,复杂 PR 可能需要人工调整 |
| 240 | + |
| 241 | +## 错误处理 |
| 242 | + |
| 243 | +- **版本号格式错误**:提示正确格式并退出 |
| 244 | +- **Tag 不存在**:提示确认 tag 已创建(可能需要先执行 `/release`) |
| 245 | +- **`gh` CLI 未安装或未认证**:提示安装/认证方法 |
| 246 | +- **无合并 PR**:提示版本范围内没有找到合并的 PR,建议检查 tag 和分支 |
| 247 | +- **GitHub API 限流**:提示稍后重试 |
| 248 | + |
| 249 | +## 相关命令 |
| 250 | + |
| 251 | +- `/release <version>` - 执行版本发布流程(创建 tag 和发布分支) |
| 252 | +- `/commit` - 提交代码 |
| 253 | +- `/create-pr` - 创建 Pull Request |
0 commit comments