From eb8827c11b3c91eccb1c770776f5297cb966e71d Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Mon, 6 Jul 2026 16:31:28 -0700 Subject: [PATCH 1/2] WIP --- .config/dotnet-tools.json | 7 +++ .../content/BuildSettings.cake | 19 +++++-- .../content/BuildVersion.cake | 55 +------------------ .../content/TestRunners.cake | 6 +- src/NUnit.Cake.Recipe/content/Tools.cake | 2 + 5 files changed, 28 insertions(+), 61 deletions(-) diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 3336d73..e74f724 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -22,6 +22,13 @@ "dotnet-gitreleasemanager" ], "rollForward": false + }, + "minver-cli": { + "version": "4.0.0", + "commands": [ + "minver" + ], + "rollForward": false } } } \ No newline at end of file diff --git a/src/NUnit.Cake.Recipe/content/BuildSettings.cake b/src/NUnit.Cake.Recipe/content/BuildSettings.cake index 4225e03..97440fa 100644 --- a/src/NUnit.Cake.Recipe/content/BuildSettings.cake +++ b/src/NUnit.Cake.Recipe/content/BuildSettings.cake @@ -6,8 +6,8 @@ public static class BuildSettings private static readonly string[] DEFAULT_STANDARD_HEADER = [ "// Copyright (c) Charlie Poole, Rob Prouse and Contributors. MIT License - see LICENSE.txt" ]; - // Standardized project directory structure - not changeable by user - const string SRC_DIR = "src/"; + // Standardized project directory structure - not changeable by user + const string SRC_DIR = "src/"; const string BIN_DIR = "bin/"; const string NUGET_DIR = "nuget/"; const string CHOCO_DIR = "choco/"; @@ -230,8 +230,8 @@ public static class BuildSettings // Versioning public static BuildVersion BuildVersion { get; private set; } public static string BranchName => BuildVersion.BranchName; - public static bool IsReleaseBranch => BuildVersion.IsReleaseBranch; - public static bool IsLocalBranch => BuildVersion.IsLocalBranch; + public static bool IsReleaseBranch => BuildVersion.IsReleaseBranch; //BranchName.StartsWith(RELEASE_BRANCH_PREFIX); + public static bool IsLocalBranch => BuildVersion.IsLocalBranch; //BranchName.StartsWith(LOCAL_BRANCH_PREFIX); public static string PackageVersion => BuildVersion.PackageVersion; public static string AssemblyVersion => BuildVersion.AssemblyVersion; public static string AssemblyFileVersion => BuildVersion.AssemblyFileVersion; @@ -460,7 +460,16 @@ public static class BuildSettings Console.WriteLine("PreReleaseLabel: " + BuildVersion.PreReleaseLabel); Console.WriteLine("PreReleaseSuffix: " + BuildVersion.PreReleaseSuffix); - Console.WriteLine("\nDIRECTORIES"); + Console.WriteLine("\nVERSIONING (MINVER)"); + var buildVersion = Context.MinVer(); + Console.WriteLine("Version: " + buildVersion.Version); + Console.WriteLine("Major: " + buildVersion.Major); + Console.WriteLine("Minor: " + buildVersion.Minor); + Console.WriteLine("Patch: " + buildVersion.Patch); + Console.WriteLine("PreRelease: " + buildVersion.PreRelease); + Console.WriteLine("BuildMetadata: " + buildVersion.BuildMetadata); + + Console.WriteLine("\nDIRECTORIES"); Console.WriteLine("Project: " + ProjectDirectory); Console.WriteLine("Output: " + OutputDirectory); Console.WriteLine("Source: " + SourceDirectory); diff --git a/src/NUnit.Cake.Recipe/content/BuildVersion.cake b/src/NUnit.Cake.Recipe/content/BuildVersion.cake index 54cd57a..7521f8f 100644 --- a/src/NUnit.Cake.Recipe/content/BuildVersion.cake +++ b/src/NUnit.Cake.Recipe/content/BuildVersion.cake @@ -1,12 +1,8 @@ public class BuildVersion { // Prefixes for special types of branches - private const string RELEASE_BRANCH_PREFIX = "release-"; private const string LOCAL_BRANCH_PREFIX = "local-"; - private ICakeContext _context; - private GitVersion _gitVersion; - // NOTE: This is complicated because (1) the user may have specified // the package version on the command-line and (2) GitVersion may // or may not be available. We'll work on solving (2) by getting @@ -19,18 +15,14 @@ public class BuildVersion if (context==null) throw new ArgumentNullException(nameof(context)); - _context = context; - _gitVersion = context.GitVersion(); - - BranchName = _gitVersion.BranchName; - IsReleaseBranch = BranchName.StartsWith(RELEASE_BRANCH_PREFIX); + BranchName = context.GitBranchCurrent(BuildSettings.ProjectDirectory).FriendlyName; IsLocalBranch = BranchName.StartsWith(LOCAL_BRANCH_PREFIX); // NOTE: The version of a Release Branch does not affect the PackageVersion // because it is only used for creating a draft release. On the other hand, // the version of a Local Branch is used directly as the Package Version. string packageVersion = CommandLineOptions.PackageVersion.Value ?? - (IsLocalBranch ? BranchName.Substring(LOCAL_BRANCH_PREFIX.Length) : CalculatePackageVersion()); + (IsLocalBranch ? BranchName.Substring(LOCAL_BRANCH_PREFIX.Length) : context.MinVer().Version); int dash = packageVersion.IndexOf('-'); IsPreRelease = dash > 0; @@ -82,47 +74,4 @@ public class BuildVersion public bool IsPreRelease { get; } public string PreReleaseLabel { get; } public string PreReleaseSuffix { get; } - - private string CalculatePackageVersion() - { - string label = _gitVersion.PreReleaseLabel; - - // Non pre-release is easy - if (string.IsNullOrEmpty(label)) - return _gitVersion.MajorMinorPatch; - - string branchName = _gitVersion.BranchName; - - // We don't currently use this pattern, but check in case we do later. - if (branchName.StartsWith("feature/")) - branchName = branchName.Substring(8); - - // Arbitrary branch names are ci builds - if (label == branchName) - label = "ci"; - - string suffix = "-" + label; - - switch (label) - { - case "ci": - branchName = Regex.Replace(branchName, "[^0-9A-Za-z-]+", "-"); - suffix += _gitVersion.CommitsSinceVersionSourcePadded + "-" + branchName; - break; - case "dev": - case "pre": - case "pr": - case "rc": - case "alpha": - case "beta": - default: - suffix += "." + _gitVersion.PreReleaseNumber; - break; - } - - // Nuget limits "special version part" to 20 chars. Add one for the hyphen. - if (suffix.Length > 21) - suffix = suffix.Substring(0, 21); - return _gitVersion.MajorMinorPatch + suffix; - } } diff --git a/src/NUnit.Cake.Recipe/content/TestRunners.cake b/src/NUnit.Cake.Recipe/content/TestRunners.cake index b946ce0..0b4c223 100644 --- a/src/NUnit.Cake.Recipe/content/TestRunners.cake +++ b/src/NUnit.Cake.Recipe/content/TestRunners.cake @@ -218,9 +218,9 @@ public abstract class NUnitConsoleRunnerBase : InstallableTestRunner, IUnitTestR public override ExtensionSpecifier[] Dependencies => [ - new("NUnit.Extension.Net462PluggableAgent", "nunit-extension-net462-pluggable-agent", "4.0.0"), - new("NUnit.Extension.Net80PluggableAgent", "nunit-extension-net80-pluggable-agent", "4.0.0"), - new("NUnit.Extension.Net90PluggableAgent", "nunit-extension-net90-pluggable-agent", "4.0.0") + new("NUnit.Extension.Net462PluggableAgent", "nunit-extension-net462-pluggable-agent", "4.1.1"), + new("NUnit.Extension.Net80PluggableAgent", "nunit-extension-net80-pluggable-agent", "4.1.1"), + new("NUnit.Extension.Net90PluggableAgent", "nunit-extension-net90-pluggable-agent", "4.1.1") ]; } diff --git a/src/NUnit.Cake.Recipe/content/Tools.cake b/src/NUnit.Cake.Recipe/content/Tools.cake index 603e0e7..8bebb5f 100644 --- a/src/NUnit.Cake.Recipe/content/Tools.cake +++ b/src/NUnit.Cake.Recipe/content/Tools.cake @@ -3,9 +3,11 @@ #tool dotnet:?package=GitVersion.Tool&version=6.4.0 #tool dotnet:?package=GitReleaseManager.Tool&version=0.20.0 #addin nuget:?package=Cake.Git&version=5.0.1 +#addin nuget:?package=Cake.MinVer&version=4.0.0 // Using statements needed in the scripts using Cake.Git; +using Cake.MinVer; using System.Text.RegularExpressions; using System.Xml; using SIO = System.IO; From 349550220e91fac90808163672b5650ef980cd88 Mon Sep 17 00:00:00 2001 From: Charlie Poole Date: Thu, 9 Jul 2026 06:50:44 -0700 Subject: [PATCH 2/2] Switch from using GitVersion to MinVer --- .config/dotnet-tools.json | 7 -- GitVersion.yml | 10 --- NUnit.Cake.Recipe.sln | 5 +- src/NUnit.Cake.Recipe/README.md | 2 +- .../content/BuildSettings.cake | 19 +++--- .../content/BuildVersion.cake | 24 ++----- .../content/PackageReleaseManager.cake | 65 +++++++------------ src/NUnit.Cake.Recipe/content/Setup.cake | 5 +- src/NUnit.Cake.Recipe/content/Tools.cake | 1 - 9 files changed, 42 insertions(+), 96 deletions(-) delete mode 100644 GitVersion.yml diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index e74f724..8a917a9 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -9,13 +9,6 @@ ], "rollForward": false }, - "gitversion.tool": { - "version": "6.7.0", - "commands": [ - "dotnet-gitversion" - ], - "rollForward": false - }, "gitreleasemanager.tool": { "version": "0.20.0", "commands": [ diff --git a/GitVersion.yml b/GitVersion.yml deleted file mode 100644 index 9ec889c..0000000 --- a/GitVersion.yml +++ /dev/null @@ -1,10 +0,0 @@ -# This copy of GitVersion.yml is used in building the recipe package itself. -next-version: 2.0.0 -mode: ContinuousDelivery -branches: - main: - label: alpha - release: - label: pre - pull-request: - label: pr diff --git a/NUnit.Cake.Recipe.sln b/NUnit.Cake.Recipe.sln index 3f5e02d..eab289d 100644 --- a/NUnit.Cake.Recipe.sln +++ b/NUnit.Cake.Recipe.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.14.36930.0 +# Visual Studio Version 18 +VisualStudioVersion = 18.7.11919.86 stable MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NUnit.Cake.Recipe", "src\NUnit.Cake.Recipe\NUnit.Cake.Recipe.csproj", "{1F5A7BC8-A55C-1404-FEA2-43940517E9EC}" EndProject @@ -13,7 +13,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build.ps1 = build.ps1 build.sh = build.sh GitReleaseManager.yaml = GitReleaseManager.yaml - GitVersion.yml = GitVersion.yml global.json = global.json EndProjectSection EndProject diff --git a/src/NUnit.Cake.Recipe/README.md b/src/NUnit.Cake.Recipe/README.md index 648466c..f74a333 100644 --- a/src/NUnit.Cake.Recipe/README.md +++ b/src/NUnit.Cake.Recipe/README.md @@ -60,7 +60,7 @@ Defaults to Release. #### --packageVersion=VERSION Specifies the full package version, including any pre-release suffix. This version is used directly instead of the default -version from the script or that calculated by GitVersion. +version from the script or that calculated by MinVer. Note that all other versions (AssemblyVersion, etc.) are derived from the package version. diff --git a/src/NUnit.Cake.Recipe/content/BuildSettings.cake b/src/NUnit.Cake.Recipe/content/BuildSettings.cake index 97440fa..e02578d 100644 --- a/src/NUnit.Cake.Recipe/content/BuildSettings.cake +++ b/src/NUnit.Cake.Recipe/content/BuildSettings.cake @@ -48,6 +48,9 @@ public static class BuildSettings private static readonly string[] LABELS_USED_AS_TAGS = { "alpha", "beta", "rc" }; private static readonly string[] LABELS_WE_ADD_TO_LOCAL_FEED = { "dev", "alpha", "beta", "rc" }; + // Prefixes for special types of branches + private const string LOCAL_BRANCH_PREFIX = "local-"; + #endregion private static BuildSystem _buildSystem; @@ -109,7 +112,9 @@ public static class BuildSettings UnitTestRunner = unitTestRunner ?? new NUnitLiteRunner(); UnitTestArguments = unitTestArguments; - BuildVersion = new BuildVersion(context); + var specificVersion = CommandLineOptions.PackageVersion.Value ?? + (IsLocalBranch ? BranchName.Substring(LOCAL_BRANCH_PREFIX.Length) : null); + BuildVersion = new BuildVersion(context, specificVersion); GitHubOwner = githubOwner; @@ -173,10 +178,6 @@ public static class BuildSettings if (!BuildVersion.IsPreRelease) return 3; - // TODO: The prerelease label is no longer being set to pr by GitVersion - // for some reason. This check is a workaround. - if (IsRunningOnAppVeyor && _buildSystem.AppVeyor.Environment.PullRequest.IsPullRequest) - return 2; if (IsRunningOnGitHubActions && _buildSystem.GitHubActions.Environment.PullRequest.IsPullRequest) return 2; @@ -227,11 +228,12 @@ public static class BuildSettings public static bool IsRunningOnAppVeyor => _buildSystem.AppVeyor.IsRunningOnAppVeyor; public static bool IsRunningOnGitHubActions => _buildSystem.GitHubActions.IsRunningOnGitHubActions; + // Branch Name + public static string BranchName => Context.GitBranchCurrent(BuildSettings.ProjectDirectory).FriendlyName; + public static bool IsLocalBranch => BranchName.StartsWith(LOCAL_BRANCH_PREFIX); + // Versioning public static BuildVersion BuildVersion { get; private set; } - public static string BranchName => BuildVersion.BranchName; - public static bool IsReleaseBranch => BuildVersion.IsReleaseBranch; //BranchName.StartsWith(RELEASE_BRANCH_PREFIX); - public static bool IsLocalBranch => BuildVersion.IsLocalBranch; //BranchName.StartsWith(LOCAL_BRANCH_PREFIX); public static string PackageVersion => BuildVersion.PackageVersion; public static string AssemblyVersion => BuildVersion.AssemblyVersion; public static string AssemblyFileVersion => BuildVersion.AssemblyFileVersion; @@ -527,7 +529,6 @@ public static class BuildSettings Console.WriteLine("\nRELEASING"); Console.WriteLine("BranchName: " + BranchName); - Console.WriteLine("IsReleaseBranch: " + IsReleaseBranch); Console.WriteLine("IsLocalBranch: " + IsLocalBranch); Console.WriteLine("ShouldPublishToGitHub: " + ShouldPublishToGitHub); } diff --git a/src/NUnit.Cake.Recipe/content/BuildVersion.cake b/src/NUnit.Cake.Recipe/content/BuildVersion.cake index 7521f8f..a624e87 100644 --- a/src/NUnit.Cake.Recipe/content/BuildVersion.cake +++ b/src/NUnit.Cake.Recipe/content/BuildVersion.cake @@ -1,29 +1,14 @@ public class BuildVersion { - // Prefixes for special types of branches - private const string LOCAL_BRANCH_PREFIX = "local-"; - - // NOTE: This is complicated because (1) the user may have specified - // the package version on the command-line and (2) GitVersion may - // or may not be available. We'll work on solving (2) by getting - // GitVersion to run for us on Linux, but (1) will alwas remain. - // - // We simplify things a by figuring out the full package version and - // then parsing it to provide information that is used in the build. - public BuildVersion(ICakeContext context) + public BuildVersion(ICakeContext context, string requestedVersion) { if (context==null) throw new ArgumentNullException(nameof(context)); - BranchName = context.GitBranchCurrent(BuildSettings.ProjectDirectory).FriendlyName; - IsLocalBranch = BranchName.StartsWith(LOCAL_BRANCH_PREFIX); - - // NOTE: The version of a Release Branch does not affect the PackageVersion - // because it is only used for creating a draft release. On the other hand, - // the version of a Local Branch is used directly as the Package Version. - string packageVersion = CommandLineOptions.PackageVersion.Value ?? - (IsLocalBranch ? BranchName.Substring(LOCAL_BRANCH_PREFIX.Length) : context.MinVer().Version); + // If a specific version is requested, we use that, otherwise get from MinVer. + string packageVersion = requestedVersion ?? context.MinVer().Version; + // Wherever we got it from, parse the package version int dash = packageVersion.IndexOf('-'); IsPreRelease = dash > 0; @@ -61,7 +46,6 @@ public class BuildVersion } public string BranchName { get; } - public bool IsReleaseBranch { get; } public bool IsLocalBranch { get; } public string PackageVersion { get; } diff --git a/src/NUnit.Cake.Recipe/content/PackageReleaseManager.cake b/src/NUnit.Cake.Recipe/content/PackageReleaseManager.cake index 0a24806..e344d22 100644 --- a/src/NUnit.Cake.Recipe/content/PackageReleaseManager.cake +++ b/src/NUnit.Cake.Recipe/content/PackageReleaseManager.cake @@ -170,53 +170,34 @@ public static class PackageReleaseManager $"Package not found: {package.GetFilename()}.\nCode may have changed since package was last built."); } - private const string DRAFT_RELEASE_ERROR = - "A direct call to CreateDraftRelease is permitted only:\r\n" + - " * On a release branch (release-x.x.x) OR\r\n" + - " * Using option --packageVersion to specify a release version"; - public static void CreateDraftRelease() { - string releaseVersion = - CommandLineOptions.PackageVersion.Exists - ? CommandLineOptions.PackageVersion.Value - : BuildSettings.IsReleaseBranch - ? BuildSettings.BranchName.Substring(8) - : null; + string releaseVersion = CommandLineOptions.PackageVersion.Value; - if (releaseVersion != null) + if (!BuildSettings.ShouldPublishToGitHub) + _context.Information("Skipping creation of draft release because this is not a production release"); + else if (CommandLineOptions.NoPush) + _context.Information($"NoPush option skipping creation of draft release for version {releaseVersion}"); + else { - if (CommandLineOptions.NoPush) - _context.Information($"NoPush option skipping creation of draft release for version {releaseVersion}"); - else - { - string releaseName = $"{BuildSettings.Title} {releaseVersion}"; - _context.Information($"Creating draft release for {releaseName}"); + string releaseName = $"{BuildSettings.Title} {releaseVersion}"; + _context.Information($"Creating draft release for {releaseName}"); - try - { - _context.GitReleaseManagerCreate(BuildSettings.GitHubAccessToken, BuildSettings.GitHubOwner, BuildSettings.GitHubRepository, new GitReleaseManagerCreateSettings() - { - Name = releaseName, - Milestone = releaseVersion - }); - } - catch + try + { + _context.GitReleaseManagerCreate(BuildSettings.GitHubAccessToken, BuildSettings.GitHubOwner, BuildSettings.GitHubRepository, new GitReleaseManagerCreateSettings() { - _context.Error($"Unable to create draft release for {releaseName}."); - _context.Error($"Check that there is a {releaseVersion} milestone with at least one closed issue."); - _context.Error(""); - throw; - } + Name = releaseName, + Milestone = releaseVersion + }); + } + catch + { + _context.Error($"Unable to create draft release for {releaseName}."); + _context.Error($"Check that there is a {releaseVersion} milestone with at least one closed issue."); + _context.Error(""); + throw; } - } - else - { - bool calledDirectly = CommandLineOptions.Target.Value == "CreateDraftRelease"; - if (calledDirectly) - throw new InvalidOperationException(DRAFT_RELEASE_ERROR); - else - _context.Information("Skipping creation of draft release because this is not a release branch"); } } @@ -265,8 +246,8 @@ public static class PackageReleaseManager public static void DownloadDraftRelease() { - if (!BuildSettings.IsReleaseBranch) - throw new Exception("DownloadDraftRelease requires a release branch!"); + if (!BuildSettings.ShouldPublishToGitHub) + throw new Exception("DownloadDraftRelease requires a production release version!"); string milestone = BuildSettings.BranchName.Substring(8); diff --git a/src/NUnit.Cake.Recipe/content/Setup.cake b/src/NUnit.Cake.Recipe/content/Setup.cake index ef14180..72ecedc 100644 --- a/src/NUnit.Cake.Recipe/content/Setup.cake +++ b/src/NUnit.Cake.Recipe/content/Setup.cake @@ -25,9 +25,8 @@ Setup((context) => DisplayTaskErrorAndThrow("Chocolatey ApiKey is required but was not set."); // GitHub Access Token, Owner and Repository - if (!CommandLineOptions.NoPush) - if (tasksToExecute.Contains("CreateDraftRelease") && BuildSettings.IsReleaseBranch || - tasksToExecute.Contains("CreateProductionRelease") && BuildSettings.ShouldPublishToGitHub) + if (!CommandLineOptions.NoPush && BuildSettings.ShouldPublishToGitHub) + if (tasksToExecute.Contains("CreateDraftRelease") || tasksToExecute.Contains("CreateProductionRelease")) { if (string.IsNullOrEmpty(BuildSettings.GitHubAccessToken)) DisplayTaskErrorAndThrow("GitHub Access Token is required but was not set."); diff --git a/src/NUnit.Cake.Recipe/content/Tools.cake b/src/NUnit.Cake.Recipe/content/Tools.cake index 8bebb5f..8298268 100644 --- a/src/NUnit.Cake.Recipe/content/Tools.cake +++ b/src/NUnit.Cake.Recipe/content/Tools.cake @@ -1,6 +1,5 @@ // Load all tools used by the recipe #tool NuGet.CommandLine&version=6.9.1 -#tool dotnet:?package=GitVersion.Tool&version=6.4.0 #tool dotnet:?package=GitReleaseManager.Tool&version=0.20.0 #addin nuget:?package=Cake.Git&version=5.0.1 #addin nuget:?package=Cake.MinVer&version=4.0.0