Repository navigation
fix(crates): do not modify Cargo.toml during a dry run - #2550
Open
unknownhackerworld wants to merge 1 commit into
Open
unknownhackerworld wants to merge 1 commit into
unknownhackerworld wants to merge 1 commit into
Conversation
The version hook called bumpVersion before checking dryRun, and bumpVersion always wrote the new version to Cargo.toml. So `auto version --dry-run` and `auto shipit --dry-run` left a modified Cargo.toml behind. Pass dryRun to bumpVersion and skip the write.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What Changed
The crates plugin no longer writes to
Cargo.tomlwhenautoruns with--dry-run.bumpVersion(bumpBy, dryRun = false)inplugins/crates/src/index.tsnow returns the computed version before the write whendryRunis true.versionhook passes itsdryRunflag through tobumpVersion.Why
Root cause: in
plugins/crates/src/index.ts, theversionhook callsbumpVersion(bump)first and only checksdryRunafterwards.bumpVersionalways ends withfs.writeFileSync(filePath, contentNew). So the earlyreturnin the dry run branch skipscargo buildand the commit, but the new version is already written to disk.Core passes
dryRuninto theversionhook (packages/core/src/auto.ts,version()), and skipscheckClean()for dry runs, so this path runs forauto version --dry-runandauto shipit --dry-run. After a dry run with the crates plugin, the working tree has a modifiedCargo.tomlwith the next version. A later real run then starts from a dirty tree, and if the change gets committed by mistake the version is bumped twice.Fix: keep the version calculation (so the dry run can still log or print the version it would publish) and skip only the file write.
Tradeoffs and alternatives:
dryRunparameter instead of splittingbumpVersioninto separate compute and write functions.bumpVersionis exported, and the optional parameter keeps its current signature and behavior for existing callers.semver.incwhendryRunis set. That would duplicate the read and parse logic and the "Could not increment" error handling, so I kept it in one place.Testing
bumpVersion(SEMVER.minor, true)returns1.3.0and does not callwriteFileSync.versionwithdryRun: truedoes not callwriteFileSyncor run any command (cargo build,git add,git commit).mainand pass with this change.npx jest plugins/crates: 16 passed.npx eslint plugins/crates --ext .ts,npx tsc -b plugins/cratesandprettier --checkon the changed files are clean.cargo publishflow.Disclosure: this change was found and written with help from an AI coding assistant.
Todo:
Change Type
Indicate the type of change your pull request is:
documentationpatchminormajor