open-issue.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/env bash
  2. # 创建自动升级失败 Issue(同版本去重:已存在相同标题的 open Issue 则跳过)
  3. #
  4. # Create an Issue for a failed auto-upgrade (dedup: skip when an open Issue with the same title exists)
  5. # Usage: open-issue.sh <latest> <current>
  6. #
  7. # 测试注入:设置 GH=/path/to/mock 可替换 gh 命令(用于单测)
  8. #
  9. # Test injection: set GH=/path/to/mock to substitute the gh command (used by unit tests)
  10. #
  11. # GitHub Actions 兜底:在 CI 环境中 gh 默认从 GH_TOKEN 取凭据;若调用方未显式设置
  12. # (早期版本漏配),自动回退到 GITHUB_TOKEN。这是双层防御:GH_TOKEN 优先,未设置则用 GITHUB_TOKEN,
  13. # 调用方仍可显式传 GH_TOKEN 覆盖(例如指向 PAT)
  14. #
  15. # GitHub Actions fallback: gh reads GH_TOKEN for credentials by default. If a caller forgets
  16. # to set it (an earlier workflow did), fall back to GITHUB_TOKEN. Belt-and-suspenders:
  17. # GH_TOKEN wins when set; otherwise GITHUB_TOKEN is used; callers can still pin GH_TOKEN
  18. # explicitly (e.g. to a PAT)
  19. set -euo pipefail
  20. LATEST="$1"
  21. CURRENT="$2"
  22. GH_BIN="${GH:-gh}"
  23. GH_TOKEN="${GH_TOKEN:-${GITHUB_TOKEN:-}}"
  24. export GH_TOKEN
  25. TITLE="[自动升级] dsh 上游 $LATEST 升级流程失败"
  26. EXISTING="$("$GH_BIN" issue list --state open --search "in:title \"$TITLE\"" --json number -q '.[0].number' 2>/dev/null || true)"
  27. if [ -n "$EXISTING" ]; then
  28. echo "已存在同版本 Issue #$EXISTING,跳过创建"
  29. exit 0
  30. fi
  31. "$GH_BIN" issue create --title "$TITLE" --body "$(cat <<EOF
  32. ## 自动升级失败 | Auto-upgrade failed
  33. - 上游版本 (upstream): \`$LATEST\`
  34. - 仓库当前版本 (repo current): \`$CURRENT\`
  35. - 检测时间 (detected at): \`$(date -u +%FT%TZ)\`
  36. - 运行日志 (run log): ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
  37. 升级脚本已将 \`DSH_VERSION\` 提升至 \`$LATEST\` 并执行构建与冒烟测试,但升级流程(冒烟测试或 PR 推送)未通过,代码**未进入** master。
  38. The upgrade script bumped \`DSH_VERSION\` to \`$LATEST\` and ran build & smoke tests, but the upgrade flow (smoke test or PR push) failed; the change did **not** reach master.
  39. 请人工排查:上游版本是否可安装、容器是否可正常启动,修复后手动升级或等待下次定时检查。
  40. Please investigate: whether the upstream version installs and the container starts; fix it, then upgrade manually or wait for the next scheduled check.
  41. EOF
  42. )"
  43. echo "已创建 Issue"