Skip to content

ci: 依赖合并遇到头提交竞态时跳过,不再染红整轮 - #15

Merged
laincat merged 1 commit into
mainfrom
fix/dependabot-merge-race
Nov 4, 2026
Merged

laincat merged 1 commit into
mainfrom
fix/dependabot-merge-race

Conversation

@laincat

@laincat laincat commented Nov 4, 2026

Copy link
Copy Markdown
Owner

现象

2026-11-02T01:14:51Z 的「Dependabot validated merge」在 PR #14 上失败:

subprocess.CalledProcessError: Command '['gh', 'pr', 'merge', '14', '--repo',
laincat/AwesomePyKit', '--squash', '--delete-branch',
'--match-head-commit', '97638aa1ab74a77482f9182fe5b76680c054136d']'
returned non-zero exit status 1

原因

.github/scripts/dependabot_merge.py 先按 head sha 校验 check-runs 和 commit status,再用
--match-head-commit 执行 gh pr merge。这中间 Dependabot 又推了新提交
(01:16:55Z → d00fb666),头提交不再匹配,gh 直接拒绝,check=True 让整轮门禁变红。

下一次调度(01:19:27Z)已经用新 sha 正常合掉了同一个 PR,所以这是纯粹的竞态,不是策略漏洞。

改动

  • gh pr merge 包进 try/except subprocess.CalledProcessError:失败时打印
    PR #N: merge skipped: <最后一行 stderr> 并 continue 处理下一个 PR,交给下一次调度重新校验
  • 合并成功后的 workflow_dispatch(post-merge build、release)保持 check=True —— 那一步失败是真问题,不能吞
  • 新增回归测试 test_merge_race_is_skipped_not_fatal:合并调用抛 CalledProcessError 时不抛异常、也不再触发后续 dispatch

验证

  • python -m unittest test_dependabot_merge:全部通过(含新增用例)
  • ruff check:通过

注:Rules / AltStore / GeoIP / wbtray / oxidns 里的同名脚本是不同分支的副本,同样没有这层保护。需要的话我可以一起同步。

2026-11-02 的「Dependabot validated merge」在 PR #14 上失败:

  CalledProcessError: Command '['gh', 'pr', 'merge', '14', '--repo',
  laincat/AwesomePyKit', '--squash', '--delete-branch',
  '--match-head-commit', '97638aa...']' returned non-zero exit status 1

脚本先按 sha 校验检查项,再执行带 --match-head-commit 的合并;这中间
Dependabot 又推了新提交(01:16:55 → d00fb66),头提交不再匹配,gh 拒绝
合并,check=True 直接把整轮门禁判红。下一次调度(01:19:27)已经正常合掉
同一个 PR,说明只是竞态。

改动:
- gh pr merge 包在 try/except 里:失败时打印 "PR #N: merge skipped: ..." 并
  继续下一个 PR,让下一次调度重新校验;
- 合并成功后触发 post-merge / release 的 workflow_dispatch 仍然 check=True,
  那一步失败是真问题,不能吞;
- 补一条回归测试:合并调用抛 CalledProcessError 时不抛异常、也不触发后续
  dispatch。

验证:python -m unittest test_dependabot_merge(含新增用例)通过;
ruff check 通过。
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-04T09:10:23.802739Z e823c4c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@laincat
laincat merged commit c7eeff1 into main Nov 4, 2026
7 checks passed
@laincat
laincat deleted the fix/dependabot-merge-race branch November 4, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant