From 3772b13c819c047f402657066f50285c207c40db Mon Sep 17 00:00:00 2001 From: CI Bot Date: Mon, 20 Jul 2026 13:03:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20auto-fix=20push=E5=A2=9E=E5=8A=A0pul?= =?UTF-8?q?l=20rebase+3=E6=AC=A1=E9=87=8D=E8=AF=95=EF=BC=8C=E8=A7=A3?= =?UTF-8?q?=E5=86=B3=E5=B9=B6=E5=8F=91=E6=8F=90=E4=BA=A4=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci/auto_fix_formatting.py | 40 +++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/scripts/ci/auto_fix_formatting.py b/scripts/ci/auto_fix_formatting.py index 0ec56ad7c..9f1778c85 100755 --- a/scripts/ci/auto_fix_formatting.py +++ b/scripts/ci/auto_fix_formatting.py @@ -242,11 +242,43 @@ def main(): # 推送(head_branch已从ensure_git_repo获取) print(f"\nPR来源分支: {head_branch}") - run(f'git push origin "HEAD:{head_branch}"') + # 推送带rebase+重试,避免并发提交导致冲突 + max_push_retries = 3 + push_success = False + for attempt in range(1, max_push_retries + 1): + print(f"推送尝试 {attempt}/{max_push_retries}...") + try: + # 先pull --rebase拉取最新提交 + run(f"git pull --rebase origin {head_branch}", check=False) + # 如果rebase有冲突,中止rebase并报错 + result = run("git status --porcelain", capture=True) + if "rebase" in result.stdout or "both modified" in result.stdout: + run("git rebase --abort", check=False) + print("rebase冲突,跳过本次推送", file=sys.stderr) + break + # 推送 + push_result = run(f'git push origin "HEAD:{head_branch}"', check=False) + if push_result.returncode == 0: + push_success = True + break + else: + print(f"推送失败: {push_result.stderr[-200:]}", file=sys.stderr) + if attempt < max_push_retries: + import time + time.sleep(2 ** attempt) + except Exception as e: + print(f"推送异常: {e}", file=sys.stderr) + if attempt < max_push_retries: + import time + time.sleep(2 ** attempt) - print() - print("✅ 格式已自动修复并推送回分支") - print("新的commit会重新触发CI检查") + if not push_success: + print("⚠️ 自动格式化推送失败,跳过(请手动检查)", file=sys.stderr) + sys.exit(0) # 不影响Validate的失败标记 + else: + print() + print("✅ 格式已自动修复并推送回分支") + print("新的commit会重新触发CI检查") if __name__ == "__main__":