feat(ci): P2-6 CI健康度每日巡检 - 每天9点自动检查,有失败发飞书报告 #658

Merged
xiaoxia merged 3 commits from p2-6-ci-health-daily into develop 2026-07-20 22:05:34 +08:00
Owner

P2-6:CI健康度每日巡检

功能

每天北京时间早上9点自动巡检:

  • 统计最近30条CI run的成功率(按workflow分类)
  • 区分基础设施失败 vs 业务代码失败
  • 有失败时:自动发送飞书卡片报告到项目群,包含各workflow成功率、失败分类、失败详情
  • 全部通过时:静默退出,不打扰

新增文件

  • .gitea/workflows/ci-health-daily.yml - 每日定时任务(cron: 0 1 * * * = 北京时间9点)
  • scripts/ci/ci_health_report.py - 报告生成+飞书通知脚本

设计原则

  1. 静默优先:全绿不发消息,只有失败才打扰
  2. 信息丰富:失败报告包含成功率统计、分类、失败run详情、直达CI面板链接
  3. 不阻断CI:通知失败不影响workflow状态,永远exit 0
  4. 可手动触发:支持workflow_dispatch手动触发排查
## P2-6:CI健康度每日巡检 ### 功能 **每天北京时间早上9点自动巡检:** - 统计最近30条CI run的成功率(按workflow分类) - 区分基础设施失败 vs 业务代码失败 - **有失败时**:自动发送飞书卡片报告到项目群,包含各workflow成功率、失败分类、失败详情 - **全部通过时**:静默退出,不打扰 ### 新增文件 - `.gitea/workflows/ci-health-daily.yml` - 每日定时任务(cron: 0 1 * * * = 北京时间9点) - `scripts/ci/ci_health_report.py` - 报告生成+飞书通知脚本 ### 设计原则 1. **静默优先**:全绿不发消息,只有失败才打扰 2. **信息丰富**:失败报告包含成功率统计、分类、失败run详情、直达CI面板链接 3. **不阻断CI**:通知失败不影响workflow状态,永远exit 0 4. **可手动触发**:支持workflow_dispatch手动触发排查
xiaoxia added 2 commits 2026-07-20 21:41:41 +08:00
ci_health_report.py:
- 调用ci_health_check.py获取健康度数据
- 有失败时生成飞书卡片报告并发送
- 无失败时静默退出(不打扰)
- 支持--dry-run/--always-notify参数
feat(ci): P2-6 新增CI健康度每日巡检定时任务
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 / Check if frontend-only change (pull_request) Successful in 10s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
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 / Frontend Unit Tests (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 / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 1m0s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 1m21s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m34s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m51s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m0s
AI Code Review / AI Code Review (pull_request) Successful in 2m22s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m55s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 6m44s
ccbbd12a7f
每天北京时间早上9点自动执行:
- 统计最近30条CI run的成功率
- 区分基础设施vs业务代码失败
- 有失败时自动发送飞书卡片报告到项目群
- 全部通过时静默,不打扰

对应脚本: scripts/ci/ci_health_report.py

🚀 预览环境已部署

项目 详情
PR号 #658
预览链接 https://pr-658.preview.xiaoxiajianji.com
API环境 staging

💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。

🔄 每次提交新代码后预览环境会自动更新。

🗑️ PR 关闭或合并后,预览环境会自动清理。

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #658 | | 预览链接 | [https://pr-658.preview.xiaoxiajianji.com](https://pr-658.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia added 1 commit 2026-07-20 22:00:37 +08:00
style(ci): black格式化ci_health_report.py
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 21s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m41s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 1m57s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 3m50s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m23s
AI Code Review / AI Code Review (pull_request) Successful in 5m3s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 19s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 5m31s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m53s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m26s
b2bca27666
auto-approve-bot approved these changes 2026-07-20 22:05:00 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-07-20 22:05:01 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia merged commit ba6cacec8d into develop 2026-07-20 22:05:34 +08:00
Collaborator

代码审查结果 - PR #658

⚠️ 问题(2个需要修改)

  1. scripts/ci/ci_health_report.py 第37行:错误处理逻辑掩盖真实失败状态

    • 问题描述:当 ci_health_check.py 执行失败(返回码非0)或 JSON 解析失败时,函数返回空字典 {"workflows": {}, "failed_runs": []}。这会导致主流程误判为“全部通过”,从而掩盖了巡检脚本本身的崩溃或 API 异常,产生误报。
    • 修改建议:建议在子进程失败或解析失败时抛出异常,或者返回一个包含错误信息的特殊结构(如 {"error": "..."}),并在 main 函数中识别该状态,发送“巡检异常”的通知而不是“全部通过”。
  2. scripts/ci/ci_health_report.py 第73行:字典键访问缺少安全检查

    • 问题描述:代码中使用 j["name"] 访问 job 名称,如果上游 ci_health_check.py 返回的数据结构中某个 job 缺少 name 字段,会抛出 KeyError 导致报告生成中断。
    • 修改建议:使用 j.get("name", "") 替代 j["name"],增强对数据格式的容错性。

💡 建议(2个可选)

  1. .gitea/workflows/ci-health-daily.yml 第38行:路径遍历安全风险

    • 具体内容:使用 tar.extract(member, '.') 解压文件时,未校验 member.name。虽然源代码通常可信,但若仓库被投毒或包含特殊构建产物,可能利用 ../ 覆盖系统文件。建议增加路径校验,过滤包含 .. 或以绝对路径开头的文件名。
  2. .gitea/workflows/ci-health-daily.yml 第28行:边界条件处理

    • 具体内容:tar.getmembers()[0] 假设压缩包至少包含一个文件。如果压缩包为空(极端异常情况),此处会抛出 IndexError。建议检查列表长度后再访问。

格式检查通过 | 逻辑审查需修改 | 性能无明显问题


🤖 由 AI 代码审查机器人自动生成 | 2026-07-20 22:05:40 | 模型:

## 代码审查结果 - PR #658 ### ⚠️ 问题(2个需要修改) 1. **scripts/ci/ci_health_report.py 第37行**:错误处理逻辑掩盖真实失败状态 - 问题描述:当 `ci_health_check.py` 执行失败(返回码非0)或 JSON 解析失败时,函数返回空字典 `{"workflows": {}, "failed_runs": []}`。这会导致主流程误判为“全部通过”,从而掩盖了巡检脚本本身的崩溃或 API 异常,产生误报。 - 修改建议:建议在子进程失败或解析失败时抛出异常,或者返回一个包含错误信息的特殊结构(如 `{"error": "..."}`),并在 `main` 函数中识别该状态,发送“巡检异常”的通知而不是“全部通过”。 2. **scripts/ci/ci_health_report.py 第73行**:字典键访问缺少安全检查 - 问题描述:代码中使用 `j["name"]` 访问 job 名称,如果上游 `ci_health_check.py` 返回的数据结构中某个 job 缺少 `name` 字段,会抛出 `KeyError` 导致报告生成中断。 - 修改建议:使用 `j.get("name", "")` 替代 `j["name"]`,增强对数据格式的容错性。 ### 💡 建议(2个可选) 1. **.gitea/workflows/ci-health-daily.yml 第38行**:路径遍历安全风险 - 具体内容:使用 `tar.extract(member, '.')` 解压文件时,未校验 `member.name`。虽然源代码通常可信,但若仓库被投毒或包含特殊构建产物,可能利用 `../` 覆盖系统文件。建议增加路径校验,过滤包含 `..` 或以绝对路径开头的文件名。 2. **.gitea/workflows/ci-health-daily.yml 第28行**:边界条件处理 - 具体内容:`tar.getmembers()[0]` 假设压缩包至少包含一个文件。如果压缩包为空(极端异常情况),此处会抛出 `IndexError`。建议检查列表长度后再访问。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-20 22:05:40 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->

🗑️ 预览环境已清理

PR #658 已关闭或合并,对应的预览环境已被清理。

如有需要,可以重新打开 PR 来重新生成预览环境。

🗑️ **预览环境已清理** PR #658 已关闭或合并,对应的预览环境已被清理。 > 如有需要,可以重新打开 PR 来重新生成预览环境。
Sign in to join this conversation.