fix(ci): auto-fix 脚本补充 ruff check --fix(F401 等可自动修复) #1847

Merged
xiaoxia merged 1 commits from fix/ci-autofix-ruff into develop 2026-09-10 20:48:15 +08:00
Owner

背景

Validate - Style 的 auto-fix 步骤(scripts/ci/auto_fix_formatting.py)只跑 black/isort/prettier,漏了 ruff check --fix。导致 F401(未使用 import)等 ruff 可自动修复的 lint 错误在 CI 报红后无法自动推修复,开发者反复被打回(近期 #49049/#49041/#49018 三个 PR 均因此卡 Style)。

改动

  • fix_python() 在 black/isort 之后追加 ruff check <targets> --fix --unsafe-fixes:
    • --unsafe-fixes 用于启用 F401 等 ruff 归类为 unsafe 的自动修复(否则 F401 不会被自动修);安全性由修复后重跑的完整 CI(单测/构建/staging 健康检查+回滚)兜底。
    • 目标范围与 validate_style.sh 的检查范围对齐:apps packages tests(alembic 在 pyproject.toml 中被 ruff exclude,scripts 不在 ruff 检查范围内,均不做修复)。
    • 增量模式只修变更文件中属于 apps/packages/tests 的 .py;全量模式修 apps packages tests。
    • ruff 不可用(未安装)时跳过、不阻断 black/isort 的修复;修复后仍有残余不可修 lint 时不报错退出,留给 style check 再次拦截。
  • 修复 commit message 同步为 style: auto-format with black + isort + ruff + prettier([skip ci-format-check] 防循环标记不变)。
  • workflow step 名更新为 Auto-fix formatting (black + isort + ruff)。

验证

  • py_compile 语法检查通过;改动后的脚本本身 ruff check 全过。
  • CI 全绿(Validate Style / Tests / Build)后合并。

影响面

仅 CI 自动化脚本,不碰业务代码。合并后所有 PR/push 的 Style 失败会自动修复 ruff 可修复项并推回分支。

## 背景 Validate - Style 的 auto-fix 步骤(`scripts/ci/auto_fix_formatting.py`)只跑 black/isort/prettier,**漏了 `ruff check --fix`**。导致 F401(未使用 import)等 ruff 可自动修复的 lint 错误在 CI 报红后无法自动推修复,开发者反复被打回(近期 #49049/#49041/#49018 三个 PR 均因此卡 Style)。 ## 改动 - `fix_python()` 在 black/isort 之后追加 **`ruff check <targets> --fix --unsafe-fixes`**: - `--unsafe-fixes` 用于启用 F401 等 ruff 归类为 unsafe 的自动修复(否则 F401 不会被自动修);安全性由修复后重跑的完整 CI(单测/构建/staging 健康检查+回滚)兜底。 - 目标范围与 `validate_style.sh` 的检查范围对齐:**apps packages tests**(alembic 在 pyproject.toml 中被 ruff exclude,scripts 不在 ruff 检查范围内,均不做修复)。 - 增量模式只修变更文件中属于 apps/packages/tests 的 .py;全量模式修 apps packages tests。 - ruff 不可用(未安装)时跳过、不阻断 black/isort 的修复;修复后仍有残余不可修 lint 时不报错退出,留给 style check 再次拦截。 - 修复 commit message 同步为 `style: auto-format with black + isort + ruff + prettier`(`[skip ci-format-check]` 防循环标记不变)。 - workflow step 名更新为 `Auto-fix formatting (black + isort + ruff)`。 ## 验证 - `py_compile` 语法检查通过;改动后的脚本本身 `ruff check` 全过。 - CI 全绿(Validate Style / Tests / Build)后合并。 ## 影响面 仅 CI 自动化脚本,不碰业务代码。合并后所有 PR/push 的 Style 失败会自动修复 ruff 可修复项并推回分支。
xiaoxia added 1 commit 2026-09-10 20:20:49 +08:00
fix(ci): auto-fix 脚本补充 ruff check --fix(含 F401 等 unsafe fix)
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Successful in 1s
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 2s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 26s
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 27s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 1m8s
CI/CD Pipeline / Validate - Style (pull_request) Successful in 1m31s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 2m1s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 2m41s
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Successful in 3m57s
AI Code Review / AI Code Review (pull_request) Successful in 6m40s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 9m25s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 10m31s
CI/CD Pipeline / Validate - Security (pull_request) Successful in 24m37s
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 2s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 11s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 1m42s
CI/CD Pipeline / Build Production Worker Image (pull_request) Failing after 138h38m17s
CI/CD Pipeline / Staging API Integration Tests (pull_request) Failing after 139h2m44s
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Failing after 139h2m55s
CI/CD Pipeline / Frontend Lint (pull_request) Failing after 139h2m56s
CI/CD Pipeline / PR Build Web Image (pull_request) Failing after 139h2m43s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Failing after 139h2m38s
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Failing after 139h2m43s
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Failing after 139h2m43s
CI/CD Pipeline / Build Staging Worker Image (pull_request) Failing after 139h2m49s
CI/CD Pipeline / Build Staging Web Image (pull_request) Failing after 139h2m49s
CI/CD Pipeline / Build Staging API Image (pull_request) Failing after 139h2m49s
CI/CD Pipeline / Deploy Production (pull_request) Failing after 138h38m4s
CI/CD Pipeline / Build Production Web Image (pull_request) Failing after 138h38m5s
CI/CD Pipeline / Build Production API Image (pull_request) Failing after 138h38m6s
CI/CD Pipeline / Check push changed paths (pull_request) Failing after 139h2m51s
CI/CD Pipeline / Canary Release to Production (pull_request) Failing after 138h38m4s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Failing after 139h2m32s
CI/CD Pipeline / Staging E2E Tests (pull_request) Failing after 139h2m32s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Failing after 139h2m43s
caa4ce118c
- fix_python() 在 black/isort 之后追加 ruff check --fix --unsafe-fixes
- 目标范围与 validate_style.sh 对齐:apps packages tests(alembic 被 ruff exclude,scripts 不在检查范围)
- ruff 不可用或修复后仍有残余问题时不阻断,剩余 lint 由 style check 继续拦截
- workflow step 名同步更新

解决 F401 等 ruff 可自动修复错误无法自动推修复、开发者反复打回的问题

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1847 | | 预览链接 | [https://pr-1847.preview.xiaoxiajianji.com](https://pr-1847.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
xiaoxia merged commit 00a6516543 into develop 2026-09-10 20:48:15 +08:00

🗑️ 预览环境已清理

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

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

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