From 0f28d8441011459f4caf1b9b549f59d67cb0e959 Mon Sep 17 00:00:00 2001 From: wangzhizhou <824219521@qq.com> Date: Mon, 23 Nov 2026 11:54:24 +0800 Subject: [PATCH] =?UTF-8?q?ci(dependabot):=20=E5=85=A5=E9=98=9F=E6=94=B9?= =?UTF-8?q?=E7=94=A8=E3=80=8C=E9=87=8D=E8=AF=95=E5=88=B0=E5=BF=85=E9=9C=80?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E9=80=9A=E8=BF=87=E3=80=8D=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=20#207=20=E7=9A=84=E8=87=AA=E9=94=81=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #207 用 `mergeStateStatus == CLEAN` 判断“检查跑完”,但**本 job 自身也是一个 check** (job 名 `dependabot`):只要它还在轮询,状态就永远不是 CLEAN —— 实测 #205 / #206 的 唯一 pending 检查正是 `dependabot` 自己,等于等到超时才告警,PR 依旧不合入。 改为不猜状态,直接反复调 `enqueuePullRequest`,由 GitHub 用它自己的必需检查清单裁决: - 成功 → 打印队列位置并退出; - `required status checks have not succeeded` / `not mergeable` / `still in progress` → 45s 后重试,最多 40 次(30 分钟); - `is closed` / `already in the merge queue` → 无需处理; - 其它错误 → `::warning::` 带上原文退出,不静默。 这样既避开了自锁死,也不依赖对 mergeStateStatus 语义的猜测。 --- .github/workflows/dependabot-auto-merge.yml | 44 ++++++++++----------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml index 46549bb..e49aa48 100644 --- a/.github/workflows/dependabot-auto-merge.yml +++ b/.github/workflows/dependabot-auto-merge.yml @@ -37,7 +37,7 @@ jobs: # `UNPROCESSABLE: Pull request 13 of 14 required status checks have not # succeeded` 拒绝(2026-11 实测 #205 / #206)—— 因此这里必须**等检查跑完再入队**, # 否则会退化成和 `--auto` 一样的“永不合并”。 - - name: Wait for required checks, then enqueue into the merge queue + - name: Enqueue into the merge queue (retry until required checks pass) if: | github.event.pull_request.state == 'open' && !github.event.pull_request.draft && @@ -50,29 +50,25 @@ jobs: run: | set -uo pipefail - # CLEAN = 与 base 同步且必需检查全过;BLOCKED/UNKNOWN = 检查仍在跑; - # BEHIND = base 前进后需要 dependabot 重新 rebase(继续等)。 + # 不用 mergeStateStatus 当判据:本 job 自身也是一个 check,等它变成 CLEAN 会 + # **自锁死**(2026-11 实测 #205 / #206:唯一 pending 的检查就是 `dependabot` 自己)。 + # 改成反复调 enqueue,由 GitHub 用它自己的必需检查清单给结论:未就绪时返回 + # `required status checks have not succeeded`,就绪即入队。 for i in $(seq 1 40); do - state=$(gh pr view "$PR_URL" --json mergeStateStatus --jq .mergeStateStatus 2>/dev/null || echo UNKNOWN) - case "$state" in - CLEAN) echo "必需检查已全部通过(第 $i 次轮询),开始入队"; break ;; - DIRTY) - echo "::warning::$PR_URL 存在冲突,跳过自动入队,需人工处理" - exit 0 - ;; - *) echo "第 $i/40 次:mergeStateStatus=$state,等待必需检查…"; sleep 45 ;; + if out=$(gh api graphql \ + -f query='mutation($id: ID!) { enqueuePullRequest(input: {pullRequestId: $id}) { mergeQueueEntry { position state } } }' \ + -f id="$PR_ID" 2>&1); then + echo "已加入 merge queue(第 $i 次尝试):$out" + exit 0 + fi + case "$out" in + *"required status checks have not succeeded"*|*"not mergeable"*|*"still in progress"*) + echo "第 $i/40 次:必需检查尚未全部通过,45s 后重试" ;; + *"is closed"*|*"already in the merge queue"*|*"already queued"*) + echo "无需入队:$out"; exit 0 ;; + *) + echo "::warning::enqueue 失败,交人工处理:$out"; exit 0 ;; esac + sleep 45 done - - if [ "${state:-}" != "CLEAN" ]; then - echo "::warning::等待 30 分钟后仍未通过必需检查(最后状态 $state),请人工检查后再入队:$PR_URL" - exit 0 - fi - - if out=$(gh api graphql \ - -f query='mutation($id: ID!) { enqueuePullRequest(input: {pullRequestId: $id}) { mergeQueueEntry { position state } } }' \ - -f id="$PR_ID" 2>&1); then - echo "已加入 merge queue:$out" - else - echo "::warning::enqueue 未成功(可能已在队列中或检查刚失效),请人工确认:$out" - fi + echo "::warning::等待 30 分钟后仍未入队,请人工检查:$PR_URL"