fix(release): update-versions.py 同一文件多条规则互相覆盖#59
Conversation
此前阶段 1 每条规则都从磁盘读原始内容独立计算替换结果,阶段 2 依次写盘, 同一文件配多条规则时后写的会覆盖先写的——只有最后一条规则生效, 且脚本仍报「成功」,属静默丢改动。 改为同一文件的多条规则在内存中累积应用:每个文件只读一次、阶段 2 只写一次。 单文件单规则的既有仓库(wuji-sdk-dev/wuji-studio-dev/wuji-cli-dev)行为不变。 场景:wuji-sdk-dev 是 workspace,Cargo.lock 里 11 个成员 crate 条目 需要各配一条规则,全部落在同一个文件上,没有本修复则只有最后一条生效。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
Walkthrough版本更新脚本按文件累积替换内容,同一文件的多条规则连续生效;实际写入每个文件仅执行一次,dry-run 返回去重排序后的文件列表。发布工作流在暂存文件和 PR 正文中去重版本文件路径。 Changes版本更新与发布流程
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
配套 PR:wuji-technology/wuji-sdk-dev#521(Cargo.lock 逐 crate 同步规则,依赖本修复) |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
scripts/update-versions.py (1)
195-196: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win统一
dry_run和实际写入时返回的updated路径格式与顺序。当前实现中,
dry_run为True时返回的updated列表是去重且按字母排序的原始路径,而实际写入时返回的是按规则首次出现顺序排序且经过relative_to标准化后的路径。为了保证两种模式下返回的数据结构完全一致,建议在
dry_run时也直接从file_contents的键提取标准化后的路径。这能天然实现去重,并保留与实际写入完全相同的原始文件处理顺序及路径格式。💡 建议的重构
- if dry_run: - updated = sorted({e['path'] for e in version_files}) + if dry_run: + updated = [str(file_path.relative_to(config_dir)) for file_path in file_contents.keys()]🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@scripts/update-versions.py` around lines 195 - 196, Update the dry_run branch in the version-update flow to derive updated from file_contents keys, applying the same relative_to path normalization and insertion order used by the actual-write path. Remove the sorted set-comprehension so dry_run preserves first-seen ordering and produces the identical standardized path format and deduplication behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@scripts/update-versions.py`:
- Around line 195-196: Update the dry_run branch in the version-update flow to
derive updated from file_contents keys, applying the same relative_to path
normalization and insertion order used by the actual-write path. Remove the
sorted set-comprehension so dry_run preserves first-seen ordering and produces
the identical standardized path format and deduplication behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7716fe59-b49f-409b-87b7-fc47453f3172
📒 Files selected for processing (1)
scripts/update-versions.py
- .release.yml 同一文件配多条规则时(如 Cargo.lock 多个 crate 条目),
staging 日志和 PR body 会重复列同一路径,按 path 去重
- PR body 生成处 python -c 双引号串里的反引号未转义,被 shell 当命令
替换执行({p}: command not found),版本文件列表一直渲染成空逗号串,
补反斜杠转义(存量 bug,本地已复现并验证修复)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
追加一个 commit(自查时发现):
两段代码已在 sdk-dev / cli-dev 真实配置上实测。 |
问题
update-versions.py阶段 1 对每条规则都从磁盘读原始内容、独立计算替换结果,阶段 2 依次写盘。同一文件配多条规则时,后写的结果基于原始内容,会把先写的替换覆盖掉——只有最后一条规则生效,脚本却仍报「成功更新 N 个版本号文件」,属静默丢改动。复现(当前 main 版脚本):
执行后只有
bbb被更新,aaa原样,退出码 0。修复
同一文件的多条规则在内存中累积应用:每个文件只读一次,规则按序作用在上一条的结果上,阶段 2 每个文件只写一次。错误语义不变:任一规则不匹配即报错退出,不写任何文件(已实测)。
兼容性
现有三个使用方(wuji-sdk-dev / wuji-studio-dev / wuji-cli-dev)的
.release.yml均为单文件单规则,行为完全不变(已用 cli-dev / sdk-dev 真实仓库回归,diff 一致)。动机
wuji-sdk-dev 是 workspace,要把发版版本号同步进
Cargo.lock需要给 11 个成员 crate 条目各配一条规则、全部落在同一个 Cargo.lock 上(wuji-technology/wuji-sdk-dev 侧的配套 PR 依赖本修复,将在评论区关联)。🤖 Generated with Claude Code
Summary by CodeRabbit