fix(ci): auto-fix push增加pull rebase+3次重试,解决并发提交冲突
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 18s
AI Code Review / AI Code Review (pull_request) Failing after 37s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 50s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 7m33s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 5m38s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 13m1s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 1394h18m4s
CI/CD Pipeline / Production Browser E2E (pull_request) Failing after 1394h26m0s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 1394h26m3s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 1394h26m4s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 1394h26m4s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 1394h26m4s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 1394h26m6s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 1394h26m6s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 1394h26m6s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 1394h26m8s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 1394h26m8s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 1394h26m8s
CI/CD Pipeline / Check if frontend-only change (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 1394h58m13s

This commit is contained in:
CI Bot
2026-07-20 13:03:02 +08:00
parent afae36bf04
commit 3772b13c81
+36 -4
View File
@@ -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__":