claude-unified-docs.yml 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. name: Claude Unified Documentation
  2. on:
  3. # 当推送新 tag 时触发(更可靠)
  4. push:
  5. tags:
  6. - "v*"
  7. # 允许手动触发(用于重新生成文档)
  8. workflow_dispatch:
  9. inputs:
  10. tag_name:
  11. description: "Release tag name (e.g., v0.3.17)"
  12. required: true
  13. type: string
  14. concurrency:
  15. group: unified-docs-${{ github.ref_name || github.event.inputs.tag_name }}
  16. cancel-in-progress: true
  17. jobs:
  18. unified-documentation:
  19. runs-on: ubuntu-latest
  20. permissions:
  21. contents: write
  22. steps:
  23. - name: Checkout repository
  24. uses: actions/checkout@v5
  25. with:
  26. fetch-depth: 0
  27. token: ${{ secrets.GITHUB_TOKEN || secrets.GH_PAT }}
  28. - name: Determine release tag
  29. id: release_info
  30. run: |
  31. # 从 tag push 事件或手动输入获取 tag
  32. if [ -n "${{ github.event.inputs.tag_name }}" ]; then
  33. TAG="${{ github.event.inputs.tag_name }}"
  34. else
  35. # 从 refs/tags/v1.0.0 中提取 tag 名称
  36. TAG="${GITHUB_REF#refs/tags/}"
  37. fi
  38. echo "tag=$TAG" >> $GITHUB_OUTPUT
  39. echo "date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT
  40. # 获取上一个 tag
  41. PREV_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "^$TAG$" | head -n 1)
  42. if [ -z "$PREV_TAG" ]; then
  43. PREV_TAG=$(git rev-list --max-parents=0 HEAD | head -n 1)
  44. fi
  45. echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT
  46. echo "Current tag: $TAG"
  47. echo "Previous tag: $PREV_TAG"
  48. - name: Gather release context
  49. id: context
  50. run: |
  51. TAG="${{ steps.release_info.outputs.tag }}"
  52. PREV_TAG="${{ steps.release_info.outputs.prev_tag }}"
  53. # 获取 commits
  54. echo "Gathering commits from $PREV_TAG to $TAG..."
  55. COMMITS=$(git log $PREV_TAG..$TAG --pretty=format:"- %s (%h) by @%an" 2>/dev/null || echo "Initial release")
  56. echo "commits<<EOF" >> $GITHUB_OUTPUT
  57. echo "$COMMITS" >> $GITHUB_OUTPUT
  58. echo "EOF" >> $GITHUB_OUTPUT
  59. # 获取 diff 摘要(限制大小以避免 token 超限)
  60. echo "Gathering diff summary..."
  61. DIFF_STAT=$(git diff $PREV_TAG..$TAG --stat 2>/dev/null | tail -50 || echo "No diff available")
  62. echo "diff_stat<<EOF" >> $GITHUB_OUTPUT
  63. echo "$DIFF_STAT" >> $GITHUB_OUTPUT
  64. echo "EOF" >> $GITHUB_OUTPUT
  65. # 获取变更的文件列表
  66. CHANGED_FILES=$(git diff $PREV_TAG..$TAG --name-only 2>/dev/null | head -100 || echo "")
  67. echo "changed_files<<EOF" >> $GITHUB_OUTPUT
  68. echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
  69. echo "EOF" >> $GITHUB_OUTPUT
  70. - name: Run Claude Code for Unified Docs Update
  71. uses: anthropics/claude-code-action@v1
  72. env:
  73. ANTHROPIC_BASE_URL: ${{ secrets.ANTHROPIC_BASE_URL }}
  74. with:
  75. anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
  76. github_token: ${{ secrets.GITHUB_TOKEN || secrets.GH_PAT }}
  77. prompt: |
  78. 你是 Claude Code Hub 项目的发布文档专家。请执行完整的文档更新流程。
  79. ## 发布信息
  80. - **当前版本**: ${{ steps.release_info.outputs.tag }}
  81. - **上一版本**: ${{ steps.release_info.outputs.prev_tag }}
  82. - **发布日期**: ${{ steps.release_info.outputs.date }}
  83. ## Commits 列表
  84. ${{ steps.context.outputs.commits }}
  85. ## 变更的文件
  86. ${{ steps.context.outputs.changed_files }}
  87. ## Diff 统计
  88. ${{ steps.context.outputs.diff_stat }}
  89. ---
  90. ## 任务
  91. 请按以下步骤执行文档更新:
  92. ### Phase 1: 分析变更
  93. 1. 首先阅读 `.github/prompts/release-analysis.md` 了解分析要求
  94. 2. 仔细分析上述 commits 和变更文件
  95. 3. 如有需要,可以读取具体的源代码文件来理解变更
  96. 4. 生成结构化的变更报告(在心中记录,用于后续步骤)
  97. 变更分类标准:
  98. - **新增**: 新功能、新 API、新配置项
  99. - **优化**: 性能改进、体验改进、功能增强
  100. - **修复**: Bug 修复
  101. - **其他**: 文档、构建、重构、依赖更新
  102. ### Phase 2: 更新文档
  103. #### 2.1 更新 CHANGELOG.md
  104. 1. 读取当前 CHANGELOG.md 文件
  105. 2. 在文件顶部(标题后)插入新版本条目
  106. 3. 使用以下格式:
  107. ```markdown
  108. ## ${{ steps.release_info.outputs.tag }} (${{ steps.release_info.outputs.date }})
  109. ### 新增
  110. - 功能描述 (#PR编号)
  111. ### 优化
  112. - 优化描述 (#PR编号) [@贡献者]
  113. ### 修复
  114. - 修复描述 (#PR编号)
  115. ### 其他
  116. - 其他变更描述
  117. ---
  118. ```
  119. 4. 如果某个分类没有内容,跳过该分类
  120. 5. 保存更新后的 CHANGELOG.md
  121. #### 2.2 更新 GitHub Release Notes
  122. 1. 读取 `.github/prompts/release-notes.md` 了解格式要求
  123. 2. 生成专业的 Release Notes 内容,包含:
  124. - 版本摘要
  125. - 亮点功能(如有重要变更)
  126. - 分类的变更列表
  127. - 破坏性变更说明(如有)
  128. - 贡献者致谢(如有外部贡献者)
  129. 3. 检查 Release 是否存在并更新:
  130. ```bash
  131. # 检查 release 是否存在
  132. if gh release view ${{ steps.release_info.outputs.tag }} >/dev/null 2>&1; then
  133. # Release 存在,更新 notes
  134. gh release edit ${{ steps.release_info.outputs.tag }} --notes "生成的内容"
  135. else
  136. # Release 不存在(可能只是 tag),创建 draft release
  137. gh release create ${{ steps.release_info.outputs.tag }} --draft --title "${{ steps.release_info.outputs.tag }}" --notes "生成的内容"
  138. fi
  139. ```
  140. ### Phase 3: 提交变更
  141. 1. 配置 git:
  142. ```bash
  143. git config user.name "github-actions[bot]"
  144. git config user.email "github-actions[bot]@users.noreply.github.com"
  145. ```
  146. 2. 提交 CHANGELOG.md 变更:
  147. ```bash
  148. git add CHANGELOG.md
  149. git commit -m "docs: update changelog for ${{ steps.release_info.outputs.tag }} [skip ci]"
  150. git push origin HEAD:main
  151. ```
  152. ## 重要提示
  153. - 使用中文分类标题(新增/优化/修复/其他)
  154. - 描述要简洁但完整,面向用户
  155. - 确保所有文件更新后再提交
  156. - 如果某个步骤失败,继续执行其他步骤
  157. claude_args: |
  158. --model claude-opus-4-6
  159. --max-turns 999
  160. --allowedTools Read,Write,Edit,Bash(*)
  161. use_commit_signing: false