#!/bin/bash # CI Validate: 代码风格检查(validate-style) # 包含:Python 字节码编译、black 格式、isort 排序、ruff lint、vulture 死代码(仅告警) set -eu echo "=== CI Validate: 代码风格检查 ===" # --- Python 字节码编译 --- echo "" echo "=== [1/3] Python bytecode compilation ===" python3 -m compileall -q alembic apps packages tests scripts echo "✅ Bytecode compilation passed" # --- 代码格式检查(全量)--- echo "" echo "=== [2/3] Code formatting (black + isort + ruff) ===" echo "Full scan mode" python3 -m black --check --fast alembic apps packages tests scripts python3 -m isort --check-only alembic apps packages tests scripts python3 -m ruff check apps packages tests --statistics echo "✅ Code formatting checks passed" # --- Vulture 死代码检测(仅告警)--- echo "" echo "=== [3/3] Dead code detection (vulture, advisory only) ===" set +e python3 -m pip install -q --no-cache-dir vulture || echo "⚠️ vulture install failed, skipping dead code detection" vulture --version echo "告警模式,不阻断CI。置信度>=90%建议尽快确认。" echo "" vulture apps packages scripts \ --exclude "tests,test,migrations,.gitea,docs,node_modules,site-packages,*/test_*.py,*/conftest.py" \ --min-confidence 70 \ 2>&1 | sort -t'(' -k2 -rn | head -80 echo "" echo "=== vulture scan summary ===" echo "发现潜在死代码(可能包含框架装饰器注册的函数,为误报)" echo "建议:定期人工审查高置信度(>=90%)条目" set -e echo "" echo "=== CI Validate: 代码风格检查 全部通过 ✅ ==="