Skip to content

fix(release): update-versions.py 同一文件多条规则互相覆盖#59

Merged
ThirteenLLB merged 2 commits into
wuji-technology:mainfrom
wuji-tech-dev:fix/update-versions-same-file-rules
Jul 14, 2026
Merged

fix(release): update-versions.py 同一文件多条规则互相覆盖#59
ThirteenLLB merged 2 commits into
wuji-technology:mainfrom
wuji-tech-dev:fix/update-versions-same-file-rules

Conversation

@wuji-tech-dev

@wuji-tech-dev wuji-tech-dev commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

问题

update-versions.py 阶段 1 对每条规则都从磁盘读原始内容、独立计算替换结果,阶段 2 依次写盘。同一文件配多条规则时,后写的结果基于原始内容,会把先写的替换覆盖掉——只有最后一条规则生效,脚本却仍报「成功更新 N 个版本号文件」,属静默丢改动。

复现(当前 main 版脚本):

version_files:
  - path: "sample.txt"
    pattern: '(name = "aaa"\nversion = ")[^"]+(")'
  - path: "sample.txt"
    pattern: '(name = "bbb"\nversion = ")[^"]+(")'

执行后只有 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

  • 改进
    • 优化版本更新流程:按同一文件累积替换结果,使多条规则可连续生效,避免后续覆盖前序替换内容。
    • 改善预览模式:在试运行时展示替换前后差异,并输出去重后的更新版本文件列表。
    • 提升批量写入的可靠性与可诊断性:非试运行时每个文件仅写入一次,写入失败时提供相对路径错误信息。
  • 构建与发布
    • 调整发布流程中版本文件路径的去重与列表生成逻辑,避免重复路径影响后续提交与变更说明内容。

此前阶段 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>
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1d22e327-732a-432f-bd98-520289b4e2df

📥 Commits

Reviewing files that changed from the base of the PR and between 655a19d and 418c078.

📒 Files selected for processing (1)
  • .github/workflows/centralized-release.yml

Walkthrough

版本更新脚本按文件累积替换内容,同一文件的多条规则连续生效;实际写入每个文件仅执行一次,dry-run 返回去重排序后的文件列表。发布工作流在暂存文件和 PR 正文中去重版本文件路径。

Changes

版本更新与发布流程

Layer / File(s) Summary
累积替换与文件写入
scripts/update-versions.py
按文件缓存并连续应用替换结果;非 dry-run 每个文件只写入一次,dry-run 输出逐条预览并对更新文件路径去重排序。
发布路径去重
.github/workflows/centralized-release.yml
创建发布分支和 Pull Request 时,对 version_files 中的路径去重。

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

小兔挥爪改版本,
文件内容层层连。
同档规则不相覆,
发布路径不重叠。
Dry-run 展示新旧篇,
胡萝卜庆更新圆。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题符合 Conventional Commits 格式,并且准确概括了同一文件多条规则互相覆盖的修复。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wuji-tech-dev

Copy link
Copy Markdown
Contributor Author

配套 PR:wuji-technology/wuji-sdk-dev#521(Cargo.lock 逐 crate 同步规则,依赖本修复)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
scripts/update-versions.py (1)

195-196: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

统一 dry_run 和实际写入时返回的 updated 路径格式与顺序。

当前实现中,dry_runTrue 时返回的 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

📥 Commits

Reviewing files that changed from the base of the PR and between 22046cd and 655a19d.

📒 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>
@wuji-tech-dev

Copy link
Copy Markdown
Contributor Author

追加一个 commit(自查时发现):

  1. workflow 两处 version_files 路径去重 — 同一文件配多条规则时(sdk-dev 的 Cargo.lock 会配 11 条),发版 PR body 会把 Cargo.lock 列 11 遍、staging 日志刷 11 行重复。
  2. 修存量 bug:PR body 的版本文件列表一直是空的python -c "..." 双引号串里的反引号未转义,被 shell 当命令替换执行({p}: command not found),vfiles 拿到的是空逗号串。本地已复现,加 \ 转义后输出正常:Cargo.toml`, `Cargo.lock

两段代码已在 sdk-dev / cli-dev 真实配置上实测。

@ThirteenLLB
ThirteenLLB merged commit 8ccc2e9 into wuji-technology:main Jul 14, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants