From ccbbd12a7f3cd79263eeb88e5f2b01226772fce0 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Mon, 20 Jul 2026 21:41:30 +0800 Subject: [PATCH] =?UTF-8?q?feat(ci):=20P2-6=20=E6=96=B0=E5=A2=9ECI?= =?UTF-8?q?=E5=81=A5=E5=BA=B7=E5=BA=A6=E6=AF=8F=E6=97=A5=E5=B7=A1=E6=A3=80?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 每天北京时间早上9点自动执行: - 统计最近30条CI run的成功率 - 区分基础设施vs业务代码失败 - 有失败时自动发送飞书卡片报告到项目群 - 全部通过时静默,不打扰 对应脚本: scripts/ci/ci_health_report.py --- .gitea/workflows/ci-health-daily.yml | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .gitea/workflows/ci-health-daily.yml diff --git a/.gitea/workflows/ci-health-daily.yml b/.gitea/workflows/ci-health-daily.yml new file mode 100644 index 000000000..d60326f2c --- /dev/null +++ b/.gitea/workflows/ci-health-daily.yml @@ -0,0 +1,81 @@ +name: CI Health Daily Report + +on: + schedule: + - cron: '0 1 * * *' # UTC 01:00 = 北京时间 09:00 + workflow_dispatch: + +permissions: + contents: read + +jobs: + ci-health-report: + name: CI健康度每日巡检 + runs-on: saas + timeout-minutes: 10 + + steps: + - name: Checkout code + shell: sh + env: + GITHUB_TOKEN: ${{ github.token }} + run: | + set -eu + python3 - <<'PY' + import io, os, tarfile, time, urllib.request, urllib.error + url = f"{os.environ['GITHUB_API_URL']}/repos/{os.environ['GITHUB_REPOSITORY']}/archive/{os.environ['GITHUB_SHA']}.tar.gz" + request = urllib.request.Request(url, headers={"Authorization": f"token {os.environ['GITHUB_TOKEN']}"}) + last_err = None + for attempt in range(5): + try: + with urllib.request.urlopen(request, timeout=120) as response: + archive = response.read() + break + except urllib.error.HTTPError as e: + last_err = e + if e.code >= 500 and attempt < 4: + wait = 2 ** attempt + print(f"Checkout HTTP {e.code}, retrying in {wait}s (attempt {attempt+1}/5)...") + time.sleep(wait) + continue + raise + except Exception as e: + last_err = e + if attempt < 4: + wait = 2 ** attempt + print(f"Checkout error: {e}, retrying in {wait}s (attempt {attempt+1}/5)...") + time.sleep(wait) + continue + raise + else: + raise last_err + with tarfile.open(fileobj=io.BytesIO(archive), mode='r:gz') as tar: + root_prefix = tar.getmembers()[0].name.split('/', 1)[0] + '/' + for member in tar.getmembers(): + name = member.name + if name == root_prefix[:-1]: + continue + if name.startswith(root_prefix): + member.name = name[len(root_prefix):] + if member.name: + tar.extract(member, '.') + PY + + - name: Run CI health check and report + shell: sh + env: + GITEA_TOKEN: ${{ github.token }} + CI_NOTIFY_WEBHOOK: ${{ secrets.CI_NOTIFY_WEBHOOK }} + run: | + set +e + echo "=== CI健康度每日巡检 ===" + echo "时间: $(date '+%Y-%m-%d %H:%M:%S')" + echo "" + + python3 scripts/ci/ci_health_report.py --limit 30 + EXIT_CODE=$? + + echo "" + echo "巡检完成 (exit code: $EXIT_CODE)" + # 永远成功,不影响CI状态(通知失败不应该标红) + exit 0