fix(ci): prevent auto-format bot from committing entire repository #1283

Merged
auto-approve-bot merged 1 commits from fix/auto-format-shallow-clone into develop 2026-08-08 12:47:00 +08:00
Owner

问题

CI 自动格式化 bot 偶尔会把整个仓库的文件加入 auto-format commit,原因是浅克隆 + git add -A 的组合问题。

根因

scripts/ci/auto_fix_formatting.py 的执行流程:

  1. 通过 tarball 下载代码(无 .git 目录)
  2. git init + git fetch --depth=1 浅克隆
  3. 浅克隆后工作区可能有 tarball 残留的未追踪文件
  4. git add -A(第335行)会把所有文件包括未追踪文件全部加入 commit

修复

两处修改,都在 scripts/ci/auto_fix_formatting.py

  1. git add 之前加 git clean -fd,清除未追踪文件
  2. git add -A 改为 git add -u,只 stage 已追踪文件的修改
# 原来(第335行):
run("git add -A")

# 改为:
run("git clean -fd")
run("git add -u")

影响

  • git clean -fd:删除未追踪的文件和目录
  • git add -u:只 stage 已追踪文件的修改、删除、重命名,不会添加新文件
  • 确保 auto-format commit 只包含格式修改的文件,不再包含整个仓库
## 问题 CI 自动格式化 bot 偶尔会把整个仓库的文件加入 auto-format commit,原因是浅克隆 + `git add -A` 的组合问题。 ## 根因 `scripts/ci/auto_fix_formatting.py` 的执行流程: 1. 通过 tarball 下载代码(无 `.git` 目录) 2. `git init` + `git fetch --depth=1` 浅克隆 3. 浅克隆后工作区可能有 tarball 残留的未追踪文件 4. `git add -A`(第335行)会把所有文件包括未追踪文件全部加入 commit ## 修复 两处修改,都在 `scripts/ci/auto_fix_formatting.py`: 1. 在 `git add` 之前加 `git clean -fd`,清除未追踪文件 2. 把 `git add -A` 改为 `git add -u`,只 stage 已追踪文件的修改 ```python # 原来(第335行): run("git add -A") # 改为: run("git clean -fd") run("git add -u") ``` ## 影响 - `git clean -fd`:删除未追踪的文件和目录 - `git add -u`:只 stage 已追踪文件的修改、删除、重命名,不会添加新文件 - 确保 auto-format commit 只包含格式修改的文件,不再包含整个仓库
xiaoxia added 1 commit 2026-08-07 21:08:10 +08:00
fix(ci): prevent auto-format bot from committing entire repository
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 / Check if frontend-only change (pull_request) Successful in 38s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 1m12s
AI Code Review / AI Code Review (pull_request) Successful in 1m12s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 1m15s
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m40s
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 2m0s
CI/CD Pipeline / Validate - Code Quality (pull_request) Failing after 3m22s
CI/CD Pipeline / Unit Tests (pull_request) Has been cancelled
CI/CD Pipeline / Integration Tests (pull_request) Has been cancelled
CI/CD Pipeline / PR Build API Image (pull_request) Has been cancelled
CI/CD Pipeline / PR Build Worker Image (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
PR Automation / Auto Approve on CI Green (pull_request) Has been cancelled
7e3671c06b
- Add git clean -fd before git add to remove untracked files
- Change git add -A to git add -u to only stage tracked files
- Fixes issue where shallow clone + tarball extraction leaves untracked
  files that get incorrectly included in auto-format commits

Fixes auto-format bot shallow clone issue

🚀 预览环境已部署

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

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

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

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

🚀 **预览环境已部署** | 项目 | 详情 | |------|------| | PR号 | #1283 | | 预览链接 | [https://pr-1283.preview.xiaoxiajianji.com](https://pr-1283.preview.xiaoxiajianji.com) | | API环境 | staging | > 💡 预览环境使用 staging API 数据,请勿在预览环境中操作重要数据。 > > 🔄 每次提交新代码后预览环境会自动更新。 > > 🗑️ PR 关闭或合并后,预览环境会自动清理。
auto-approve-bot added 1 commit 2026-08-07 21:11:33 +08:00
style: auto-format with black + isort + prettier [skip ci-format-check]
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 / Check if frontend-only change (pull_request) Successful in 1m12s
CI/CD Pipeline / Validate - Migration (alembic) (pull_request) Successful in 56s
AI Code Review / AI Code Review (pull_request) Successful in 1m34s
CI/CD Pipeline / Validate - Type Check (mypy) (pull_request) Successful in 2m24s
Preview Deploy / Deploy Preview Environment (pull_request) Successful in 1m25s
PR Automation / Auto Merge on CI Green + Approved (pull_request) Successful in 2m0s
CI/CD Pipeline / Deploy Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Frontend Lint (pull_request) Has been skipped
CI/CD Pipeline / Frontend Unit Tests (pull_request) Has been skipped
CI/CD Pipeline / PR Build Web Image (pull_request) Has been skipped
PR Automation / Auto Approve on CI Green (pull_request) Successful in 4m17s
CI/CD Pipeline / Validate - Code Quality (pull_request) Successful in 6m41s
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 / PR Build API Image (pull_request) Successful in 3m50s
CI/CD Pipeline / ACR Image Cleanup (pull_request) Has been skipped
CI/CD Pipeline / PR Build Worker Image (pull_request) Successful in 3m37s
CI/CD Pipeline / Integration Tests (pull_request) Successful in 3m32s
CI/CD Pipeline / Unit Tests (pull_request) Successful in 11m15s
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 Production (pull_request) Has been skipped
CI/CD Pipeline / Canary Release to Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
CI/CD Pipeline / CI Gate (pull_request) Successful in 40s
Preview Cleanup / Cleanup Preview Environment (pull_request) Successful in 58s
ACR Cleanup / ACR Image Cleanup (pull_request_target) Successful in 1m19s
4d7f47b463
Collaborator

【阻塞级判定】

  • 是否存在阻塞级问题:否
  • 阻塞级问题数量:0 个

📊 审查概览

  • 整体评价:通过
  • 建议级问题数量:0 个

🔴 阻塞级问题(必须修复)

💡 改进建议(不阻塞合并)

良好实践

  • 修复了文件末尾缺少换行符的问题,符合 POSIX 标准及大多数代码规范检查工具的要求。

🤖 由 AI 代码审查机器人自动生成 | 2026-08-07 13:15:05 | 模型:

### 【阻塞级判定】 - 是否存在阻塞级问题:否 - 阻塞级问题数量:0 个 ### 📊 审查概览 - 整体评价:通过 - 建议级问题数量:0 个 ### 🔴 阻塞级问题(必须修复) 无 ### 💡 改进建议(不阻塞合并) 无 ### ✅ 良好实践 - 修复了文件末尾缺少换行符的问题,符合 POSIX 标准及大多数代码规范检查工具的要求。 --- <sub>🤖 由 AI 代码审查机器人自动生成 | 2026-08-07 13:15:05 | 模型: </sub> <!-- AI_CODE_REVIEW_AUTO_COMMENT -->
auto-approve-bot approved these changes 2026-08-08 12:46:27 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot approved these changes 2026-08-08 12:46:27 +08:00
auto-approve-bot left a comment
Collaborator

CI全绿,自动审批通过。

CI全绿,自动审批通过。
auto-approve-bot merged commit d5bec6ebe5 into develop 2026-08-08 12:47:00 +08:00
auto-approve-bot deleted branch fix/auto-format-shallow-clone 2026-08-08 12:47:01 +08:00

🗑️ 预览环境已清理

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

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

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