check-issue-gate.sh 1.3 KB

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. # 门闩检查:是否存在针对指定版本的未关闭「自动升级」失败 Issue
  3. # 输出:1(存在,应跳过自动升级)/ 0(无,可继续)
  4. #
  5. # Gate check: whether an open auto-upgrade failure Issue exists for the given version
  6. # Output: 1 (exists, skip the auto-upgrade) / 0 (none, proceed)
  7. # Usage: check-issue-gate.sh <version>
  8. #
  9. # 测试注入:设置 GH=/path/to/mock 可替换 gh 命令(用于单测)
  10. #
  11. # Test injection: set GH=/path/to/mock to substitute the gh command (used by unit tests)
  12. set -euo pipefail
  13. VERSION="$1"
  14. GH_BIN="${GH:-gh}"
  15. # 列出未关闭的自动升级失败 Issue,标题含目标版本即命中
  16. # simp: gh 仅输出 JSON,匹配交给 jq(mock 易仿真);查询上限 50 条,按版本去重后远不会触及
  17. #
  18. # List open auto-upgrade failure Issues; a title containing the target version is a hit
  19. # simp: gh only outputs JSON, matching is delegated to jq (easy to mock); cap of 50 is far above the deduped per-version count
  20. JSON="$("$GH_BIN" issue list --state open --search 'in:title "[自动升级]"' --json title,number --limit 50 2>/dev/null || true)"
  21. [ -n "$JSON" ] || { echo 0; exit 0; }
  22. MATCH="$(jq -r '.[] | select(.title | contains("'"$VERSION"'")) | .number' <<<"$JSON" | head -n1)"
  23. [ -n "$MATCH" ] && echo 1 || echo 0