Files
xiaoxia-saas/scripts/ci/ci_run_selfcheck.sh
T
xiaoxia 80999118b7
CI/CD Pipeline / Check push changed paths (pull_request) Has been skipped
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Failing after 1s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Failing after 1s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 2s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 1m51s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
CI/CD Pipeline / Unit Tests (pull_request) Failing after 2s
CI/CD Pipeline / Integration Tests (pull_request) Failing after 2s
CI/CD Pipeline / PR Build API Image (pull_request) Failing after 1s
CI/CD Pipeline / PR Build Worker Image (pull_request) Failing after 1s
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Failing after 1m3s
fix(ci): 僵尸run复活防护——重负载job自检+dedupe竞态增强
P1修复(2026-08-30 CI巡检实证):
Gitea 1.26.4 调度器bug:被 concurrency cancel 的 run,其 job 会在数小时后
被复活重跑(attempt=2)。实测 42597 号 run 18:46 被取消,21:46 复活,
与正常流水线并行烧了1.5小时 runner(Validate+UnitTests+staging构建全套),
合并高峰双流水线CPU超卖导致单测 14分→30分。

改动:
1. 新增 scripts/ci/ci_run_selfcheck.sh:job 启动第一步实时查本 run 状态,
   若 conclusion 为 cancelled/skipped(被复活的僵尸job)立即退出(exit 78),
   API 故障时不阻断(unknown 照常执行)
2. ci-pipeline.yml 12 个重量级 job(validate×3、unit/integration/frontend×2、
   build-pr/build-staging/staging-e2e/api-tests/build-production)首步插入自检
3. dedupe-check 情形2增强:同一 head_sha 的 push 流水线不只是在跑时去重,
   已 success 完成时 PR 侧测试同样跳过(消除竞态窗口双跑)
2026-08-30 23:04:40 +08:00

35 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# CI job 运行前自检 —— 防 Gitea 1.26 调度 bug
# 被 concurrency cancel 的 run,其已派发的 job 可能在数小时后被调度器复活重跑
# 2026-08-30 实测:18:46 取消的 run21:46 复活 attempt=2,与正常流水线抢 runner 1.5 小时)。
# job 启动第一步先实时查本 run 状态,若已终结(cancelled/skipped),容器立即退出不烧资源。
#
# 用法:在重量级 jobValidate/Unit Tests/Integration/Frontend/Build/E2E 类)的
# 首个 step 中加入:bash scripts/ci/ci_run_selfcheck.sh
set -u
echo "▶ CI 运行前自检(僵尸 run 复活防护)..."
if [ -z "${GITHUB_API_URL:-}" ] || [ -z "${GITHUB_REPOSITORY:-}" ] || [ -z "${GITHUB_TOKEN:-}" ] || [ -z "${GITHUB_RUN_ID:-}" ]; then
echo "⚠️ 缺少 GITHUB_* 环境变量(GITHUB_RUN_ID/GITHUB_TOKEN),跳过自检(不阻断)"
exit 0
fi
CONCLUSION=$(curl -sf -H "Authorization: token ${GITHUB_TOKEN}" --max-time 10 \
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" 2>/dev/null \
| python3 -c "import json,sys; print(json.load(sys.stdin).get('conclusion') or 'running')" 2>/dev/null || echo "unknown")
case "${CONCLUSION}" in
cancelled|skipped)
echo "::error::本 run(${GITHUB_RUN_ID}) 状态已为 ${CONCLUSION},却仍被调度器派发执行——判定为 Gitea 复活的僵尸 job,立即退出,不再占用 runner"
exit 78 # EX_CONFIG:非零退出让调度器知晓该 job 终结(避免被当成功空跑)
;;
running|unknown|"")
# unknown 时不阻断(API 临时故障),正常执行
echo "✅ run ${GITHUB_RUN_ID} 状态正常(${CONCLUSION:-running}),继续执行"
;;
*)
echo "✅ run ${GITHUB_RUN_ID} 结论=${CONCLUSION}(已终结但非取消),继续执行"
;;
esac