fix(ci): 修复integration-tests needs依赖 + push事件auto-fix支持 #766

Merged
xiaoxia merged 1 commits from fix/ci-systematic-p0-round2 into develop 2026-07-23 22:33:23 +08:00
Owner

变更内容

任务1:修复integration-tests的needs依赖bug

  • integration-tests job的needs里写了不存在的validate job
  • 替换为3个真实存在的job:validate-code-qualityvalidate-type-checkvalidate-migration
  • 效果:集成测试等代码检查通过了再跑,不浪费资源

任务2:Code Quality auto-fix 在push事件也生效

  • 之前auto-fix只在PR事件运行,push到develop后格式不对就永远红着
  • 新增push事件支持:develop/main等受保护分支push时,如果ruff/black格式不通过,自动修复并push回原分支
  • 只改格式问题,不动业务逻辑

改动文件

  • .gitea/workflows/ci-pipeline.yml
  • scripts/ci/auto_fix_formatting.py
## 变更内容 ### 任务1:修复integration-tests的needs依赖bug - `integration-tests` job的`needs`里写了不存在的`validate` job - 替换为3个真实存在的job:`validate-code-quality`、`validate-type-check`、`validate-migration` - 效果:集成测试等代码检查通过了再跑,不浪费资源 ### 任务2:Code Quality auto-fix 在push事件也生效 - 之前auto-fix只在PR事件运行,push到develop后格式不对就永远红着 - 新增push事件支持:develop/main等受保护分支push时,如果ruff/black格式不通过,自动修复并push回原分支 - 只改格式问题,不动业务逻辑 ## 改动文件 - `.gitea/workflows/ci-pipeline.yml` - `scripts/ci/auto_fix_formatting.py`
auto-approve-bot approved these changes 2026-07-23 18:50:36 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-07-23 18:50:36 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
xiaoxia added 1 commit 2026-07-23 21:52:32 +08:00
fix(ci): 修复integration-tests needs依赖 + push事件auto-fix支持
CI/CD Pipeline / Check if frontend-only change (pull_request) Successful in 21s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m13s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m10s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 30s
CI/CD Pipeline / PR Build Web Image (pull_request) Successful in 10s
CI/CD Pipeline / Build Staging API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Staging Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 4m56s
Preview Deploy / Deploy Preview Environment (pull_request) Failing after 24s
CI/CD Pipeline / PR Build API Image (pull_request) Successful in 3m45s
AI Code Review / AI Code Review (pull_request) Successful in 3m51s
PR Automation / Auto Approve on CI Green (pull_request) Successful in 3m25s
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / Build Production API Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Web Image (pull_request) Has been skipped
CI/CD Pipeline / Build Production Worker Image (pull_request) Has been skipped
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 9m29s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 2m34s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 5m27s
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 6s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 49m24s
c1a5f52004
xiaoxia force-pushed fix/ci-systematic-p0-round2 from 75ed2dceec to c1a5f52004 2026-07-23 21:52:32 +08:00 Compare
Collaborator

代码审查结果 - PR #766

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

  1. scripts/ci/auto_fix_formatting.py 第79-83行:Git仓库存在时未配置写权限Remote URL

    • 问题描述:当检测到 .git 目录已存在时(第79行),函数仅执行 checkout 后直接返回,跳过了后续配置 remote_url 的步骤(第96行)。如果CI环境复用了缓存的 .git 目录,或者默认 actions/checkout 使用的 Token 只有读权限,后续的 git push 操作将因认证失败(403 Forbidden)或权限不足而报错。
    • 后果:导致在特定CI环境下(如使用了自托管Runner且缓存了Git目录),自动修复功能无法推送代码。
  2. scripts/ci/auto_fix_formatting.py 第82行:分支切换失败未做错误处理

    • 问题描述:代码使用了 check=False 执行 git checkout,如果切换分支失败(例如本地有未提交的修改导致冲突,或者分支名拼写错误),脚本不会抛出异常,而是静默继续执行。
    • 后果:脚本可能会在错误的分支上执行代码格式化,或者后续的 git push 推送到错误的提交,导致代码混乱。

💡 建议(3个可选)

  1. scripts/ci/auto_fix_formatting.py 第227-230行:API请求建议增加异常捕获

    • 具体内容:urllib.request.urlopen 请求可能会因网络波动、API限流或权限问题抛出异常。建议使用 try-except 捕获这些异常,打印明确的错误日志并优雅退出,避免抛出难以追踪的 StackTrace。
  2. scripts/ci/auto_fix_formatting.py 第206行:Token有效性校验

    • 具体内容:虽然脚本在后续使用 token 时会失败,但建议在获取环境变量后立即检查 if not token: 并报错退出,以便更早发现配置问题。
  3. scripts/ci/auto_fix_formatting.py 第96行:Remote URL配置逻辑优化

    • 具体内容:新增的 ensure_git_repo_for_push 函数中,使用 git remote add origin 可能会在 remote 已存在时报错。建议使用 git remote set-url origin ... 或先检查 remote 是否存在,以支持重试场景。

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


🤖 由 AI 代码审查机器人自动生成 | 2026-07-23 14:04:00 | 模型:

## 代码审查结果 - PR #766 ### ⚠️ 问题(2个需要修改) 1. **scripts/ci/auto_fix_formatting.py 第79-83行**:Git仓库存在时未配置写权限Remote URL - 问题描述:当检测到 `.git` 目录已存在时(第79行),函数仅执行 `checkout` 后直接返回,跳过了后续配置 `remote_url` 的步骤(第96行)。如果CI环境复用了缓存的 `.git` 目录,或者默认 `actions/checkout` 使用的 Token 只有读权限,后续的 `git push` 操作将因认证失败(403 Forbidden)或权限不足而报错。 - 后果:导致在特定CI环境下(如使用了自托管Runner且缓存了Git目录),自动修复功能无法推送代码。 2. **scripts/ci/auto_fix_formatting.py 第82行**:分支切换失败未做错误处理 - 问题描述:代码使用了 `check=False` 执行 `git checkout`,如果切换分支失败(例如本地有未提交的修改导致冲突,或者分支名拼写错误),脚本不会抛出异常,而是静默继续执行。 - 后果:脚本可能会在错误的分支上执行代码格式化,或者后续的 `git push` 推送到错误的提交,导致代码混乱。 ### 💡 建议(3个可选) 1. **scripts/ci/auto_fix_formatting.py 第227-230行**:API请求建议增加异常捕获 - 具体内容:`urllib.request.urlopen` 请求可能会因网络波动、API限流或权限问题抛出异常。建议使用 `try-except` 捕获这些异常,打印明确的错误日志并优雅退出,避免抛出难以追踪的 StackTrace。 2. **scripts/ci/auto_fix_formatting.py 第206行**:Token有效性校验 - 具体内容:虽然脚本在后续使用 `token` 时会失败,但建议在获取环境变量后立即检查 `if not token:` 并报错退出,以便更早发现配置问题。 3. **scripts/ci/auto_fix_formatting.py 第96行**:Remote URL配置逻辑优化 - 具体内容:新增的 `ensure_git_repo_for_push` 函数中,使用 `git remote add origin` 可能会在 remote 已存在时报错。建议使用 `git remote set-url origin ...` 或先检查 remote 是否存在,以支持重试场景。 --- ✅ 格式检查通过 | ❌ 逻辑审查需修改 | ✅ 性能无明显问题 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-07-23 14:04:00 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
xiaoxia merged commit a009cd382a into develop 2026-07-23 22:33:23 +08:00

🗑️ 预览环境已清理

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

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

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