-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor versioning in build / release scripts.
Signed-off-by: Riccardo De Agostini <[email protected]>
- Loading branch information
Showing
11 changed files
with
493 additions
and
313 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
#load "./build/process.cake" | ||
#load "./build/public-api.cake" | ||
#load "./build/setup-teardown.cake" | ||
#load "./build/version.cake" | ||
#load "./build/versioning.cake" | ||
#load "./build/workspace.cake" | ||
|
||
#nullable enable | ||
|
@@ -70,10 +70,17 @@ Task("Release") | |
.Description("Publish a new public release (CI only)") | ||
.Does<BuildData>(async (context, data) => { | ||
// Preliminary checks | ||
// Perform some preliminary checks | ||
Ensure(data.IsCI, "The Release target cannot run on a local system."); | ||
Ensure(data.IsPublicRelease, "Cannot create a release from the current branch."); | ||
// Compute the version spec change to apply, if any | ||
// This implies more checks and possibly throws, so do it as early as possible | ||
var versionSpecChange = context.ComputeVersionSpecChange( | ||
currentVersion: data.Version, | ||
requestedChange: context.GetOption<VersionSpecChange>("versionSpecChange", VersionSpecChange.None), | ||
checkPublicApi: context.GetOption<bool>("checkPublicApi", true)); | ||
// Identify Git user for later push if needed | ||
context.GitSetUserIdentity("Buildvana", "[email protected]"); | ||
|
@@ -83,36 +90,18 @@ Task("Release") | |
var committed = false; | ||
try | ||
{ | ||
// Advance version if requested. | ||
var versionAdvance = context.GetOption<VersionAdvance>("versionAdvance", VersionAdvance.None); | ||
if (context.GetOption<bool>("checkPublicApi", true)) | ||
// Modify version if required. | ||
if (versionSpecChange != VersionSpecChange.None) | ||
{ | ||
var requiredVersionAdvance = context.GetMaxPublicApiRequiredVersionAdvance(); | ||
Ensure(versionAdvance >= requiredVersionAdvance, $"Changes to public API require a minimum version advance of {requiredVersionAdvance}."); | ||
} | ||
if (versionAdvance != VersionAdvance.None) | ||
{ | ||
context.Information($"Version advance requested: {versionAdvance}."); | ||
var versionFile = VersionFile.Load(); | ||
var previousVersionSpec = versionFile.VersionSpec; | ||
if (versionFile.AdvanceVersion(versionAdvance)) | ||
if (versionFile.ApplyVersionSpecChange(context, versionSpecChange)) | ||
{ | ||
context.Information($"Version advanced from {previousVersionSpec} to {versionFile.VersionSpec}."); | ||
versionFile.Save(); | ||
UpdateRepo(versionFile.Path); | ||
} | ||
else | ||
{ | ||
context.Information("Version not changed."); | ||
} | ||
} | ||
else | ||
{ | ||
context.Information("No version advance requested."); | ||
} | ||
// Update public API files only on non-prerelease | ||
// Update public API files only when releasing a stable version | ||
if (!data.IsPrerelease) | ||
{ | ||
var modified = context.TransferAllPublicApiToShipped().ToArray(); | ||
|
@@ -160,7 +149,7 @@ Task("Release") | |
// Ensure that the release tag doesn't already exist. | ||
// This assumes that full repo history has been checked out; | ||
// however, that is already a prerequisite for using Nerdbank.GitVersioning. | ||
Ensure(!context.GitTagExists(data.Version), $"Tag {data.Version} already exists in repository."); | ||
Ensure(!context.GitTagExists(data.VersionStr), $"Tag {data.VersionStr} already exists in repository."); | ||
dupeTagChecked = true; | ||
context.RestoreSolution(data); | ||
|
@@ -219,13 +208,13 @@ Task("Release") | |
// Set outputs for subsequent steps in GitHub Actions | ||
if (data.IsGitHubAction) | ||
{ | ||
context.SetActionsStepOutput("version", data.Version); | ||
context.SetActionsStepOutput("version", data.VersionStr); | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
context.Error(e is CakeException ? e.Message : $"{e.GetType().Name}: {e.Message}"); | ||
await context.DeleteReleaseAsync(data, releaseId, dupeTagChecked ? data.Version : null); | ||
await context.DeleteReleaseAsync(data, releaseId, dupeTagChecked ? data.VersionStr : null); | ||
throw; | ||
} | ||
|
@@ -253,14 +242,15 @@ Task("Release") | |
// The commit changed the Git height, so update build data | ||
// and amend the commit adding the right version. | ||
// Amending a commit does not further change the Git height. | ||
data.Update(context); | ||
_ = context.Exec( | ||
"git", | ||
new ProcessArgumentBuilder() | ||
.Append("commit") | ||
.Append("--amend") | ||
.Append("-m") | ||
.AppendQuoted($"Prepare release {data.Version} [skip ci]")); | ||
.AppendQuoted($"Prepare release {data.VersionStr} [skip ci]")); | ||
committed = true; | ||
} | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.