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
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
- 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 可自动修复错误无法自动推修复、开发者反复打回的问题
This commit is contained in:
@@ -196,7 +196,7 @@ jobs:
|
||||
- name: Run style checks
|
||||
shell: bash
|
||||
run: bash scripts/ci/validate_style.sh
|
||||
- name: Auto-fix formatting (black + isort)
|
||||
- name: Auto-fix formatting (black + isort + ruff)
|
||||
if: failure()
|
||||
shell: sh
|
||||
env:
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
#!/usr/bin/env python3
|
||||
"""CI中自动修复代码格式(Python: black + isort | Frontend: prettier),并推送回原分支。
|
||||
"""CI中自动修复代码格式(Python: black + isort + ruff | Frontend: prettier),并推送回原分支。
|
||||
|
||||
- PR事件:所有PR只要Code Quality因格式问题失败,自动修复并push回源分支
|
||||
- Push事件(develop/main):自动修复并push回原分支,保持主干格式永远正确
|
||||
- 防循环:修复commit带 [skip ci-format-check] 标记,检测到该标记则跳过修复
|
||||
- 只修格式(black/isort/prettier),ruff逻辑类错误不动
|
||||
- black/isort/prettier 修格式;ruff check --fix --unsafe-fixes 自动修复
|
||||
ruff 可修复的 lint 规则(含 F401 未使用 import 等 unsafe fix)
|
||||
- ruff 目标范围与 validate_style.sh 的检查范围对齐:apps packages tests
|
||||
(alembic/scripts 不在 ruff 检查范围内,不做修复)
|
||||
当code quality检查因格式问题失败时触发。
|
||||
"""
|
||||
|
||||
@@ -135,7 +138,7 @@ def get_pr_head_branch(pr_number, api_url, token):
|
||||
|
||||
|
||||
def fix_python(target_py_files, scan_mode):
|
||||
"""修复 Python 文件格式 (black + isort)"""
|
||||
"""修复 Python 文件 (black 格式化 + isort 排序 + ruff lint 自动修复)"""
|
||||
if not target_py_files:
|
||||
print("没有需要修复的 Python 文件,跳过")
|
||||
return
|
||||
@@ -146,14 +149,48 @@ def fix_python(target_py_files, scan_mode):
|
||||
result = run(f"python3 -m black {target_str}", check=False)
|
||||
print(result.stdout[-500:] if result.stdout else "")
|
||||
if result.returncode != 0:
|
||||
print("black执行失败,但继续尝试isort", file=sys.stderr)
|
||||
print("black执行失败,但继续尝试isort/ruff", file=sys.stderr)
|
||||
|
||||
print()
|
||||
print("--- isort 排序 ---")
|
||||
result = run(f"python3 -m isort {target_str}", check=False)
|
||||
print(result.stdout[-500:] if result.stdout else "")
|
||||
if result.returncode != 0:
|
||||
print("isort执行失败", file=sys.stderr)
|
||||
print("isort执行失败,继续尝试ruff", file=sys.stderr)
|
||||
|
||||
# ruff lint 自动修复
|
||||
# 与 validate_style.sh 的检查范围对齐:只修 apps/packages/tests
|
||||
# (alembic 在 pyproject.toml 中被 exclude,scripts 不在 ruff 检查范围内)
|
||||
ruff_scopes = ("apps/", "packages/", "tests/")
|
||||
ruff_files = [f for f in target_py_files if f.startswith(ruff_scopes)]
|
||||
if scan_mode != "incremental":
|
||||
ruff_targets = "apps packages tests"
|
||||
elif ruff_files:
|
||||
ruff_targets = " ".join(ruff_files)
|
||||
else:
|
||||
ruff_targets = ""
|
||||
|
||||
if ruff_targets:
|
||||
# ruff 由 style job 的 requirements-dev.txt 安装;不可用时跳过(不阻断 black/isort 的修复)
|
||||
avail = run("python3 -m ruff --version", check=False)
|
||||
if avail.returncode != 0:
|
||||
print("ruff 不可用,跳过 ruff 自动修复", file=sys.stderr)
|
||||
else:
|
||||
print()
|
||||
print("--- ruff lint 自动修复 (--fix --unsafe-fixes) ---")
|
||||
# --unsafe-fixes 用于启用 F401(未使用 import)等 ruff 归类为 unsafe 的自动修复;
|
||||
# 安全性由修复后重跑的完整 CI(单测/构建/staging 健康检查)兜底
|
||||
result = run(
|
||||
f"python3 -m ruff check {ruff_targets} --fix --unsafe-fixes",
|
||||
check=False,
|
||||
)
|
||||
print(result.stdout[-1500:] if result.stdout else "")
|
||||
if result.returncode != 0:
|
||||
# 可能是仍有不可自动修复的 lint 错误(留待 style check 再次拦截),或修复过程出错
|
||||
print("ruff 自动修复后仍有未修复项或执行失败,剩余问题由 style check 继续拦截", file=sys.stderr)
|
||||
else:
|
||||
print()
|
||||
print("增量模式且无 apps/packages/tests 范围内的 Python 变更,跳过 ruff 自动修复")
|
||||
|
||||
|
||||
def fix_frontend(target_fe_files, scan_mode, repo_root):
|
||||
@@ -334,7 +371,7 @@ def main():
|
||||
# 提交修复
|
||||
run("git clean -fd")
|
||||
run("git add -u")
|
||||
run('git commit -m "style: auto-format with black + isort + prettier [skip ci-format-check]"')
|
||||
run('git commit -m "style: auto-format with black + isort + ruff + prettier [skip ci-format-check]"')
|
||||
|
||||
# 推送(head_branch已从ensure_git_repo获取)
|
||||
print(f"\nPR来源分支: {head_branch}")
|
||||
|
||||
Reference in New Issue
Block a user