upstream-check.yml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. # 定时检查 dsh 上游版本:有新版本 → 提升版本号 → 构建冒烟测试 → 通过则推送常驻 PR 分支
  2. # auto-upgrade/dsh 并创建/更新唯一 PR(成员批准合并),失败则创建 Issue
  3. # 成员合并 PR 产生的 push 事件会自动触发 docker-build.yml 发布 GHCR 镜像,形成「升级 → 批准 → 发布」闭环
  4. # 注意:bot 用 GITHUB_TOKEN 创建的 PR 不会触发 docker-build.yml 的 pull_request 事件(GitHub 递归保护),
  5. # 属预期行为——冒烟测试已在升级流程内完成;成员合并的 push 会正常触发 CI
  6. #
  7. # Scheduled dsh upstream check: bump version on update → build & smoke test → push the standing PR
  8. # branch auto-upgrade/dsh and create/update the single PR (merged by a member approver), open an
  9. # Issue on failure
  10. # A member's merge push fires docker-build.yml automatically to publish GHCR images — an
  11. # "upgrade → approval → release" loop
  12. # Note: a PR created by the bot's GITHUB_TOKEN does NOT fire docker-build.yml's pull_request event
  13. # (GitHub recursion protection); this is expected — the smoke test already ran inside the
  14. # upgrade flow. A member's merge push triggers CI normally
  15. name: check-dsh-upstream
  16. on:
  17. schedule:
  18. # 每日 UTC 03:00(北京时间 11:00)
  19. #
  20. # Daily 03:00 UTC (11:00 Beijing time)
  21. - cron: "0 3 * * *"
  22. workflow_dispatch:
  23. permissions:
  24. contents: read
  25. concurrency:
  26. group: check-dsh-upstream
  27. cancel-in-progress: false
  28. jobs:
  29. check:
  30. runs-on: ubuntu-latest
  31. permissions:
  32. contents: read
  33. issues: read
  34. pull-requests: read
  35. outputs:
  36. current: ${{ steps.check.outputs.current }}
  37. latest: ${{ steps.check.outputs.latest }}
  38. should_upgrade: ${{ steps.check.outputs.should_upgrade }}
  39. blocked: ${{ steps.gate.outputs.blocked }}
  40. blocked_pr: ${{ steps.gate-pr.outputs.blocked_pr }}
  41. steps:
  42. - uses: actions/checkout@v4
  43. - name: 查询上游版本并比较
  44. id: check
  45. run: |
  46. scripts/check-upstream.sh | tee -a "$GITHUB_OUTPUT"
  47. # 门闩:同版本已有未关闭的失败 Issue 时跳过自动升级(npm 包版本不可变,重试必失败)
  48. # 仅定时触发生效;手动触发(workflow_dispatch)绕过,用于人工重试环境性失败
  49. #
  50. # Gate: skip auto-upgrade when an open failure Issue exists for this version (npm versions are immutable, retry is doomed)
  51. # Only applies to schedule runs; manual dispatch bypasses it for human-driven retries
  52. - name: 门闩检查:同版本失败 Issue
  53. id: gate
  54. if: steps.check.outputs.should_upgrade == 'true' && github.event_name == 'schedule'
  55. run: |
  56. BLOCKED="$(scripts/check-issue-gate.sh "$LATEST")"
  57. if [ "$BLOCKED" = "1" ]; then
  58. BOOL=true
  59. echo "存在 $LATEST 的未关闭失败 Issue,跳过本次自动升级(可手动触发强制重试)"
  60. else
  61. BOOL=false
  62. fi
  63. # 布尔字符串输出:upgrade job 的 if 按 'true'/'false' 比较(此前输出 1/0 使门闩恒不拦截)
  64. #
  65. # Boolean string output: the upgrade job's if compares against 'true'/'false'
  66. # (previously emitting 1/0 made the gate never block)
  67. echo "blocked=$BOOL" >> "$GITHUB_OUTPUT"
  68. env:
  69. LATEST: ${{ steps.check.outputs.latest }}
  70. # GH_TOKEN 显式透传:gh 在 Actions 中需要凭据(脚本内亦有 GITHUB_TOKEN 兜底,双层防御)
  71. #
  72. # Pass GH_TOKEN explicitly: gh needs credentials in Actions
  73. # (the script also falls back to GITHUB_TOKEN, belt-and-suspenders)
  74. GH_TOKEN: ${{ github.token }}
  75. # 门闩:auto-upgrade/dsh 分支上已有同版本 open PR 时跳过(避免每日重复推送同版本提交)
  76. # 仅定时触发生效;手动触发(workflow_dispatch)绕过,用于人工强制刷新 PR
  77. #
  78. # Gate: skip when an open PR for this version already exists on auto-upgrade/dsh
  79. # (avoid re-pushing the same version every day); manual dispatch bypasses it to force-refresh the PR
  80. - name: 门闩检查:自动升级 PR
  81. id: gate-pr
  82. if: steps.check.outputs.should_upgrade == 'true' && github.event_name == 'schedule'
  83. run: |
  84. BLOCKED="$(scripts/check-pr-gate.sh "$LATEST")"
  85. if [ "$BLOCKED" = "1" ]; then
  86. BOOL=true
  87. echo "auto-upgrade/dsh 已有 $LATEST 的 open PR,跳过本次自动升级(可手动触发强制刷新)"
  88. else
  89. BOOL=false
  90. fi
  91. # 布尔字符串输出:upgrade job 的 if 按 'true'/'false' 比较(与 issue 门闩同约定)
  92. #
  93. # Boolean string output: the upgrade job's if compares against 'true'/'false'
  94. # (same convention as the Issue gate)
  95. echo "blocked_pr=$BOOL" >> "$GITHUB_OUTPUT"
  96. env:
  97. LATEST: ${{ steps.check.outputs.latest }}
  98. # GH_TOKEN 显式透传:gh 在 Actions 中需要凭据(脚本内亦有 GITHUB_TOKEN 兜底,双层防御)
  99. #
  100. # Pass GH_TOKEN explicitly: gh needs credentials in Actions
  101. # (the script also falls back to GITHUB_TOKEN, belt-and-suspenders)
  102. GH_TOKEN: ${{ github.token }}
  103. - name: 打印检查结果
  104. run: |
  105. echo "当前版本 (current): ${{ steps.check.outputs.current }}"
  106. echo "上游最新 (latest): ${{ steps.check.outputs.latest }}"
  107. echo "需要升级 (upgrade): ${{ steps.check.outputs.should_upgrade }}"
  108. echo "被 Issue 门闩拦截 (blocked): ${{ steps.gate.outputs.blocked }}"
  109. echo "被 PR 门闩拦截 (blocked_pr): ${{ steps.gate-pr.outputs.blocked_pr }}"
  110. upgrade:
  111. needs: check
  112. if: needs.check.outputs.should_upgrade == 'true' && needs.check.outputs.blocked != 'true' && needs.check.outputs.blocked_pr != 'true'
  113. runs-on: ubuntu-latest
  114. permissions:
  115. contents: write
  116. issues: write
  117. pull-requests: write
  118. steps:
  119. # fetch-depth: 0(完整历史):prepare 需合并远端 PR 分支,浅克隆(默认 depth=1)缺少共同祖先,
  120. # merge 会报 "refusing to merge unrelated histories"
  121. #
  122. # fetch-depth: 0 (full history): prepare merges the remote PR branch and needs the common
  123. # ancestor; a shallow clone (default depth=1) fails the merge with
  124. # "refusing to merge unrelated histories"
  125. - uses: actions/checkout@v4
  126. with:
  127. fetch-depth: 0
  128. # 在版本提升前准备 PR 分支:分支不存在则从 master 新建;存在则合并 master 最新内容,
  129. # 保证后续 push 为 fast-forward(ruleset 禁 force push;若先 bump 再切分支,bump 结果会被覆盖)
  130. #
  131. # Prep the PR branch BEFORE the version bump: create it from master, or merge master's latest,
  132. # so the later push is fast-forward (the ruleset forbids force pushes; switching branches after
  133. # the bump would clobber it)
  134. - name: 准备 PR 分支
  135. run: |
  136. scripts/push-upgrade-pr.sh prepare
  137. - name: 提升版本号(Dockerfile / compose / README 双语)
  138. run: |
  139. scripts/upgrade-dsh.sh "$LATEST"
  140. env:
  141. LATEST: ${{ needs.check.outputs.latest }}
  142. - name: 构建镜像并冒烟测试
  143. id: smoke
  144. run: |
  145. scripts/smoke-test.sh "$LATEST"
  146. env:
  147. LATEST: ${{ needs.check.outputs.latest }}
  148. # 提交升级、推送常驻 PR 分支并创建/更新唯一 PR(成员批准合并后,
  149. # 合并 push 自动触发 docker-build.yml 发布 GHCR,无需显式 dispatch)
  150. #
  151. # Commit the upgrade, push the standing PR branch, and create/update the single PR
  152. # (after a member approves and merges, the merge push fires docker-build.yml automatically;
  153. # no explicit dispatch is needed)
  154. - name: 推送升级分支并创建/更新 PR
  155. run: |
  156. scripts/push-upgrade-pr.sh push "$LATEST" "$CURRENT"
  157. env:
  158. LATEST: ${{ needs.check.outputs.latest }}
  159. CURRENT: ${{ needs.check.outputs.current }}
  160. # GH_TOKEN 显式透传:gh pr 需要凭据(脚本内亦有 GITHUB_TOKEN 兜底,这是双层防御)
  161. #
  162. # Pass GH_TOKEN explicitly: gh pr needs credentials (the script also falls back to
  163. # GITHUB_TOKEN, so this is belt-and-suspenders)
  164. GH_TOKEN: ${{ github.token }}
  165. # 升级已提交为 PR:旧版本的失败 Issue 均已过时,关闭以免陈旧累积
  166. # continue-on-error:清理失败不影响升级结果(不触发下方 failure() 步骤)
  167. #
  168. # The upgrade is now a PR: failure Issues for older versions are stale; close them to avoid accumulation
  169. # continue-on-error: cleanup failure must not fail the upgrade (must not trigger the failure() step below)
  170. - name: 关闭过时的失败 Issue
  171. continue-on-error: true
  172. run: |
  173. scripts/close-stale-issues.sh
  174. env:
  175. LATEST: ${{ needs.check.outputs.latest }}
  176. # GH_TOKEN 显式透传:gh 在 Actions 中需要凭据(脚本内亦有 GITHUB_TOKEN 兜底,双层防御)
  177. #
  178. # Pass GH_TOKEN explicitly: gh needs credentials in Actions
  179. # (the script also falls back to GITHUB_TOKEN, belt-and-suspenders)
  180. GH_TOKEN: ${{ github.token }}
  181. - name: 失败时创建 Issue(同版本去重)
  182. if: failure()
  183. run: |
  184. scripts/open-issue.sh "$LATEST" "$CURRENT"
  185. env:
  186. LATEST: ${{ needs.check.outputs.latest }}
  187. CURRENT: ${{ needs.check.outputs.current }}
  188. # GH_TOKEN 显式透传:避免 gh 因无凭据报错(open-issue.sh 内部亦有 GITHUB_TOKEN 兜底,这是双层防御)
  189. #
  190. # Pass GH_TOKEN explicitly: prevents gh from failing for lack of credentials.
  191. # open-issue.sh also falls back to GITHUB_TOKEN, so this is belt-and-suspenders
  192. GH_TOKEN: ${{ github.token }}