From e705cbdd8acfef3382f0ca4198cbd4b0fe938f6f Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 15 Jul 2026 09:04:03 +0800 Subject: [PATCH 1/4] =?UTF-8?q?perf(ci):=20=E4=BF=AE=E5=A4=8DFrontend=20Li?= =?UTF-8?q?nt=E7=9A=84npm=E7=BC=93=E5=AD=98=E5=81=87=E5=91=BD=E4=B8=AD?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20(#341)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index 0f214247b..72f2b02ce 100644 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -371,7 +371,7 @@ jobs: ' - name: Install dependencies shell: sh - run: "set -eu\nNPM_CACHE_VOLUME=\"xiaoxia-npm-cache\"\nif ! docker volume inspect \"$NPM_CACHE_VOLUME\" >/dev/null 2>&1; then\n docker volume create \"$NPM_CACHE_VOLUME\" >/dev/null\n echo \"Created npm cache volume: $NPM_CACHE_VOLUME\"\nfi\n\ndocker run --rm \\\n -v \"$PWD:/workspace\" \\\n -v \"$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules\" -w /workspace/apps/web \\\n docker.m.daocloud.io/library/node:20 \\\n sh -lc 'rm -rf node_modules/* 2>/dev/null; npm ci --include=dev'\n" + run: "set -eu\nNPM_CACHE_VOLUME=\"xiaoxia-npm-cache\"\nif ! docker volume inspect \"$NPM_CACHE_VOLUME\" >/dev/null 2>&1; then\n docker volume create \"$NPM_CACHE_VOLUME\" >/dev/null\n echo \"Created npm cache volume: $NPM_CACHE_VOLUME\"\nfi\n\ndocker run --rm \\\n -v \"$PWD:/workspace\" \\\n -v \"$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules\" -w /workspace/apps/web \\\n docker.m.daocloud.io/library/node:20 \\\n sh -lc 'PACKAGE_LOCK_HASH=$(md5sum package-lock.json 2>/dev/null | cut -d\" \" -f1)\nCACHE_HASH_FILE=\"node_modules/.package-lock-hash\"\nif [ -f \"$CACHE_HASH_FILE\" ] && [ \"$(cat \"$CACHE_HASH_FILE\")\" = \"$PACKAGE_LOCK_HASH\" ]; then\n echo \"Cache hit: dependencies unchanged, skipping npm ci\"\nelse\n echo \"Cache miss: running npm ci...\"\n npm ci --include=dev\n echo \"$PACKAGE_LOCK_HASH\" > \"$CACHE_HASH_FILE\"\n echo \"Dependencies installed, cache updated\"\nfi'\n" - name: Run ESLint shell: sh run: "set -eu\nNPM_CACHE_VOLUME=\"xiaoxia-npm-cache\"\nif ! docker volume inspect \"$NPM_CACHE_VOLUME\" >/dev/null 2>&1; then\n docker volume create \"$NPM_CACHE_VOLUME\" >/dev/null\n echo \"Created npm cache volume: $NPM_CACHE_VOLUME\"\nfi\n\ndocker run --rm \\\n -v \"$PWD:/workspace\" \\\n -v \"$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules\" -w /workspace/apps/web \\\n docker.m.daocloud.io/library/node:20 \\\n sh -lc 'npx eslint src --ext .ts,.tsx --max-warnings 50'\n" From 535e525a0e552194029cedefc82e60bbb7813b36 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 15 Jul 2026 09:16:35 +0800 Subject: [PATCH 2/4] =?UTF-8?q?fix(worker):=20=E4=BF=AE=E5=A4=8D=E7=98=A6?= =?UTF-8?q?=E8=BA=AB=E5=90=8Eshared=E6=A8=A1=E5=9D=97=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E7=9A=84PYTHONPATH=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #343: 修复Worker镜像瘦身后shared模块无法导入的PYTHONPATH问题 将ENV PYTHONPATH=/app改为ENV PYTHONPATH=/app:/app/packages,解决ModuleNotFoundError: No module named "shared"问题。 --- infra/docker/worker.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/docker/worker.Dockerfile b/infra/docker/worker.Dockerfile index 4fc1ff980..32766988d 100755 --- a/infra/docker/worker.Dockerfile +++ b/infra/docker/worker.Dockerfile @@ -113,7 +113,7 @@ RUN chmod +x /usr/local/bin/entrypoint-worker.sh # 设置 Python 路径 ENV PATH="/opt/venv/bin:$PATH" -ENV PYTHONPATH=/app +ENV PYTHONPATH=/app:/app/packages ENV PYTHONUNBUFFERED=1 ENV APP_VERSION=$APP_VERSION From 9c155d05618b56be8429c6d1f120a6f07eb1a6e2 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 15 Jul 2026 10:04:55 +0800 Subject: [PATCH 3/4] =?UTF-8?q?fix(ci):=20=E4=BF=AE=E5=A4=8DFrontend=20Lin?= =?UTF-8?q?t=E7=BC=93=E5=AD=98=E8=84=8F=E6=95=B0=E6=8D=AE=E5=AF=BC?= =?UTF-8?q?=E8=87=B4npm=20ci=E5=A4=B1=E8=B4=A5=20(#345)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml index 72f2b02ce..3e04e1dc0 100644 --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -371,7 +371,7 @@ jobs: ' - name: Install dependencies shell: sh - run: "set -eu\nNPM_CACHE_VOLUME=\"xiaoxia-npm-cache\"\nif ! docker volume inspect \"$NPM_CACHE_VOLUME\" >/dev/null 2>&1; then\n docker volume create \"$NPM_CACHE_VOLUME\" >/dev/null\n echo \"Created npm cache volume: $NPM_CACHE_VOLUME\"\nfi\n\ndocker run --rm \\\n -v \"$PWD:/workspace\" \\\n -v \"$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules\" -w /workspace/apps/web \\\n docker.m.daocloud.io/library/node:20 \\\n sh -lc 'PACKAGE_LOCK_HASH=$(md5sum package-lock.json 2>/dev/null | cut -d\" \" -f1)\nCACHE_HASH_FILE=\"node_modules/.package-lock-hash\"\nif [ -f \"$CACHE_HASH_FILE\" ] && [ \"$(cat \"$CACHE_HASH_FILE\")\" = \"$PACKAGE_LOCK_HASH\" ]; then\n echo \"Cache hit: dependencies unchanged, skipping npm ci\"\nelse\n echo \"Cache miss: running npm ci...\"\n npm ci --include=dev\n echo \"$PACKAGE_LOCK_HASH\" > \"$CACHE_HASH_FILE\"\n echo \"Dependencies installed, cache updated\"\nfi'\n" + run: "set -eu\nNPM_CACHE_VOLUME=\"xiaoxia-npm-cache\"\nif ! docker volume inspect \"$NPM_CACHE_VOLUME\" >/dev/null 2>&1; then\n docker volume create \"$NPM_CACHE_VOLUME\" >/dev/null\n echo \"Created npm cache volume: $NPM_CACHE_VOLUME\"\nfi\n\ndocker run --rm \\\n -v \"$PWD:/workspace\" \\\n -v \"$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules\" -w /workspace/apps/web \\\n docker.m.daocloud.io/library/node:20 \\\n sh -lc 'PACKAGE_LOCK_HASH=$(md5sum package-lock.json 2>/dev/null | cut -d\" \" -f1)\nCACHE_HASH_FILE=\"node_modules/.package-lock-hash\"\nCACHE_VALID=false\nif [ -f \"$CACHE_HASH_FILE\" ] && [ \"$(cat \"$CACHE_HASH_FILE\")\" = \"$PACKAGE_LOCK_HASH\" ] && [ -x \"node_modules/.bin/eslint\" ]; then\n CACHE_VALID=true\n echo \"Cache hit: dependencies valid, skipping npm ci\"\nfi\nif [ \"$CACHE_VALID\" = \"false\" ]; then\n echo \"Cache miss or invalid: running npm ci...\"\n if ! npm ci --include=dev; then\n echo \"npm ci failed, cleaning node_modules and retrying...\"\n rm -rf node_modules\n mkdir -p node_modules\n npm ci --include=dev\n fi\n echo \"$PACKAGE_LOCK_HASH\" > \"$CACHE_HASH_FILE\"\n echo \"Dependencies installed, cache updated\"\nfi'\n" - name: Run ESLint shell: sh run: "set -eu\nNPM_CACHE_VOLUME=\"xiaoxia-npm-cache\"\nif ! docker volume inspect \"$NPM_CACHE_VOLUME\" >/dev/null 2>&1; then\n docker volume create \"$NPM_CACHE_VOLUME\" >/dev/null\n echo \"Created npm cache volume: $NPM_CACHE_VOLUME\"\nfi\n\ndocker run --rm \\\n -v \"$PWD:/workspace\" \\\n -v \"$NPM_CACHE_VOLUME:/workspace/apps/web/node_modules\" -w /workspace/apps/web \\\n docker.m.daocloud.io/library/node:20 \\\n sh -lc 'npx eslint src --ext .ts,.tsx --max-warnings 50'\n" From 4397c670d82adad99a61eb5f37aba7f7c44c0038 Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 15 Jul 2026 10:12:26 +0800 Subject: [PATCH 4/4] =?UTF-8?q?perf(ci):=20=E7=94=A8=20ruff=20=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2=20flake8=20-=20=E8=A7=84=E5=88=99=E5=AE=8C=E5=85=A8?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=EF=BC=8C=E9=80=9F=E5=BA=A6=E6=8F=90=E5=8D=87?= =?UTF-8?q?10x+?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yml | 8 ++------ pyproject.toml | 26 ++++++++++++++------------ requirements-dev.txt | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) mode change 100644 => 100755 .gitea/workflows/ci-cd.yml mode change 100644 => 100755 requirements-dev.txt diff --git a/.gitea/workflows/ci-cd.yml b/.gitea/workflows/ci-cd.yml old mode 100644 new mode 100755 index 3e04e1dc0..561b64abd --- a/.gitea/workflows/ci-cd.yml +++ b/.gitea/workflows/ci-cd.yml @@ -68,7 +68,7 @@ jobs: python3 -m isort --version-number - python3 -m flake8 --version + python3 -m ruff --version bandit --version @@ -89,13 +89,9 @@ jobs: python3 -m isort --check-only alembic apps packages tests scripts - python3 -m flake8 apps packages tests --count --statistics + python3 -m ruff check apps packages tests --statistics ' - - name: Ruff lint (advisory mode - 摸底阶段) - if: always() - shell: sh - run: "set +e\necho \"=== Installing ruff ===\"\npython3 -m pip install -q ruff\nruff --version\necho \"\"\necho \"=== Running ruff lint (advisory mode) ===\"\necho \"告警模式,不阻断CI。用于摸底问题数量,后续分批修复后正式替换flake8。\"\necho \"\"\nruff check apps packages tests scripts --statistics --output-format concise 2>&1 | tail -30\nEXIT_CODE=$?\necho \"\"\nif [ \"$EXIT_CODE\" != \"0\" ]; then\n echo \"ruff 发现 lint 问题(告警模式,不阻断)\"\n echo \"问题分类统计见上方,后续将分批修复\"\nelse\n echo \"ruff 检查全部通过 ✅\"\nfi\nexit 0\n" - name: Type check (mypy, advisory mode) if: always() shell: sh diff --git a/pyproject.toml b/pyproject.toml index cf71b34ae..eeda60168 100755 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,18 +66,18 @@ exclude = [ ] [tool.ruff.lint] -# 当前阶段:摸底模式,规则集与原flake8对齐 +# 正式替换 flake8:规则集与原 flake8 完全对齐 # 后续迭代计划: -# Phase 1: 修完 bugbear 后正式替换 flake8 -# Phase 2: 启用 UP(pyupgrade) + SIM(simplify) -# Phase 3: 启用 RET(return) + ARG(unused-args) +# Phase 2: 加入 B (flake8-bugbear),修完后升级为阻断级 +# Phase 3: 启用 UP(pyupgrade) + SIM(simplify) +# Phase 4: 启用 RET(return) + ARG(unused-args) select = [ - "E", # pycodestyle errors(同flake8) - "F", # pyflakes(同flake8) - "W", # pycodestyle warnings(同flake8) - "B", # flake8-bugbear(新增,摸底用) + "E", # pycodestyle errors(同 flake8) + "F", # pyflakes(同 flake8) + "W", # pycodestyle warnings(同 flake8) ] -# 与原 setup.cfg flake8 配置对齐,确保不新增阻断 +# 与原 setup.cfg + .flake8 的 flake8 配置完全对齐 +# 注意:W503 在 ruff≥0.14 中已被移除(行为变默认),故不列入 ignore = [ "E203", "E501", # line-too-long(black管) @@ -90,12 +90,14 @@ ignore = [ "F403", "F405", "F841", # unused-variable - "B008", # do-not-perform-callback-from-arg(fastapi依赖注入) ] [tool.ruff.lint.per-file-ignores] "__init__.py" = ["F401", "F403", "F405"] -"tests/*" = ["E402", "F401", "F841"] -"packages/ports/*" = ["E301"] +"tests/*" = ["E402", "F401", "F821", "F841"] +"packages/ports/*" = ["E301"] # E704 在 ruff≥0.14 已移除 +"apps/api/app/api/routes/auth.py" = ["ALL"] +"apps/api/app/api/routes/workspaces.py" = ["ALL"] +"apps/api/app/middleware/auth.py" = ["ALL"] "apps/*/migrations/*" = ["ALL"] "alembic/*" = ["ALL"] diff --git a/requirements-dev.txt b/requirements-dev.txt old mode 100644 new mode 100755 index 4aafad283..585f62d07 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -3,7 +3,7 @@ # 代码质量 black==26.5.1 isort==8.0.1 -flake8==7.3.0 +ruff==0.14.0 bandit==1.9.4 # 测试