fix(ci): 修复自动合并竞态条件 (#1648)
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Successful in 4s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 3s
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 5s
CI/CD Pipeline / Check push changed paths (push) Successful in 20s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 22s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 9s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 12s
CI/CD Pipeline / Build Staging API Image (push) Successful in 47s
CI/CD Pipeline / Build Staging Worker Image (push) Successful in 46s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 4s
CI/CD Pipeline / Retag skipped Staging Web Image (push) Successful in 20s
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Successful in 2m7s
AI Code Review / AI Code Review (pull_request) Failing after 2m3s
CI/CD Pipeline / Integration Tests (push) Successful in 2m13s
CI/CD Pipeline / Validate - Style (push) Successful in 2m42s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m12s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Successful in 1m8s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m5s
CI/CD Pipeline / ACR Image Cleanup (push) Successful in 1m34s
CI/CD Pipeline / Frontend Unit Tests (push) Successful in 5m31s
CI/CD Pipeline / Staging API Integration Tests (push) Successful in 3m2s
CI/CD Pipeline / Staging E2E Tests (push) Successful in 3m53s
CI/CD Pipeline / Validate - Security (push) Successful in 7m36s
CI/CD Pipeline / Unit Tests (push) Successful in 8m18s
CI/CD Pipeline / Build Production Web Image (push) Successful in 12s
CI/CD Pipeline / Build Production Worker Image (push) Successful in 11s
CI/CD Pipeline / Build Production API Image (push) Successful in 13s
CI/CD Pipeline / Deploy Production (push) Successful in 42s
CI/CD Pipeline / Production Browser E2E (push) Failing after 4m46s
CI/CD Pipeline / Canary Release to Production (push) Failing after 311h20m59s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Failing after 311h26m15s
CI/CD Pipeline / CI Gate (push) Failing after 311h21m12s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 311h27m30s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 311h27m35s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 311h27m34s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 311h27m41s
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Failing after 311h27m51s
CI/CD Pipeline / Retag skipped Staging API Image (push) Failing after 311h27m56s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 311h27m58s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 311h27m59s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 311h28m1s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 311h28m3s
CI/CD Pipeline / Build Staging Web Image (push) Failing after 311h28m50s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 311h28m3s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 311h28m59s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 311h28m59s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 311h29m20s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 311h29m20s
CI/CD Pipeline / Unit Tests (pull_request) Failing after 311h29m21s
CI/CD Pipeline / Validate - Security (pull_request) Failing after 311h29m22s
CI/CD Pipeline / Validate - Style (pull_request) Failing after 311h29m23s
CI/CD Pipeline / Frontend Lint (push) Failing after 311h29m26s
CI/CD Pipeline / PR Build Web Image (push) Failing after 311h29m35s
CI/CD Pipeline / PR Build API Image (push) Failing after 311h29m39s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 311h29m40s
CI/CD Pipeline / Check if frontend-only change (push) Failing after 311h29m45s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 312h1m56s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 312h2m22s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 312h3m20s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 312h3m41s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Failing after 312h3m43s
CI/CD Pipeline / PR Build Worker Image (push) Failing after 312h3m56s

This commit is contained in:
CI Test
2026-09-03 15:55:00 +08:00
2 changed files with 27 additions and 11 deletions
+3 -2
View File
@@ -18,7 +18,7 @@ jobs:
name: Auto Approve on CI Green
runs-on: ci-check
if: github.event_name == 'pull_request' && !github.event.pull_request.draft
timeout-minutes: 3 # 长等待模式:等CI全绿后自动合并,不遗漏任何PR
timeout-minutes: 10 # 等待CI全绿+审批,需要充足时间
steps:
- name: Checkout code
shell: sh
@@ -61,7 +61,8 @@ jobs:
name: Auto Merge on CI Green + Approved
runs-on: ci-check
if: github.event_name == 'pull_request' && !github.event.pull_request.draft && github.event.pull_request.base.ref == 'develop'
timeout-minutes: 3 # 短作业模式:检查一次,不满足就退出,由pr-auto-scan每5分钟定时兜底
needs: [auto-approve] # 修复竞态:必须等审批完成后再尝试合并
timeout-minutes: 15 # 等待审批+CI就绪+合并,需要充足时间
steps:
- name: Checkout code
shell: sh
+24 -9
View File
@@ -32,9 +32,9 @@ CONTEXTS=(
echo "检查CI Gate统一门禁"
echo
# 等待60秒,给CI启动写status的时间
echo "等待60秒让CI启动..."
sleep 60
# 等待30秒后开始轮询,最多10分钟
echo "等待30秒让CI启动..."
sleep 30
# 405计数器(单次运行内重试)
MERGE_405_COUNT=0
@@ -72,9 +72,9 @@ check_and_merge() {
# CI未全绿(pending中)→ 退出,等下次触发
if [ "$ALL_SUCCESS" != "true" ]; then
echo
echo "⏳ CI尚未全绿(仍有pending),退出等待下次触发"
echo " (pr-auto-scan每5分钟扫描一次,CI通过后会自动合并)"
exit 0
echo "⏳ CI尚未全绿(仍有pending),等待重试..."
echo " (当前第${attempt}次轮询,最多${MAX_ATTEMPTS}次)"
return 1
fi
# CI全绿 → 合并
@@ -136,13 +136,28 @@ check_and_merge() {
fi
}
# 最多重试3次(用于405重试,非CI轮询)
for i in 1 2 3; do
# 轮询等待CI就绪+审批完成,最多10分钟(60次x10秒)
MAX_ATTEMPTS=60
for attempt in $(seq 1 $MAX_ATTEMPTS); do
if check_and_merge; then
exit 0
fi
# 检查PR是否还open(可能已被手动合并或关闭)
PR_STATE=$(curl -s -H "Authorization: token ${MERGE_TOKEN}" \
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/pulls/${PR_NUMBER}" \
| python3 -c "import sys,json; print(json.load(sys.stdin).get('state',''))" 2>/dev/null || echo "?")
if [ "$PR_STATE" != "open" ]; then
echo "PR状态为 ${PR_STATE},无需继续等待"
exit 0
fi
if [ $attempt -lt $MAX_ATTEMPTS ]; then
sleep 10
fi
done
echo
echo "本次检查未满足合并条件,退出。pr-auto-scan每5分钟会继续扫描。"
echo "⏰ 等待10分钟后仍未满足合并条件,退出。pr-auto-scan定时扫描会继续重试。"
exit 0