upstream-check.yml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. # 定时检查 dsh 上游版本:有新版本 → 提升版本号 → 构建冒烟测试 → 通过则推送 master,失败则创建 Issue
  2. # 推送后显式触发 docker-build.yml 发布 GHCR 镜像,形成「升级 → 发布」闭环
  3. # 注意:bot 用 GITHUB_TOKEN 推送的提交不会触发 docker-build.yml 的 push 事件(GitHub 递归保护),
  4. # 因此发布必须通过 workflow_dispatch API 显式钩住(该事件是 GITHUB_TOKEN 的例外,总是创建 run)
  5. #
  6. # Scheduled dsh upstream check: bump version on update → build & smoke test → push master on success, open an Issue on failure
  7. # After pushing, explicitly dispatch docker-build.yml to publish GHCR images — an "upgrade → release" loop
  8. # Note: commits pushed by the bot's GITHUB_TOKEN do NOT fire docker-build.yml's push event (GitHub
  9. # recursion protection), so the release must be hooked explicitly via the workflow_dispatch
  10. # API (the GITHUB_TOKEN exception that always creates a run)
  11. name: check-dsh-upstream
  12. on:
  13. schedule:
  14. # 每日 UTC 03:00(北京时间 11:00)
  15. #
  16. # Daily 03:00 UTC (11:00 Beijing time)
  17. - cron: "0 3 * * *"
  18. workflow_dispatch:
  19. permissions:
  20. contents: read
  21. concurrency:
  22. group: check-dsh-upstream
  23. cancel-in-progress: false
  24. jobs:
  25. check:
  26. runs-on: ubuntu-latest
  27. permissions:
  28. contents: read
  29. issues: read
  30. outputs:
  31. current: ${{ steps.check.outputs.current }}
  32. latest: ${{ steps.check.outputs.latest }}
  33. should_upgrade: ${{ steps.check.outputs.should_upgrade }}
  34. blocked: ${{ steps.gate.outputs.blocked }}
  35. steps:
  36. - uses: actions/checkout@v4
  37. - name: 查询上游版本并比较
  38. id: check
  39. run: |
  40. scripts/check-upstream.sh | tee -a "$GITHUB_OUTPUT"
  41. # 门闩:同版本已有未关闭的失败 Issue 时跳过自动升级(npm 包版本不可变,重试必失败)
  42. # 仅定时触发生效;手动触发(workflow_dispatch)绕过,用于人工重试环境性失败
  43. #
  44. # Gate: skip auto-upgrade when an open failure Issue exists for this version (npm versions are immutable, retry is doomed)
  45. # Only applies to schedule runs; manual dispatch bypasses it for human-driven retries
  46. - name: 门闩检查:同版本失败 Issue
  47. id: gate
  48. if: steps.check.outputs.should_upgrade == 'true' && github.event_name == 'schedule'
  49. run: |
  50. BLOCKED="$(scripts/check-issue-gate.sh "$LATEST")"
  51. if [ "$BLOCKED" = "1" ]; then
  52. BOOL=true
  53. echo "存在 $LATEST 的未关闭失败 Issue,跳过本次自动升级(可手动触发强制重试)"
  54. else
  55. BOOL=false
  56. fi
  57. # 布尔字符串输出:upgrade job 的 if 按 'true'/'false' 比较(此前输出 1/0 使门闩恒不拦截)
  58. #
  59. # Boolean string output: the upgrade job's if compares against 'true'/'false'
  60. # (previously emitting 1/0 made the gate never block)
  61. echo "blocked=$BOOL" >> "$GITHUB_OUTPUT"
  62. env:
  63. LATEST: ${{ steps.check.outputs.latest }}
  64. - name: 打印检查结果
  65. run: |
  66. echo "当前版本 (current): ${{ steps.check.outputs.current }}"
  67. echo "上游最新 (latest): ${{ steps.check.outputs.latest }}"
  68. echo "需要升级 (upgrade): ${{ steps.check.outputs.should_upgrade }}"
  69. echo "被门闩拦截 (blocked): ${{ steps.gate.outputs.blocked }}"
  70. upgrade:
  71. needs: check
  72. if: needs.check.outputs.should_upgrade == 'true' && needs.check.outputs.blocked != 'true'
  73. runs-on: ubuntu-latest
  74. permissions:
  75. contents: write
  76. issues: write
  77. actions: write
  78. steps:
  79. - uses: actions/checkout@v4
  80. - name: 提升版本号(Dockerfile / compose / README 双语)
  81. run: |
  82. scripts/upgrade-dsh.sh "$LATEST"
  83. env:
  84. LATEST: ${{ needs.check.outputs.latest }}
  85. - name: 构建镜像并冒烟测试
  86. id: smoke
  87. run: |
  88. scripts/smoke-test.sh "$LATEST"
  89. env:
  90. LATEST: ${{ needs.check.outputs.latest }}
  91. - name: 推送升级至 master
  92. run: |
  93. git config user.name "github-actions[bot]"
  94. git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
  95. git add Dockerfile docker-compose.yml README.md README.zh.md
  96. git commit -m "【维护,构建】升级 dsh 版本至 $LATEST"
  97. git push origin master
  98. env:
  99. LATEST: ${{ needs.check.outputs.latest }}
  100. # 钩住 GHCR 发布(见文件头注释)。continue-on-error:升级推送已成功,触发失败不应把 job
  101. # 标记失败——否则 failure() 会误建「构建冒烟测试失败」Issue;触发失败可在日志中排查或手动触发
  102. #
  103. # Hook the GHCR release (see the file header). continue-on-error: the upgrade push already
  104. # succeeded, so a dispatch failure must not fail the job—otherwise failure() would falsely
  105. # open a "smoke test failed" Issue; a failed dispatch can be investigated in the log or
  106. # triggered manually
  107. - name: 触发 GHCR 发布(docker-build.yml)
  108. continue-on-error: true
  109. run: |
  110. gh workflow run docker-build.yml --ref master
  111. env:
  112. GH_TOKEN: ${{ github.token }}
  113. # 升级已成功:旧版本的失败 Issue 均已过时,关闭以免陈旧累积
  114. # continue-on-error:清理失败不影响升级结果(不触发下方 failure() 步骤)
  115. #
  116. # The upgrade succeeded: failure Issues for older versions are stale; close them to avoid accumulation
  117. # continue-on-error: cleanup failure must not fail the upgrade (must not trigger the failure() step below)
  118. - name: 关闭过时的失败 Issue
  119. continue-on-error: true
  120. run: |
  121. scripts/close-stale-issues.sh
  122. env:
  123. LATEST: ${{ needs.check.outputs.latest }}
  124. - name: 失败时创建 Issue(同版本去重)
  125. if: failure()
  126. run: |
  127. scripts/open-issue.sh "$LATEST" "$CURRENT"
  128. env:
  129. LATEST: ${{ needs.check.outputs.latest }}
  130. CURRENT: ${{ needs.check.outputs.current }}
  131. # GH_TOKEN 显式透传:与「触发 GHCR 发布」对齐,避免 gh 因无凭据报错
  132. # (open-issue.sh 内部亦有 GITHUB_TOKEN 兜底,这是双层防御)
  133. #
  134. # Pass GH_TOKEN explicitly: matches the "Hook GHCR release" step; prevents gh from
  135. # failing for lack of credentials. open-issue.sh also falls back to GITHUB_TOKEN,
  136. # so this is belt-and-suspenders
  137. GH_TOKEN: ${{ github.token }}