fix(scripts): exclude auto-maintained-file-only commits from generated changelogs#490
fix(scripts): exclude auto-maintained-file-only commits from generated changelogs#490kate-shine wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Updates the crate release script’s changelog generation so that commits are only attributed to a crate when they modify at least one non auto-maintained file within that crate, preventing unrelated changelog entries caused by workspace-wide README regeneration.
Changes:
- Collect commit hashes affecting a crate folder, then filter to commits that touch at least one non-auto-maintained file.
- Treat
README.mdandCHANGELOG.mdas auto-maintained for the purpose of crate changelog attribution.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| $autoMaintainedFiles = @('README.md', 'CHANGELOG.md') | ||
|
|
||
| $rawCommits = @() | ||
| foreach ($hash in $commitHashes) { | ||
| $changedFiles = @(Invoke-GitCommand -Command "show $hash --name-only --pretty=format: -- `"$crateFolder`"" -ErrorMessage "Failed to retrieve changed files for commit $hash" | Where-Object { $_ }) | ||
| $hasMeaningfulChange = $false | ||
| foreach ($file in $changedFiles) { | ||
| if ($autoMaintainedFiles -notcontains (Split-Path $file -Leaf)) { | ||
| $hasMeaningfulChange = $true | ||
| break | ||
| } | ||
| } |
There was a problem hiding this comment.
GHCP: Good catch — fixed in 4a30857. The filter now only treats the crate-ROOT README.md/CHANGELOG.md as auto-maintained: a file counts as auto-maintained iff its leaf is README.md/CHANGELOG.md AND its parent directory is the package folder itself. Nested docs like crates//examples/README.md now correctly count as meaningful changes. Added a regression test (keeps a commit that touches a NESTED README.md). Note: the change moved from the now-deleted scripts/release-crate.ps1 to scripts/lib/release-flow.ps1 (Write-Changelog) after the release-tooling refactor on main.
| $rawCommits = @() | ||
| foreach ($hash in $commitHashes) { | ||
| $changedFiles = @(Invoke-GitCommand -Command "show $hash --name-only --pretty=format: -- `"$crateFolder`"" -ErrorMessage "Failed to retrieve changed files for commit $hash" | Where-Object { $_ }) |
There was a problem hiding this comment.
GHCP: Done in 4a30857. Replaced the 1 git log + up-to-2 git show-per-commit pattern with a single git log --name-only --pretty=format:%H%s, parsing the record (0x1e) / unit (0x1f) separators and per-commit file lists in PowerShell. Git is now invoked once regardless of range size. Verified against real history (templated_uri v0.2.3..v0.3.0) — reproduces the expected keep/drop set.
…d changelogs just readme regenerates every crate's README.md workspace-wide, so a commit that only introduced an unrelated package still touches this package's folder via that regeneration. Path-scoped git log then leaked its subject into the wrong changelog. Skip commits whose only in-folder changes are README.md/CHANGELOG.md. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d2faf92 to
c923f23
Compare
…e-root docs only Address review on PR #490: - Only crate-root README.md/CHANGELOG.md are auto-maintained; nested files like crates/<pkg>/examples/README.md (matched solely by leaf name before) are hand-authored and must count as meaningful changes. Now match on the parent directory being the package folder. - Replace the per-commit 'git show' calls (1 log + up to 2 show per commit) with a single 'git log --name-only', parsing record/unit separators in PowerShell, so large ranges no longer fan out into many git processes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #490 +/- ##
=====================================
Coverage 99.9% 99.9%
=====================================
Files 336 336
Lines 24829 24829
=====================================
Hits 24818 24818
Misses 11 11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…t leaf Address follow-up review on PR #490: comparing only the parent directory's leaf name to the package folder name misclassifies crates/<pkg>/<pkg>/README.md as the crate root. Build the exact repo-relative crate-root paths (crates/<pkg>/README.md, crates/<pkg>/CHANGELOG.md) from the package folder's last two segments and require a full-path match. Added a regression test for the same-leaf-and-parent nested case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
| $content | Should -Match 'nested same-named readme' | ||
| } | ||
|
|
||
| It 'warns and writes nothing when every in-range commit is crate-root README-only' { |
| if ($hasMeaningfulChange) { | ||
| $rawCommits += $subject | ||
| } |
Problem
The release tooling sometimes added unrelated entries to a package's CHANGELOG.
Root cause:
just readmerunscargo doc2readmeworkspace-wide, so it regenerates every crate'sREADME.md(the opaque[__cargo_doc2readme_dependencies_info]blob) on any change. A commit that only introduced an unrelated package therefore stilltouchesthis package's folder via that README regeneration. The path-scopedgit log -- <folder>used byWrite-Changelogthen attributed that commit's subject to the wrong changelog.Concrete example: commit #450 (
introduce fetch_tls crate) touched onlycrates/templated_uri/README.mdyet leaked intotemplated_uri's changelog.Fix
In
scripts/lib/release-flow.ps1(Write-Changelog), exclude a commit iff every file it changed within the package folder is an auto-maintained file (README.md/CHANGELOG.md). Commits that also touchsrc/etc. are kept.Tests
Added a
Write-Changelog commit filteringregression block inscripts/tests/Pester/unit/releasing/WriteChangelog.Tests.ps1:All 150
unit/releasingPester tests pass.