perf(ci): P0-4 Phase 1 - PR模式下lint增量扫描,只扫改动文件 #344

Merged
xiaoxia merged 1 commits from feat/ci-incremental-lint into develop 2026-07-15 10:44:20 +08:00
Owner

变更内容

P0-4 Phase 1:PR 模式下 lint 增量扫描

核心改动

  1. 新增步骤:Calculate changed Python files

    • PR 事件中,fetch base 分支,用 git diff 获取改动的 Python 文件
    • 设置 SCAN_MODECHANGED_PY_FILES 环境变量供后续步骤使用
    • 非 PR 事件(push 到 develop/main):全量扫描模式
    • fetch 失败自动 fallback 到全量扫描
  2. Run code quality checks 支持增量模式

    • incremental 模式:black/isort/ruff/compileall 只扫改动文件
    • skip_py 模式:没有 Python 文件变更时跳过 lint 检查
    • full 模式(默认):全量扫描,跟之前行为一致
    • ruff 增量扫描排除 scripts/ 目录,与全量模式规则对齐
  3. Prepare git for migration diff 兼容已有 git 仓库

    • 检测 .git 目录是否已存在,避免重复 git remote add 冲突

预期收益

PR 规模 优化前 优化后 节省
小 PR (<10文件) ~2min ~40s 60%+
中 PR (10-30文件) ~2min ~1min 50%
大 PR (重构) ~2min ~2min 接近全量

风险控制

  • develop/main 分支保持全量扫描兜底,不会漏检跨文件问题
  • fetch base 失败自动 fallback 到全量,不会因为增量逻辑导致 CI 挂掉
  • ruff 排除 scripts/ 目录,与全量模式规则完全一致,不会多拦
## 变更内容 **P0-4 Phase 1:PR 模式下 lint 增量扫描** ### 核心改动 1. **新增步骤:Calculate changed Python files** - PR 事件中,fetch base 分支,用 `git diff` 获取改动的 Python 文件 - 设置 `SCAN_MODE` 和 `CHANGED_PY_FILES` 环境变量供后续步骤使用 - 非 PR 事件(push 到 develop/main):全量扫描模式 - fetch 失败自动 fallback 到全量扫描 2. **Run code quality checks 支持增量模式** - `incremental` 模式:black/isort/ruff/compileall 只扫改动文件 - `skip_py` 模式:没有 Python 文件变更时跳过 lint 检查 - `full` 模式(默认):全量扫描,跟之前行为一致 - ruff 增量扫描排除 `scripts/` 目录,与全量模式规则对齐 3. **Prepare git for migration diff 兼容已有 git 仓库** - 检测 `.git` 目录是否已存在,避免重复 `git remote add` 冲突 ### 预期收益 | PR 规模 | 优化前 | 优化后 | 节省 | |--------|--------|--------|------| | 小 PR (<10文件) | ~2min | ~40s | 60%+ | | 中 PR (10-30文件) | ~2min | ~1min | 50% | | 大 PR (重构) | ~2min | ~2min | 接近全量 | ### 风险控制 - develop/main 分支保持全量扫描兜底,不会漏检跨文件问题 - fetch base 失败自动 fallback 到全量,不会因为增量逻辑导致 CI 挂掉 - ruff 排除 scripts/ 目录,与全量模式规则完全一致,不会多拦
xiaoxia force-pushed feat/ci-incremental-lint from b8b0821ffc to 3962994c43 2026-07-15 09:20:56 +08:00 Compare
xiaoxia reviewed 2026-07-15 10:06:12 +08:00
xiaoxia left a comment
Author
Owner

LGTM - 增量扫描设计合理,三模式 fallback 正确,migration diff 兼容性处理到位

LGTM - 增量扫描设计合理,三模式 fallback 正确,migration diff 兼容性处理到位
xiaoxia force-pushed feat/ci-incremental-lint from 3962994c43 to fed7103eec 2026-07-15 10:09:44 +08:00 Compare
auto-approve-bot approved these changes 2026-07-15 10:26:30 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia added 1 commit 2026-07-15 10:40:35 +08:00
perf(ci): P0-4 Phase 1 - PR模式下lint增量扫描,只扫改动文件
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 56s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 2m8s
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Successful in 2m38s
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 / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (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 / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m16s
f7ceb17efa
- PR模式:git diff获取改动Python文件,black/isort/ruff只扫改动
- develop/main模式:全量扫描兜底
- 小PR预计Validate阶段从2min降到40s以内
- 兼容已有migration diff的git仓库初始化
xiaoxia force-pushed feat/ci-incremental-lint from fed7103eec to f7ceb17efa 2026-07-15 10:40:35 +08:00 Compare
xiaoxia merged commit 2293adfbcf into develop 2026-07-15 10:44:20 +08:00
Sign in to join this conversation.