perf(ci): mypy增量扫描优化 #354

Merged
xiaoxia merged 3 commits from feat/mypy-incremental into develop 2026-07-16 00:35:52 +08:00
3 changed files with 50 additions and 1 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ jobs:
- name: Type check (mypy, advisory mode)
if: always()
shell: sh
run: "set +e\necho \"=== Installing mypy ===\"\npython3 -m pip install -q mypy\nmypy --version\necho \"\"\necho \"=== Running mypy type check (advisory mode) ===\"\necho \"告警模式,不阻断CI\"\necho \"\"\n# 只检查核心业务代码,跳过测试和迁移\nEXIT_CODE=0\nmypy apps/api/app packages --ignore-missing-imports --no-site-packages --no-strict-optional --explicit-package-bases --exclude 'tests/|test_|migrations/|alembic/' --no-error-summary 2>&1 | head -60 || EXIT_CODE=$?\necho \"\"\nif [ \"$EXIT_CODE\" != \"0\" ]; then\n echo \"mypy 发现类型问题(告警模式,不阻断)\"\n echo \"建议后续逐步修复\"\nelse\n echo \"mypy 类型检查通过 ✅\"\nfi\nexit 0\n"
run: "bash scripts/ci/mypy_check.sh"
- name: Run security scan (bandit)
shell: sh
run: 'set -eu
+1
View File
@@ -63,6 +63,7 @@ exclude = [
".next",
"dist",
"build",
"hostexecutor",
]
[tool.ruff.lint]
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
# mypy憓鮋𡁏𧋦 - CI銝剛
# : SCAN_MODE, CHANGED_PY_FILES
set +e
echo "=== Installing mypy ==="
python3 -m pip install -q mypy
mypy --version
echo ""
echo "=== Running mypy type check (advisory mode) ==="
echo "𡃏郎璅∪嚗䔶裊餅鱏CI"
echo ""
MYPY_COMMON_ARGS="--ignore-missing-imports --no-site-packages --no-strict-optional --explicit-package-bases --exclude tests/|test_|migrations/|alembic/ --no-error-summary --incremental --cache-dir .mypy_cache"
EXIT_CODE=0
if [ "$SCAN_MODE" = "incremental" ] && [ -n "$CHANGED_PY_FILES" ]; then
echo "=== Incremental mypy scan (PR mode) ==="
echo "Changed files: $(echo $CHANGED_PY_FILES | wc -w) files"
MYPY_FILES=""
for f in $CHANGED_PY_FILES; do
case "$f" in
apps/*|packages/*)
MYPY_FILES="$MYPY_FILES $f"
;;
esac
done
if [ -n "$MYPY_FILES" ]; then
echo "Checking: $MYPY_FILES"
mypy $MYPY_FILES $MYPY_COMMON_ARGS 2>&1 | head -80 || EXIT_CODE=$?
else
echo "No mypy-checkable files changed, skipping"
fi
else
echo "=== Full mypy scan ==="
mypy apps/api/app packages $MYPY_COMMON_ARGS 2>&1 | head -60 || EXIT_CODE=$?
fi
echo ""
if [ "$EXIT_CODE" != "0" ]; then
echo "mypy 𤑳緵蝐餃霅行芋撘𧶏銝俛獈"
echo "撱箄悅𡒊賒鞉郊靽桀"
else
echo "mypy 蝐餃仿"
fi
exit 0