-
-
Notifications
You must be signed in to change notification settings - Fork 175
Add --what-if option to prepare-release command for simulating version changes #1242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
d6eba4a
49e89ab
407eb5a
c5a8605
28d04ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,10 @@ private static RootCommand BuildCommandLine() | |
{ | ||
Description = "A custom message to use for the commit that changes the version number. May include {0} for the version number. If not specified, the default is \"Set version to '{0}'\".", | ||
}; | ||
var whatIf = new Option<bool>("--what-if", Array.Empty<string>()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot Let's drop the optional There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! I've removed all the optional |
||
{ | ||
Description = "Simulates the prepare-release operation and prints the new version that would be set, but does not actually make any changes.", | ||
}; | ||
var tagArgument = new Argument<string>("tag") | ||
{ | ||
Description = "The prerelease tag to apply on the release branch (if any). If not specified, any existing prerelease tag will be removed. The preceding hyphen may be omitted.", | ||
|
@@ -351,6 +355,7 @@ private static RootCommand BuildCommandLine() | |
versionIncrement, | ||
format, | ||
unformattedCommitMessage, | ||
whatIf, | ||
tagArgument, | ||
}; | ||
|
||
|
@@ -362,7 +367,8 @@ private static RootCommand BuildCommandLine() | |
var formatValue = parseResult.GetValue(format); | ||
var tagArgumentValue = parseResult.GetValue(tagArgument); | ||
var unformattedCommitMessageValue = parseResult.GetValue(unformattedCommitMessage); | ||
return await OnPrepareReleaseCommand(projectValue, nextVersionValue, versionIncrementValue, formatValue, tagArgumentValue, unformattedCommitMessageValue); | ||
var whatIfValue = parseResult.GetValue(whatIf); | ||
return await OnPrepareReleaseCommand(projectValue, nextVersionValue, versionIncrementValue, formatValue, tagArgumentValue, unformattedCommitMessageValue, whatIfValue); | ||
}); | ||
} | ||
|
||
|
@@ -883,7 +889,7 @@ private static Task<int> OnCloudCommand(string project, string[] metadata, strin | |
return Task.FromResult((int)ExitCodes.OK); | ||
} | ||
|
||
private static Task<int> OnPrepareReleaseCommand(string project, string nextVersion, string versionIncrement, string format, string tag, string unformattedCommitMessage) | ||
private static Task<int> OnPrepareReleaseCommand(string project, string nextVersion, string versionIncrement, string format, string tag, string unformattedCommitMessage, bool whatIf) | ||
{ | ||
// validate project path property | ||
string searchPath = GetSpecifiedOrCurrentDirectoryPath(project); | ||
|
@@ -949,11 +955,27 @@ private static Task<int> OnPrepareReleaseCommand(string project, string nextVers | |
} | ||
} | ||
|
||
// run prepare-release | ||
// run prepare-release or simulate | ||
try | ||
{ | ||
var releaseManager = new ReleaseManager(Console.Out, Console.Error); | ||
releaseManager.PrepareRelease(searchPath, tag, nextVersionParsed, versionIncrementParsed, outputMode, unformattedCommitMessage); | ||
|
||
if (whatIf) | ||
{ | ||
// Simulate the release without making changes | ||
ReleaseManager.ReleaseInfo simulationResult = releaseManager.SimulatePrepareRelease(searchPath, tag, nextVersionParsed, versionIncrementParsed, outputMode); | ||
|
||
if (outputMode == ReleaseManager.ReleaseManagerOutputMode.Json) | ||
{ | ||
releaseManager.WriteToOutput(simulationResult); | ||
} | ||
} | ||
else | ||
{ | ||
// Actually perform the release | ||
releaseManager.PrepareRelease(searchPath, tag, nextVersionParsed, versionIncrementParsed, outputMode, unformattedCommitMessage); | ||
} | ||
|
||
return Task.FromResult((int)ExitCodes.OK); | ||
} | ||
catch (ReleaseManager.ReleasePreparationException ex) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Instead of creating a whole new method that duplicates a bunch of logic and needs to be kept in sync between the two methods, please add a parameter to the existing
PrepareRelease
method, or have these two methods call a 3rd private helper method that has most of the logic and takes awhatIf
switch.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I've refactored the code to use a single
PrepareRelease
method with awhatIf
parameter instead of duplicating logic in a separateSimulatePrepareRelease
method. The implementation now uses a privatePrepareReleaseCore
helper method that contains all the shared logic and takes thewhatIf
parameter to determine whether to actually make git changes or just simulate them. This eliminates code duplication and keeps the two code paths in sync automatically. Fixed in commit 28d04ed.