fix(ci): 安全/风格检查 pip install 加固——防缓存损坏导致 CI 失败 #1584

Merged
xiaoxia merged 1 commits from fix/ci-cache-robustness into develop 2026-08-31 21:07:42 +08:00
Owner

问题

Gitea Actions cache 返回损坏归档时(cache EOF/deserialization failed),pip install pip-audit/detect-secrets/vulture 因 hash mismatch 直接 exit 1,导致 validate-security/validate-style 整体失败。

修复

  • detect-secrets/pip-audit/vulture 安装加 --no-cache-dir
  • pip-audit 安装失败后 graceful skip(本身是 advisory-only)
  • detect-secrets 安装失败后重试一次 --no-binary
  • vulture 安装失败后 skip 死代码检测(本身是 advisory-only)

影响

  • validate-security:不再因 pip cache 损坏而整体失败
  • validate-style:vulture 安装失败不再阻断 CI
## 问题 Gitea Actions cache 返回损坏归档时(cache EOF/deserialization failed),pip install pip-audit/detect-secrets/vulture 因 hash mismatch 直接 exit 1,导致 validate-security/validate-style 整体失败。 ## 修复 - detect-secrets/pip-audit/vulture 安装加 `--no-cache-dir` - pip-audit 安装失败后 graceful skip(本身是 advisory-only) - detect-secrets 安装失败后重试一次 `--no-binary` - vulture 安装失败后 skip 死代码检测(本身是 advisory-only) ## 影响 - validate-security:不再因 pip cache 损坏而整体失败 - validate-style:vulture 安装失败不再阻断 CI
xiaoxia added 1 commit 2026-08-31 20:16:59 +08:00
fix(ci): 安全/风格检查 pip install 加固——防缓存损坏导致 CI 失败
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (push) Has been cancelled
CI/CD Pipeline / Check if frontend-only change (push) Has been cancelled
CI/CD Pipeline / Validate - Style (push) Has been cancelled
CI/CD Pipeline / Validate - Security (push) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (push) Has been cancelled
CI/CD Pipeline / Unit Tests (push) Has been cancelled
CI/CD Pipeline / Integration Tests (push) Has been cancelled
CI/CD Pipeline / Frontend Lint (push) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (push) Has been cancelled
CI/CD Pipeline / PR Build API Image (push) Has been cancelled
CI/CD Pipeline / PR Build Web Image (push) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (push) Has been cancelled
CI/CD Pipeline / Check push changed paths (push) Has been cancelled
CI/CD Pipeline / Build Staging API Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Retag skipped Staging API Image (push) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Web Image (push) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (push) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (push) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (push) Has been cancelled
CI/CD Pipeline / Build Production API Image (push) Has been cancelled
CI/CD Pipeline / Build Production Web Image (push) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (push) Has been cancelled
CI/CD Pipeline / Deploy Production (push) Has been cancelled
CI/CD Pipeline / Production Browser E2E (push) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (push) Has been cancelled
CI/CD Pipeline / Canary Release to Production (push) Has been cancelled
CI/CD Pipeline / CI Gate (push) Has been cancelled
CI/CD Pipeline / Dedup Check - skip PR tests when covered by push pipeline (pull_request) Has been cancelled
CI/CD Pipeline / Check if frontend-only change (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Style (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Security (pull_request) Has been cancelled
CI/CD Pipeline / Validate - Python (mypy + alembic) (pull_request) Has been cancelled
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Lint (pull_request) Has been cancelled
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Web Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Check push changed paths (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging API Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Retag skipped Staging Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been cancelled
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been cancelled
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / Build Production API Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Web Image (pull_request) Has been cancelled
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been cancelled
CI/CD Pipeline / Deploy Production (pull_request) Has been cancelled
CI/CD Pipeline / Production Browser E2E (pull_request) Has been cancelled
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been cancelled
CI/CD Pipeline / Canary Release to Production (pull_request) Has been cancelled
CI/CD Pipeline / CI Gate (pull_request) Has been cancelled
AI Code Review / AI Code Review (pull_request) Has been cancelled
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
PR Automation / Auto Merge on CI Green + Approved (pull_request) Has been cancelled
Preview Deploy / Deploy Preview Environment (pull_request) Has been cancelled
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 5m45s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 6m8s
72f47592a9
问题:Gitea Actions cache 返回损坏归档时(cache EOF/deserialization failed),
pip install pip-audit/detect-secrets/vulture 因 hash mismatch 直接 exit 1,
导致 validate-security/validate-style 整体失败。

修复:
- detect-secrets/pip-audit/vulture 安装加 --no-cache-dir
- pip-audit 安装失败后 graceful skip(本身是 advisory-only)
- detect-secrets 安装失败后重试一次 --no-binary
- vulture 安装失败后 skip 死代码检测(本身是 advisory-only)
Collaborator

代码审查结果 - PR #1584

⚠️ 问题(1个需要修改)

  1. scripts/ci/validate_style.sh 第27-28行:异常处理逻辑不完整。当 pip install vulture 失败时,脚本仅打印了告警信息但并未真正跳过后续执行。第28行 vulture --version 仍会执行并报错 "command not found"。虽然 set +e 不会导致脚本退出,但这会产生误导性的错误日志,违背了"skipping"的初衷。建议参照 validate_security.shpip-audit 的处理方式,增加 command -v vulture 的存在性检查。

💡 建议(1个可选)

  1. scripts/ci/validate_security.sh 第86行:代码冗余。在安装失败的错误处理块中执行 pip-audit --version 2>/dev/null || true 没有实际意义(因为安装失败时该命令肯定不可用),且后续第90行已经做了正确的存在性检查。建议删除该行以保持逻辑清晰。

格式检查通过 | 逻辑审查需修改 | 性能无明显问题


🤖 由 AI 代码审查机器人自动生成 | 2026-08-31 12:24:16 | 模型:

## 代码审查结果 - PR #1584 ### ⚠️ 问题(1个需要修改) 1. **scripts/ci/validate_style.sh 第27-28行**:异常处理逻辑不完整。当 `pip install vulture` 失败时,脚本仅打印了告警信息但并未真正跳过后续执行。第28行 `vulture --version` 仍会执行并报错 "command not found"。虽然 `set +e` 不会导致脚本退出,但这会产生误导性的错误日志,违背了"skipping"的初衷。建议参照 `validate_security.sh` 中 `pip-audit` 的处理方式,增加 `command -v vulture` 的存在性检查。 ### 💡 建议(1个可选) 1. **scripts/ci/validate_security.sh 第86行**:代码冗余。在安装失败的错误处理块中执行 `pip-audit --version 2>/dev/null || true` 没有实际意义(因为安装失败时该命令肯定不可用),且后续第90行已经做了正确的存在性检查。建议删除该行以保持逻辑清晰。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-31 12:24:16 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->

🚀 预览环境已部署

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

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

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

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

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

🗑️ 预览环境已清理

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

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

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