You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
git status > git.txt
该流程存在明显问题:CI 文件检查脚本本应只读地获取当前分支相对于目标分支的差异文件,但上述实现会改变当前仓库状态。通过临时 Git 仓库复现可以观察到:执行 get_new_file() 前,feature 分支 HEAD 位于新增文件提交上且 git status --short 为空;执行后,feature 分支 HEAD 被重置回基线提交,新增文件被重新置为 staged 状态,并且工作区留下 git.txt 临时文件。
这会导致 CI 后续步骤基于被修改过的 HEAD、index 或 working tree 继续运行,可能引起误检、漏检或污染后续检查环境。该问题属于 CI 辅助脚本的普通软件缺陷,不涉及功能新增,也不涉及安全漏洞。
此外,tools/ci/format_ignore.py 和 tools/ci/compile_bsp_with_drivers.py 原先直接使用 git diff HEAD origin/master 获取差异文件,存在以下问题:
基线分支硬编码为 origin/master,在 fork、不同 remote 名称或 CI 目标分支变化时不够可靠;
空 diff 可能被解析为 [''],导致后续出现空路径处理;
Git 命令失败时缺少统一处理,容易继续使用不可靠输出。
因此,本 PR 将相关 CI 脚本的 changed-file detection 改为统一、只读、可配置且失败可感知的实现。
你的解决方案是什么 (what is your solution)
本 PR 新增 tools/ci/ci_common.py,提供一组共享的只读 Git diff helper,并将相关 CI 脚本迁移到该公共实现。
主要修改如下:
新增 tools/ci/ci_common.py
新增公共 helper,用于统一处理 CI 脚本中的 Git 差异文件检测逻辑,包括:
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!
为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).
设置需排除的文件/目录(目录请以"/"结尾)
Set files/directories to exclude (directories should end with "/")
将目标分支设置为 \ Set the target branch to:bugfix-ci-tooling-robustness
设置PR number为 \ Set the PR number to:11586
等待工作流完成 | Wait for the workflow to complete
格式化后的代码将自动推送至你的分支。
The formatted code will be automatically pushed to your branch.
完成后,提交将自动更新至 bugfix-ci-tooling-robustness 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the bugfix-ci-tooling-robustness branch automatically, and the related Pull Request will be updated.
如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
本 PR 修复
tools/ci中变更文件检测逻辑会修改 Git 工作区状态的问题。当前
tools/ci/file_check.py::CheckOut.get_new_file()原本通过以下流程获取变更文件:git remote add rtt_repo ...git fetch rtt_repogit merge rtt_repo/<branch>git reset rtt_repo/<branch> --softgit status > git.txt该流程存在明显问题:CI 文件检查脚本本应只读地获取当前分支相对于目标分支的差异文件,但上述实现会改变当前仓库状态。通过临时 Git 仓库复现可以观察到:执行
get_new_file()前,feature 分支 HEAD 位于新增文件提交上且git status --short为空;执行后,feature 分支 HEAD 被重置回基线提交,新增文件被重新置为 staged 状态,并且工作区留下git.txt临时文件。这会导致 CI 后续步骤基于被修改过的 HEAD、index 或 working tree 继续运行,可能引起误检、漏检或污染后续检查环境。该问题属于 CI 辅助脚本的普通软件缺陷,不涉及功能新增,也不涉及安全漏洞。
此外,
tools/ci/format_ignore.py和tools/ci/compile_bsp_with_drivers.py原先直接使用git diff HEAD origin/master获取差异文件,存在以下问题:origin/master,在 fork、不同 remote 名称或 CI 目标分支变化时不够可靠;[''],导致后续出现空路径处理;因此,本 PR 将相关 CI 脚本的 changed-file detection 改为统一、只读、可配置且失败可感知的实现。
你的解决方案是什么 (what is your solution)
本 PR 新增
tools/ci/ci_common.py,提供一组共享的只读 Git diff helper,并将相关 CI 脚本迁移到该公共实现。主要修改如下:
tools/ci/ci_common.py新增公共 helper,用于统一处理 CI 脚本中的 Git 差异文件检测逻辑,包括:
run_git():使用subprocess.run(["git", ...])执行 Git 命令,不使用shell=True,不使用os.system,并返回结构化结果;resolve_target_ref():支持通过RTT_CI_TARGET_REF指定目标基线分支,默认保持兼容origin/master;get_merge_base():只读获取目标分支和当前 HEAD 的 merge-base;get_changed_files():使用git merge-base+git diff --name-only获取变更文件;get_changed_files_between():支持显式指定 base/head ref;normalize_changed_files():统一处理空 diff,过滤空行,并规范化路径分隔符;maybe_fetch_remote():用于兼容file_check.py原有传入rtt_repo/rtt_branch的调用方式;当 remote 不存在时添加 remote,当 remote 已存在但 URL 不一致时更新 URL,然后 fetch refs。该过程只会影响.git/config和FETCH_HEAD,不会修改 HEAD、index 或 working tree。tools/ci/file_check.py保留原有
CheckOut类名和__init__(rtt_repo, rtt_branch)接口,避免破坏现有调用方式。修改
get_new_file()的实现:git merge;git reset --soft;git status > git.txt临时文件流程;None,避免继续使用不可靠结果;[];tools/ci/format_ignore.py将原先硬编码的:
origin/master;RTT_CI_TARGET_REF配置目标基线;[];None,由调用方处理;tools/ci/compile_bsp_with_drivers.py将
diff()中硬编码的git diff HEAD origin/master替换为公共 helper。同时调整失败处理逻辑:
set(),表示没有需要重新编译的 BSP;None;diff()返回None时以错误退出,避免把 Git 失败误当作“没有 BSP 需要编译”。整体修复后,CI changed-file detection 变为只读操作,不再修改 HEAD、index 或 working tree,也不会留下
git.txt临时文件;同时多个 CI 脚本复用统一实现,避免不同脚本间的 diff 语义不一致。请提供验证的bsp和config (provide the config and bsp)
本 PR 为
tools/ci辅助脚本修复,不涉及具体 BSP 源码、板级配置或硬件相关改动,因此无特定 BSP 要求。验证类型为 CI helper 脚本级验证。
本 PR 不修改任何 BSP 的
.config,也不要求开启或关闭额外配置项。无
.config变更。本 PR 修改的是 CI helper 脚本逻辑,已完成本地脚本级验证。PR 创建后可由 GitHub Actions 自动触发进一步检查。
本地已完成以下验证:
Python 语法检查:
python -m py_compile tools\ci\ci_common.py tools\ci\file_check.py tools\ci\format_ignore.py tools\ci\compile_bsp_with_drivers.py tools\ci\cpp_check.py结果:通过,无语法错误。
Git diff whitespace 检查:
结果:通过,无 whitespace error。
临时 Git 仓库复现验证:
构造临时 base/work 仓库:
base/master中包含基础提交;work/feature中新增并提交test.c;file_check.py::CheckOut.get_new_file()获取 changed files。修复前行为:
get_new_file()会将 feature 分支 HEAD 重置回 base/master;test.c变为 staged 状态;git.txt临时文件。修复后行为:
file_check.py::CheckOut.get_new_file()正确返回['test.c'];git status --short保持为空;git.txt;format_ignore.py::CheckOut.get_new_file()同样能返回 changed file,并且不修改仓库状态;compile_bsp_with_drivers.py::diff()在空 diff 时返回空set();compile_bsp_with_drivers.py::diff()在 Git 失败时返回None,不会再把失败误当作空变更成功处理。提交前检查:
确认仅包含以下 4 个相关文件:
tools/ci/ci_common.pytools/ci/file_check.pytools/ci/format_ignore.pytools/ci/compile_bsp_with_drivers.py未修改 Rust 相关代码,未修改 BSP,未修改无关组件,未提交临时复现仓库或构建产物。
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up