Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
],
"rollForward": false
},
"gitversion.tool": {
"version": "6.7.0",
"gitreleasemanager.tool": {
"version": "0.20.0",
"commands": [
"dotnet-gitversion"
"dotnet-gitreleasemanager"
],
"rollForward": false
},
"gitreleasemanager.tool": {
"version": "0.20.0",
"minver-cli": {
"version": "4.0.0",
"commands": [
"dotnet-gitreleasemanager"
"minver"
],
"rollForward": false
}
Expand Down
10 changes: 0 additions & 10 deletions GitVersion.yml

This file was deleted.

5 changes: 2 additions & 3 deletions NUnit.Cake.Recipe.sln
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/NUnit.Cake.Recipe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
34 changes: 22 additions & 12 deletions src/NUnit.Cake.Recipe/content/BuildSettings.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
public static bool IsLocalBranch => BuildVersion.IsLocalBranch;
public static string PackageVersion => BuildVersion.PackageVersion;
public static string AssemblyVersion => BuildVersion.AssemblyVersion;
public static string AssemblyFileVersion => BuildVersion.AssemblyFileVersion;
Expand Down Expand Up @@ -460,7 +462,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);
Expand Down Expand Up @@ -518,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);
}
Expand Down
75 changes: 4 additions & 71 deletions src/NUnit.Cake.Recipe/content/BuildVersion.cake
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
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
// 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));

_context = context;
_gitVersion = context.GitVersion();

BranchName = _gitVersion.BranchName;
IsReleaseBranch = BranchName.StartsWith(RELEASE_BRANCH_PREFIX);
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());
// 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;

Expand Down Expand Up @@ -69,7 +46,6 @@ public class BuildVersion
}

public string BranchName { get; }
public bool IsReleaseBranch { get; }
public bool IsLocalBranch { get; }

public string PackageVersion { get; }
Expand All @@ -82,47 +58,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;
}
}
65 changes: 23 additions & 42 deletions src/NUnit.Cake.Recipe/content/PackageReleaseManager.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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);

Expand Down
5 changes: 2 additions & 3 deletions src/NUnit.Cake.Recipe/content/Setup.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
6 changes: 3 additions & 3 deletions src/NUnit.Cake.Recipe/content/TestRunners.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
];
}

Expand Down
3 changes: 2 additions & 1 deletion src/NUnit.Cake.Recipe/content/Tools.cake
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// 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

// Using statements needed in the scripts
using Cake.Git;
using Cake.MinVer;
using System.Text.RegularExpressions;
using System.Xml;
using SIO = System.IO;
Expand Down