From 8bfda56225084dac065653925a37112eb6114f70 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Mon, 29 Apr 2024 22:56:09 +0930 Subject: [PATCH 1/2] Cleanup and SDK update --- .github/workflows/build.yml | 2 +- README.md | 4 +- azure-pipelines.yml | 8 +- .../BuildVersion.cs | 13 +- .../BuildVersioner.cs | 113 +++++----- .../BuildVersioningOptions.cs | 17 +- .../GitCommandRunner.cs | 69 +++--- .../IGitCommandRunner.cs | 23 +- .../IVersionDetailsProvider.cs | 9 +- .../Program.cs | 89 ++++---- ...TurnerSoftware.BuildVersioning.Tool.csproj | 6 +- .../VersionDetails.cs | 23 +- .../VersionDetailsProvider.cs | 90 ++++---- .../TurnerSoftware.BuildVersioning.csproj | 8 +- .../TurnerSoftware.BuildVersioning.targets | 2 +- .../Tool/BuildVersionerTests.cs | 199 +++++++++--------- .../Tool/GitCommandRunnerTests.cs | 22 +- .../Tool/VersionDetailsProviderTests.cs | 101 +++++---- ...urnerSoftware.BuildVersioning.Tests.csproj | 15 +- 19 files changed, 389 insertions(+), 424 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 16f9de5..2bccd19 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -31,8 +31,8 @@ jobs: uses: actions/setup-dotnet@v1.9.0 with: dotnet-version: | - 5.0.x 6.0.x + 8.0.x - name: .NET info run: dotnet --info - name: Install dependencies diff --git a/README.md b/README.md index 33c0c6f..a943647 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Simple build versioning for .NET, powered by Git tags. -![Build](https://img.shields.io/github/workflow/status/TurnerSoftware/buildversioning/Build) +![Build](https://img.shields.io/github/actions/workflow/status/TurnerSoftware/buildversioning/build.yml?branch=main) [![Codecov](https://img.shields.io/codecov/c/github/turnersoftware/BuildVersioning/main.svg)](https://codecov.io/gh/TurnerSoftware/BuildVersioning) [![NuGet](https://img.shields.io/nuget/v/TurnerSoftware.BuildVersioning.svg)](https://www.nuget.org/packages/TurnerSoftware.BuildVersioning/) @@ -37,8 +37,8 @@ These support plans help fund our OSS commitments to provide better software for - Your project must be using a modern SDK-style project file - One of the following .NET runtimes must be installed: - - .NET 5 - .NET 6 + - .NET 8 The runtime requirement is so that Build Versioning itself can run. Your project though can target whatever version of .NET you want (Framework/Standard/Core etc). diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2d6234c..e89accc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -10,14 +10,14 @@ jobs: BUILD_ARTIFACT_PATH: $(Build.ArtifactStagingDirectory) steps: - - task: UseDotNet@2 - displayName: Install .NET 5 SDK - inputs: - version: 5.0.x - task: UseDotNet@2 displayName: Install .NET 6 SDK inputs: version: 6.0.x + - task: UseDotNet@2 + displayName: Install .NET 8 SDK + inputs: + version: 8.0.x - script: dotnet --info displayName: .NET info diff --git a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersion.cs b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersion.cs index c778920..444553b 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersion.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersion.cs @@ -1,9 +1,8 @@ -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +public record BuildVersion { - public record BuildVersion - { - public string FullVersion { get; init; } - public string FileVersion { get; init; } - public string AssemblyVersion { get; init; } - } + public string FullVersion { get; init; } + public string FileVersion { get; init; } + public string AssemblyVersion { get; init; } } diff --git a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs index 49dff7c..815f0df 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs @@ -1,82 +1,69 @@ -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +internal class BuildVersioner(IVersionDetailsProvider versionDetailsProvider) { - internal class BuildVersioner + public BuildVersion GetBuildVersion(BuildVersioningOptions options) { - private IVersionDetailsProvider VersionDetailsProvider { get; } - - public BuildVersioner(IVersionDetailsProvider versionDetailsProvider) + var versionDetails = versionDetailsProvider.GetVersionDetails(); + if (versionDetails is null) { - VersionDetailsProvider = versionDetailsProvider; + return null; } - public BuildVersion GetBuildVersion(BuildVersioningOptions options) + if (!versionDetails.IsTaggedRelease && versionDetails.PreRelease is null && options.PreReleaseFormat?.Length > 0) { - var versionDetails = VersionDetailsProvider.GetVersionDetails(); - if (versionDetails is null) - { - return null; - } - - if (!versionDetails.IsTaggedRelease && versionDetails.PreRelease is null && options.PreReleaseFormat?.Length > 0) - { - versionDetails = versionDetails with - { - PreRelease = options.PreReleaseFormat - .Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) - }; - } - - if (options.BuildMetadataFormat?.Length > 0) + versionDetails = versionDetails with { - versionDetails = versionDetails with - { - BuildMetadata = options.BuildMetadataFormat - .Replace("{CommitHash}", versionDetails.CommitHash) - .Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) - }; - } - - var fullVersion = FormatFullVersion(options.FullVersionFormat, versionDetails); - var fileVersion = FormatVersion(options.FileVersionFormat, versionDetails); - var assemblyVersion = FormatVersion(options.AssemblyVersionFormat, versionDetails); - - return new BuildVersion - { - FullVersion = fullVersion, - FileVersion = fileVersion, - AssemblyVersion = assemblyVersion + PreRelease = options.PreReleaseFormat + .Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) }; } - private static string FormatFullVersion(string format, VersionDetails versionDetails) + if (options.BuildMetadataFormat?.Length > 0) { - if (string.IsNullOrEmpty(format)) + versionDetails = versionDetails with { - return format; - } - - return FormatVersion(format, versionDetails) - .Replace("{PreRelease}", versionDetails.PreRelease is null ? default : $"-{versionDetails.PreRelease}") - .Replace("{BuildMetadata}", versionDetails.BuildMetadata is null ? default : $"+{versionDetails.BuildMetadata}"); + BuildMetadata = options.BuildMetadataFormat + .Replace("{CommitHash}", versionDetails.CommitHash) + .Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) + }; } - private static string FormatVersion(string format, VersionDetails versionDetails) + var fullVersion = FormatFullVersion(options.FullVersionFormat, versionDetails); + var fileVersion = FormatVersion(options.FileVersionFormat, versionDetails); + var assemblyVersion = FormatVersion(options.AssemblyVersionFormat, versionDetails); + + return new BuildVersion(fullVersion, fileVersion, assemblyVersion); + } + + private static string FormatFullVersion(string format, VersionDetails versionDetails) + { + if (string.IsNullOrEmpty(format)) { - if (string.IsNullOrEmpty(format)) - { - return format; - } + return format; + } - var autoIncrement = versionDetails.IsTaggedRelease ? 0 : 1; - return format - .Replace("{Major}", versionDetails.MajorVersion.ToString()) - .Replace("{Major++}", (versionDetails.MajorVersion + autoIncrement).ToString()) - .Replace("{Minor}", versionDetails.MinorVersion.ToString()) - .Replace("{Minor++}", (versionDetails.MinorVersion + autoIncrement).ToString()) - .Replace("{Patch}", versionDetails.PatchVersion.ToString()) - .Replace("{Patch++}", (versionDetails.PatchVersion + autoIncrement).ToString()) - .Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) - .Replace("{CommitHash}", versionDetails.CommitHash ?? "NOCANDO"); + return FormatVersion(format, versionDetails) + .Replace("{PreRelease}", versionDetails.PreRelease is null ? default : $"-{versionDetails.PreRelease}") + .Replace("{BuildMetadata}", versionDetails.BuildMetadata is null ? default : $"+{versionDetails.BuildMetadata}"); + } + + private static string FormatVersion(string format, VersionDetails versionDetails) + { + if (string.IsNullOrEmpty(format)) + { + return format; } + + var autoIncrement = versionDetails.IsTaggedRelease ? 0 : 1; + return format + .Replace("{Major}", versionDetails.MajorVersion.ToString()) + .Replace("{Major++}", (versionDetails.MajorVersion + autoIncrement).ToString()) + .Replace("{Minor}", versionDetails.MinorVersion.ToString()) + .Replace("{Minor++}", (versionDetails.MinorVersion + autoIncrement).ToString()) + .Replace("{Patch}", versionDetails.PatchVersion.ToString()) + .Replace("{Patch++}", (versionDetails.PatchVersion + autoIncrement).ToString()) + .Replace("{CommitHeight}", versionDetails.CommitHeight.ToString()) + .Replace("{CommitHash}", versionDetails.CommitHash ?? "NOCANDO"); } } diff --git a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioningOptions.cs b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioningOptions.cs index ab6014c..3b51b41 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioningOptions.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioningOptions.cs @@ -1,11 +1,10 @@ -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +public record BuildVersioningOptions { - public record BuildVersioningOptions - { - public string FullVersionFormat { get; init; } - public string FileVersionFormat { get; init; } - public string AssemblyVersionFormat { get; init; } - public string PreReleaseFormat { get; init; } - public string BuildMetadataFormat { get; init; } - } + public string FullVersionFormat { get; init; } + public string FileVersionFormat { get; init; } + public string AssemblyVersionFormat { get; init; } + public string PreReleaseFormat { get; init; } + public string BuildMetadataFormat { get; init; } } diff --git a/src/TurnerSoftware.BuildVersioning.Tool/GitCommandRunner.cs b/src/TurnerSoftware.BuildVersioning.Tool/GitCommandRunner.cs index 6d88b56..74a9e32 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/GitCommandRunner.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/GitCommandRunner.cs @@ -2,46 +2,43 @@ using System.Diagnostics; using System.Threading.Tasks; -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +internal class GitCommandRunner : IGitCommandRunner { - internal class GitCommandRunner : IGitCommandRunner + private static string RunCommand(string command) { - private string RunCommand(string command) + using var process = new Process(); + process.StartInfo = new ProcessStartInfo("git", command) + { + RedirectStandardOutput = true + }; + + var waitOnExit = new TaskCompletionSource(); + process.Exited += (s, e) => waitOnExit.SetResult(default); + process.EnableRaisingEvents = true; + + try + { + process.Start(); + } + catch (Exception ex) { - using (var process = new Process()) - { - process.StartInfo = new ProcessStartInfo("git", command) - { - RedirectStandardOutput = true - }; - - var waitOnExit = new TaskCompletionSource(); - process.Exited += (s, e) => waitOnExit.SetResult(default); - process.EnableRaisingEvents = true; - - try - { - process.Start(); - } - catch (Exception ex) - { - Console.Error.WriteLine(ex.Message); - return null; - } - - var standardOutputTask = process.StandardOutput.ReadToEndAsync(); - - Task.WaitAll(waitOnExit.Task, standardOutputTask); - - if (process.ExitCode != 0) - { - return null; - } - - return standardOutputTask.Result; - } + Console.Error.WriteLine(ex.Message); + return null; } - public string GitDescribe() => RunCommand("describe --tags --abbrev=7 --always --long"); + var standardOutputTask = process.StandardOutput.ReadToEndAsync(); + + Task.WaitAll(waitOnExit.Task, standardOutputTask); + + if (process.ExitCode != 0) + { + return null; + } + + return standardOutputTask.Result; } + + public string GitDescribe() => RunCommand("describe --tags --abbrev=7 --always --long"); } diff --git a/src/TurnerSoftware.BuildVersioning.Tool/IGitCommandRunner.cs b/src/TurnerSoftware.BuildVersioning.Tool/IGitCommandRunner.cs index 5e68af5..34063b5 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/IGitCommandRunner.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/IGitCommandRunner.cs @@ -1,14 +1,13 @@ -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +public interface IGitCommandRunner { - public interface IGitCommandRunner - { - /// - /// Returns a result from `git describe` containing the tag name, number of commits from the tag (commit height) and a 7-character commit hash. - /// - /// - /// Format with tag: {tag}-{commitHeight}-{commitHash}
- /// Format without tag: {commitHash} - ///
- string GitDescribe(); - } + /// + /// Returns a result from `git describe` containing the tag name, number of commits from the tag (commit height) and a 7-character commit hash. + /// + /// + /// Format with tag: {tag}-{commitHeight}-{commitHash}
+ /// Format without tag: {commitHash} + ///
+ string GitDescribe(); } diff --git a/src/TurnerSoftware.BuildVersioning.Tool/IVersionDetailsProvider.cs b/src/TurnerSoftware.BuildVersioning.Tool/IVersionDetailsProvider.cs index fbfc674..13a0436 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/IVersionDetailsProvider.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/IVersionDetailsProvider.cs @@ -1,7 +1,6 @@ -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +public interface IVersionDetailsProvider { - public interface IVersionDetailsProvider - { - VersionDetails GetVersionDetails(); - } + VersionDetails GetVersionDetails(); } diff --git a/src/TurnerSoftware.BuildVersioning.Tool/Program.cs b/src/TurnerSoftware.BuildVersioning.Tool/Program.cs index 55a39f1..ea4d614 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/Program.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/Program.cs @@ -1,59 +1,50 @@ using System; using System.CommandLine; using System.CommandLine.Invocation; +using TurnerSoftware.BuildVersioning.Tool; -namespace TurnerSoftware.BuildVersioning.Tool +var rootCommand = new RootCommand { - class Program + new Option("--full-version-format") { - static int Main(string[] args) - { - var rootCommand = new RootCommand - { - new Option("--full-version-format") - { - IsRequired = true, - Description = "The string to format for the full version." - }, - new Option("--file-version-format") - { - IsRequired = true, - Description = "The string to format for the file version." - }, - new Option("--assembly-version-format") - { - IsRequired = true, - Description = "The string to format for the assembly version." - }, - new Option("--prerelease-format", () => string.Empty) - { - Description = "The string to format for the pre-release." - }, - new Option("--build-metadata-format", () => string.Empty) - { - Description = "The string to format for the build metadata." - } - }; + IsRequired = true, + Description = "The string to format for the full version." + }, + new Option("--file-version-format") + { + IsRequired = true, + Description = "The string to format for the file version." + }, + new Option("--assembly-version-format") + { + IsRequired = true, + Description = "The string to format for the assembly version." + }, + new Option("--prerelease-format", () => string.Empty) + { + Description = "The string to format for the pre-release." + }, + new Option("--build-metadata-format", () => string.Empty) + { + Description = "The string to format for the build metadata." + } +}; - rootCommand.Description = "Build Versioning Tool"; +rootCommand.Description = "Build Versioning Tool"; - rootCommand.Handler = CommandHandler.Create((fullVersionFormat, fileVersionFormat, assemblyVersionFormat, preReleaseFormat, buildMetadataFormat) => - { - var buildVersioner = new BuildVersioner(new VersionDetailsProvider(new GitCommandRunner())); - var buildVersion = buildVersioner.GetBuildVersion(new BuildVersioningOptions - { - FullVersionFormat = fullVersionFormat, - FileVersionFormat = fileVersionFormat, - AssemblyVersionFormat = assemblyVersionFormat, - PreReleaseFormat = preReleaseFormat, - BuildMetadataFormat = buildMetadataFormat - }); +rootCommand.Handler = CommandHandler.Create((fullVersionFormat, fileVersionFormat, assemblyVersionFormat, preReleaseFormat, buildMetadataFormat) => +{ + var buildVersioner = new BuildVersioner(new VersionDetailsProvider(new GitCommandRunner())); + var buildVersion = buildVersioner.GetBuildVersion(new BuildVersioningOptions( + fullVersionFormat, + fileVersionFormat, + assemblyVersionFormat, + preReleaseFormat, + buildMetadataFormat + )); - Console.WriteLine($"{buildVersion.FullVersion};{buildVersion.FileVersion};{buildVersion.AssemblyVersion}"); - return 0; - }); + Console.WriteLine($"{buildVersion.FullVersion};{buildVersion.FileVersion};{buildVersion.AssemblyVersion}"); + return 0; +}); - return rootCommand.InvokeAsync(args).Result; - } - } -} +return rootCommand.InvokeAsync(args).Result; diff --git a/src/TurnerSoftware.BuildVersioning.Tool/TurnerSoftware.BuildVersioning.Tool.csproj b/src/TurnerSoftware.BuildVersioning.Tool/TurnerSoftware.BuildVersioning.Tool.csproj index a1bd6b8..7fbee16 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/TurnerSoftware.BuildVersioning.Tool.csproj +++ b/src/TurnerSoftware.BuildVersioning.Tool/TurnerSoftware.BuildVersioning.Tool.csproj @@ -10,7 +10,7 @@ Exe - net5.0;net6.0 + net6.0;net8.0 high TurnerSoftware.BuildVersioning.Tool true @@ -27,6 +27,10 @@ + + + + diff --git a/src/TurnerSoftware.BuildVersioning.Tool/VersionDetails.cs b/src/TurnerSoftware.BuildVersioning.Tool/VersionDetails.cs index aed4915..a56e081 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/VersionDetails.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/VersionDetails.cs @@ -1,14 +1,13 @@ -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +public record VersionDetails { - public record VersionDetails - { - public int MajorVersion { get; init; } - public int MinorVersion { get; init; } - public int PatchVersion { get; init; } - public string PreRelease { get; init; } - public string BuildMetadata { get; init; } - public string CommitHash { get; init; } - public int CommitHeight { get; init; } - public bool IsTaggedRelease { get; init; } - } + public int MajorVersion { get; init; } + public int MinorVersion { get; init; } + public int PatchVersion { get; init; } + public string PreRelease { get; init; } + public string BuildMetadata { get; init; } + public string CommitHash { get; init; } + public int CommitHeight { get; init; } + public bool IsTaggedRelease { get; init; } } diff --git a/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs b/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs index 617310b..8d7ae8a 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs @@ -1,62 +1,52 @@ using System.Text.RegularExpressions; -namespace TurnerSoftware.BuildVersioning.Tool +namespace TurnerSoftware.BuildVersioning.Tool; + +internal class VersionDetailsProvider(IGitCommandRunner gitDataProvider) : IVersionDetailsProvider { - internal class VersionDetailsProvider : IVersionDetailsProvider + /// + /// Parses the value from `git describe --tags --abbrev=7 --always` into specific version and commit information. + /// + /// + /// + /// Format with tag: {tag}-{commitHeight}-{commitHash}
+ /// Format without tag: {commitHash} + ///
+ /// + /// Tag format: {major}.{minor}.{patch}{-preRelease}{+buildMetadata}
+ /// Tag can have a prefix which will be ignored. + ///
+ ///
+ private static readonly Regex GitDescribeParser = new(@"(?:[a-z. ]+)?(?\d+).(?\d+).(?\d+)(?:-(?[a-z0-9][a-z0-9-.]+))?(?:\+(?[a-z0-9][a-z0-9-.]+))?-(?\d+)-(?\w+)|(?\w+)", RegexOptions.IgnoreCase); + + public VersionDetails GetVersionDetails() { - /// - /// Parses the value from `git describe --tags --abbrev=7 --always` into specific version and commit information. - /// - /// - /// - /// Format with tag: {tag}-{commitHeight}-{commitHash}
- /// Format without tag: {commitHash} - ///
- /// - /// Tag format: {major}.{minor}.{patch}{-preRelease}{+buildMetadata}
- /// Tag can have a prefix which will be ignored. - ///
- ///
- private static readonly Regex GitDescribeParser = new(@"(?:[a-z. ]+)?(?\d+).(?\d+).(?\d+)(?:-(?[a-z0-9][a-z0-9-.]+))?(?:\+(?[a-z0-9][a-z0-9-.]+))?-(?\d+)-(?\w+)|(?\w+)", RegexOptions.IgnoreCase); + var gitDetails = gitDataProvider.GitDescribe(); + if (gitDetails is null) + { + return null; + } - private IGitCommandRunner GitCommandRunner { get; } + var matchedGroups = GitDescribeParser.Match(gitDetails).Groups; - public VersionDetailsProvider(IGitCommandRunner gitDataProvider) + if (matchedGroups["major"].Success) { - GitCommandRunner = gitDataProvider; + return new VersionDetails( + MajorVersion: int.Parse(matchedGroups["major"].Value), + MinorVersion: int.Parse(matchedGroups["minor"].Value), + PatchVersion: int.Parse(matchedGroups["patch"].Value), + PreRelease: matchedGroups["preRelease"].Success ? matchedGroups["preRelease"].Value : default, + BuildMetadata: matchedGroups["buildMetadata"].Success ? matchedGroups["buildMetadata"].Value : default, + CommitHeight: int.Parse(matchedGroups["commitHeight"].Value), + IsTaggedRelease: int.Parse(matchedGroups["commitHeight"].Value) == 0, + CommitHash: matchedGroups["commitHash"].Value + ); } - - public VersionDetails GetVersionDetails() + else { - var gitDetails = GitCommandRunner.GitDescribe(); - if (gitDetails is null) - { - return null; - } - - var matchedGroups = GitDescribeParser.Match(gitDetails).Groups; - - if (matchedGroups["major"].Success) - { - return new VersionDetails - { - MajorVersion = int.Parse(matchedGroups["major"].Value), - MinorVersion = int.Parse(matchedGroups["minor"].Value), - PatchVersion = int.Parse(matchedGroups["patch"].Value), - PreRelease = matchedGroups["preRelease"].Success ? matchedGroups["preRelease"].Value : default, - BuildMetadata = matchedGroups["buildMetadata"].Success ? matchedGroups["buildMetadata"].Value : default, - CommitHeight = int.Parse(matchedGroups["commitHeight"].Value), - IsTaggedRelease = int.Parse(matchedGroups["commitHeight"].Value) == 0, - CommitHash = matchedGroups["commitHash"].Value - }; - } - else - { - return new VersionDetails - { - CommitHash = matchedGroups["commitHash"].Value - }; - } + return new VersionDetails( + matchedGroups["commitHash"].Value + ); } } } diff --git a/src/TurnerSoftware.BuildVersioning/TurnerSoftware.BuildVersioning.csproj b/src/TurnerSoftware.BuildVersioning/TurnerSoftware.BuildVersioning.csproj index 5cff1c9..ad1896d 100644 --- a/src/TurnerSoftware.BuildVersioning/TurnerSoftware.BuildVersioning.csproj +++ b/src/TurnerSoftware.BuildVersioning/TurnerSoftware.BuildVersioning.csproj @@ -9,7 +9,7 @@
- net6.0 + net8.0 true true false @@ -31,8 +31,12 @@ - + + + + + diff --git a/src/TurnerSoftware.BuildVersioning/build/TurnerSoftware.BuildVersioning.targets b/src/TurnerSoftware.BuildVersioning/build/TurnerSoftware.BuildVersioning.targets index f86f85c..d1cc07a 100644 --- a/src/TurnerSoftware.BuildVersioning/build/TurnerSoftware.BuildVersioning.targets +++ b/src/TurnerSoftware.BuildVersioning/build/TurnerSoftware.BuildVersioning.targets @@ -30,8 +30,8 @@ - <_BuildVersioningToolRuntime Condition="$(_DotnetInfo.Contains("NETCore.App 5.0"))">net5.0 <_BuildVersioningToolRuntime Condition="$(_DotnetInfo.Contains("NETCore.App 6.0"))">net6.0 + <_BuildVersioningToolRuntime Condition="$(_DotnetInfo.Contains("NETCore.App 8.0"))">net8.0 diff --git a/tests/TurnerSoftware.BuildVersioning.Tests/Tool/BuildVersionerTests.cs b/tests/TurnerSoftware.BuildVersioning.Tests/Tool/BuildVersionerTests.cs index 8107136..c0e98de 100644 --- a/tests/TurnerSoftware.BuildVersioning.Tests/Tool/BuildVersionerTests.cs +++ b/tests/TurnerSoftware.BuildVersioning.Tests/Tool/BuildVersionerTests.cs @@ -4,113 +4,112 @@ using Moq; using TurnerSoftware.BuildVersioning.Tool; -namespace TurnerSoftware.BuildVersioning.Tests.Tool +namespace TurnerSoftware.BuildVersioning.Tests.Tool; + +[TestClass] +public class BuildVersionerTests { - [TestClass] - public class BuildVersionerTests + private static readonly BuildVersioningOptions DefaultBuildVersioningOptions = new() + { + FullVersionFormat = "{Major}.{Minor}.{Patch}{PreRelease}{BuildMetadata}", + FileVersionFormat = "{Major}.{Minor}.{Patch}.0", + AssemblyVersionFormat = "{Major}.0.0.0", + PreReleaseFormat = "dev.{CommitHeight}", + BuildMetadataFormat = "{CommitHash}" + }; + + private static IEnumerable GetBuildVersionTestData() { - private static readonly BuildVersioningOptions DefaultBuildVersioningOptions = new() + yield return new object[] { - FullVersionFormat = "{Major}.{Minor}.{Patch}{PreRelease}{BuildMetadata}", - FileVersionFormat = "{Major}.{Minor}.{Patch}.0", - AssemblyVersionFormat = "{Major}.0.0.0", - PreReleaseFormat = "dev.{CommitHeight}", - BuildMetadataFormat = "{CommitHash}" + "Null values", + null, + null, + null }; - - private static IEnumerable GetBuildVersionTestData() + yield return new object[] + { + "No formats specified", + new VersionDetails { }, + new BuildVersioningOptions { }, + new BuildVersion { } + }; + yield return new object[] + { + "No Git tag", + new VersionDetails { CommitHash = "abcdef" }, + DefaultBuildVersioningOptions, + new BuildVersion { FullVersion = "0.0.0-dev.0+abcdef", FileVersion = "0.0.0.0", AssemblyVersion = "0.0.0.0" } + }; + yield return new object[] + { + "Tagged release", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHash = "abcdef", IsTaggedRelease = true }, + DefaultBuildVersioningOptions, + new BuildVersion { FullVersion = "1.2.4+abcdef", FileVersion = "1.2.4.0", AssemblyVersion = "1.0.0.0" } + }; + yield return new object[] + { + "Has commit height", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHeight = 1, CommitHash = "abcdef" }, + DefaultBuildVersioningOptions, + new BuildVersion { FullVersion = "1.2.4-dev.1+abcdef", FileVersion = "1.2.4.0", AssemblyVersion = "1.0.0.0" } + }; + yield return new object[] + { + "Pre-release", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", CommitHeight = 4, CommitHash = "abcdef" }, + DefaultBuildVersioningOptions, + new BuildVersion { FullVersion = "1.2.4-alpha+abcdef", FileVersion = "1.2.4.0", AssemblyVersion = "1.0.0.0" } + }; + yield return new object[] + { + "Build metadata is overridden when format is defined", + new VersionDetails { BuildMetadata = "custom.{CommitHash}", CommitHash = "abcdef" }, + DefaultBuildVersioningOptions, + new BuildVersion { FullVersion = "0.0.0-dev.0+abcdef", FileVersion = "0.0.0.0", AssemblyVersion = "0.0.0.0" } + }; + yield return new object[] + { + "Auto-increment tags", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 3 }, + new BuildVersioningOptions { FullVersionFormat = "{Major++}.{Minor++}.{Patch++}", FileVersionFormat = "{Major++}.{Minor++}.{Patch++}", AssemblyVersionFormat = "{Major++}.{Minor++}.{Patch++}" }, + new BuildVersion { FullVersion = "2.3.4", FileVersion = "2.3.4", AssemblyVersion = "2.3.4" } + }; + yield return new object[] + { + "Don't auto-increment tags on tagged release", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 3, IsTaggedRelease = true }, + new BuildVersioningOptions { FullVersionFormat = "{Major++}.{Minor++}.{Patch++}", FileVersionFormat = "{Major++}.{Minor++}.{Patch++}", AssemblyVersionFormat = "{Major++}.{Minor++}.{Patch++}" }, + new BuildVersion { FullVersion = "1.2.3", FileVersion = "1.2.3", AssemblyVersion = "1.2.3" } + }; + yield return new object[] { - yield return new object[] - { - "Null values", - null, - null, - null - }; - yield return new object[] - { - "No formats specified", - new VersionDetails { }, - new BuildVersioningOptions { }, - new BuildVersion { } - }; - yield return new object[] - { - "No Git tag", - new VersionDetails { CommitHash = "abcdef" }, - DefaultBuildVersioningOptions, - new BuildVersion { FullVersion = "0.0.0-dev.0+abcdef", FileVersion = "0.0.0.0", AssemblyVersion = "0.0.0.0" } - }; - yield return new object[] - { - "Tagged release", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHash = "abcdef", IsTaggedRelease = true }, - DefaultBuildVersioningOptions, - new BuildVersion { FullVersion = "1.2.4+abcdef", FileVersion = "1.2.4.0", AssemblyVersion = "1.0.0.0" } - }; - yield return new object[] - { - "Has commit height", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHeight = 1, CommitHash = "abcdef" }, - DefaultBuildVersioningOptions, - new BuildVersion { FullVersion = "1.2.4-dev.1+abcdef", FileVersion = "1.2.4.0", AssemblyVersion = "1.0.0.0" } - }; - yield return new object[] - { - "Pre-release", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", CommitHeight = 4, CommitHash = "abcdef" }, - DefaultBuildVersioningOptions, - new BuildVersion { FullVersion = "1.2.4-alpha+abcdef", FileVersion = "1.2.4.0", AssemblyVersion = "1.0.0.0" } - }; - yield return new object[] - { - "Build metadata is overridden when format is defined", - new VersionDetails { BuildMetadata = "custom.{CommitHash}", CommitHash = "abcdef" }, - DefaultBuildVersioningOptions, - new BuildVersion { FullVersion = "0.0.0-dev.0+abcdef", FileVersion = "0.0.0.0", AssemblyVersion = "0.0.0.0" } - }; - yield return new object[] - { - "Auto-increment tags", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 3 }, - new BuildVersioningOptions { FullVersionFormat = "{Major++}.{Minor++}.{Patch++}", FileVersionFormat = "{Major++}.{Minor++}.{Patch++}", AssemblyVersionFormat = "{Major++}.{Minor++}.{Patch++}" }, - new BuildVersion { FullVersion = "2.3.4", FileVersion = "2.3.4", AssemblyVersion = "2.3.4" } - }; - yield return new object[] - { - "Don't auto-increment tags on tagged release", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 3, IsTaggedRelease = true }, - new BuildVersioningOptions { FullVersionFormat = "{Major++}.{Minor++}.{Patch++}", FileVersionFormat = "{Major++}.{Minor++}.{Patch++}", AssemblyVersionFormat = "{Major++}.{Minor++}.{Patch++}" }, - new BuildVersion { FullVersion = "1.2.3", FileVersion = "1.2.3", AssemblyVersion = "1.2.3" } - }; - yield return new object[] - { - "Commit height available for pre-release", - new VersionDetails { CommitHeight = 1, CommitHash = "abcdef" }, - new BuildVersioningOptions { FullVersionFormat = "{Major}.{Minor}.{Patch}{PreRelease}", PreReleaseFormat = "commitHeight.{CommitHeight}" }, - new BuildVersion { FullVersion = "0.0.0-commitHeight.1" } - }; - yield return new object[] - { - "Commit height and commit hash available for build metadata", - new VersionDetails { CommitHeight = 1, CommitHash = "abcdef" }, - new BuildVersioningOptions { FullVersionFormat = "{Major}.{Minor}.{Patch}{BuildMetadata}", BuildMetadataFormat = "commitHeight.{CommitHeight}-commitHash.{CommitHash}" }, - new BuildVersion { FullVersion = "0.0.0+commitHeight.1-commitHash.abcdef" } - }; - } + "Commit height available for pre-release", + new VersionDetails { CommitHeight = 1, CommitHash = "abcdef" }, + new BuildVersioningOptions { FullVersionFormat = "{Major}.{Minor}.{Patch}{PreRelease}", PreReleaseFormat = "commitHeight.{CommitHeight}" }, + new BuildVersion { FullVersion = "0.0.0-commitHeight.1" } + }; + yield return new object[] + { + "Commit height and commit hash available for build metadata", + new VersionDetails { CommitHeight = 1, CommitHash = "abcdef" }, + new BuildVersioningOptions { FullVersionFormat = "{Major}.{Minor}.{Patch}{BuildMetadata}", BuildMetadataFormat = "commitHeight.{CommitHeight}-commitHash.{CommitHash}" }, + new BuildVersion { FullVersion = "0.0.0+commitHeight.1-commitHash.abcdef" } + }; + } - public static string GetBuildVersionTestName(MethodInfo methodInfo, object[] data) => data[0] as string; + public static string GetBuildVersionTestName(MethodInfo methodInfo, object[] data) => data[0] as string; - [DataTestMethod] - [DynamicData(nameof(GetBuildVersionTestData), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetBuildVersionTestName))] - public void GetBuildVersion(string testName, VersionDetails inputVersion, BuildVersioningOptions options, BuildVersion expected) - { - var versionDetailsProviderMock = new Mock(); - versionDetailsProviderMock.Setup(c => c.GetVersionDetails()).Returns(inputVersion); - var buildVersioner = new BuildVersioner(versionDetailsProviderMock.Object); + [DataTestMethod] + [DynamicData(nameof(GetBuildVersionTestData), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetBuildVersionTestName))] + public void GetBuildVersion(string testName, VersionDetails inputVersion, BuildVersioningOptions options, BuildVersion expected) + { + var versionDetailsProviderMock = new Mock(); + versionDetailsProviderMock.Setup(c => c.GetVersionDetails()).Returns(inputVersion); + var buildVersioner = new BuildVersioner(versionDetailsProviderMock.Object); - var result = buildVersioner.GetBuildVersion(options); - Assert.AreEqual(expected, result); - } + var result = buildVersioner.GetBuildVersion(options); + Assert.AreEqual(expected, result); } } diff --git a/tests/TurnerSoftware.BuildVersioning.Tests/Tool/GitCommandRunnerTests.cs b/tests/TurnerSoftware.BuildVersioning.Tests/Tool/GitCommandRunnerTests.cs index 574e933..edae3e3 100644 --- a/tests/TurnerSoftware.BuildVersioning.Tests/Tool/GitCommandRunnerTests.cs +++ b/tests/TurnerSoftware.BuildVersioning.Tests/Tool/GitCommandRunnerTests.cs @@ -1,22 +1,18 @@ -using System.Collections.Generic; -using System.Reflection; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Moq; using TurnerSoftware.BuildVersioning.Tool; -namespace TurnerSoftware.BuildVersioning.Tests.Tool +namespace TurnerSoftware.BuildVersioning.Tests.Tool; + +[TestClass] +public class GitCommandRunnerTests { - [TestClass] - public class GitCommandRunnerTests + [TestMethod] + public void GitDescribe() { - [TestMethod] - public void GitDescribe() - { - var gitCommandRunner = new GitCommandRunner(); + var gitCommandRunner = new GitCommandRunner(); - var result = gitCommandRunner.GitDescribe(); + var result = gitCommandRunner.GitDescribe(); - Assert.IsFalse(result.StartsWith("fatal")); - } + Assert.IsFalse(result.StartsWith("fatal")); } } diff --git a/tests/TurnerSoftware.BuildVersioning.Tests/Tool/VersionDetailsProviderTests.cs b/tests/TurnerSoftware.BuildVersioning.Tests/Tool/VersionDetailsProviderTests.cs index c71a6ba..03ef104 100644 --- a/tests/TurnerSoftware.BuildVersioning.Tests/Tool/VersionDetailsProviderTests.cs +++ b/tests/TurnerSoftware.BuildVersioning.Tests/Tool/VersionDetailsProviderTests.cs @@ -4,62 +4,61 @@ using Moq; using TurnerSoftware.BuildVersioning.Tool; -namespace TurnerSoftware.BuildVersioning.Tests.Tool +namespace TurnerSoftware.BuildVersioning.Tests.Tool; + +[TestClass] +public class VersionDetailsProviderTests { - [TestClass] - public class VersionDetailsProviderTests + private static IEnumerable GetVersionDetailsTestData() { - private static IEnumerable GetVersionDetailsTestData() + yield return new object[] + { + null, + null + }; + yield return new object[] + { + "abcdef", + new VersionDetails { CommitHash = "abcdef" } + }; + yield return new object[] + { + "1.2.4-0-abcdef", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHash = "abcdef", IsTaggedRelease = true } + }; + yield return new object[] + { + "1.2.4-1-abcdef", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHeight = 1, CommitHash = "abcdef" } + }; + yield return new object[] { - yield return new object[] - { - null, - null - }; - yield return new object[] - { - "abcdef", - new VersionDetails { CommitHash = "abcdef" } - }; - yield return new object[] - { - "1.2.4-0-abcdef", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHash = "abcdef", IsTaggedRelease = true } - }; - yield return new object[] - { - "1.2.4-1-abcdef", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, CommitHeight = 1, CommitHash = "abcdef" } - }; - yield return new object[] - { - "1.2.4-alpha-4-abcdef", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", CommitHeight = 4, CommitHash = "abcdef" } - }; - yield return new object[] - { - "1.2.4-alpha+build.123-4-abcdef", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", BuildMetadata = "build.123", CommitHeight = 4, CommitHash = "abcdef" } - }; - yield return new object[] - { - "v1.2.4-alpha+build.123-4-abcdef", - new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", BuildMetadata = "build.123", CommitHeight = 4, CommitHash = "abcdef" } - }; - } + "1.2.4-alpha-4-abcdef", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", CommitHeight = 4, CommitHash = "abcdef" } + }; + yield return new object[] + { + "1.2.4-alpha+build.123-4-abcdef", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", BuildMetadata = "build.123", CommitHeight = 4, CommitHash = "abcdef" } + }; + yield return new object[] + { + "v1.2.4-alpha+build.123-4-abcdef", + new VersionDetails { MajorVersion = 1, MinorVersion = 2, PatchVersion = 4, PreRelease = "alpha", BuildMetadata = "build.123", CommitHeight = 4, CommitHash = "abcdef" } + }; + } - public static string GetVersionDetailsTestName(MethodInfo methodInfo, object[] data) => data[0] as string ?? "Null"; + public static string GetVersionDetailsTestName(MethodInfo methodInfo, object[] data) => data[0] as string ?? "Null"; - [DataTestMethod] - [DynamicData(nameof(GetVersionDetailsTestData), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetVersionDetailsTestName))] - public void GetVersionDetails(string gitDescribeString, VersionDetails expected) - { - var commandRunnerMock = new Mock(); - commandRunnerMock.Setup(c => c.GitDescribe()).Returns(gitDescribeString); - var versionDetailsProvider = new VersionDetailsProvider(commandRunnerMock.Object); + [DataTestMethod] + [DynamicData(nameof(GetVersionDetailsTestData), DynamicDataSourceType.Method, DynamicDataDisplayName = nameof(GetVersionDetailsTestName))] + public void GetVersionDetails(string gitDescribeString, VersionDetails expected) + { + var commandRunnerMock = new Mock(); + commandRunnerMock.Setup(c => c.GitDescribe()).Returns(gitDescribeString); + var versionDetailsProvider = new VersionDetailsProvider(commandRunnerMock.Object); - var result = versionDetailsProvider.GetVersionDetails(); - Assert.AreEqual(expected, result); - } + var result = versionDetailsProvider.GetVersionDetails(); + Assert.AreEqual(expected, result); } } diff --git a/tests/TurnerSoftware.BuildVersioning.Tests/TurnerSoftware.BuildVersioning.Tests.csproj b/tests/TurnerSoftware.BuildVersioning.Tests/TurnerSoftware.BuildVersioning.Tests.csproj index 3202077..8481172 100644 --- a/tests/TurnerSoftware.BuildVersioning.Tests/TurnerSoftware.BuildVersioning.Tests.csproj +++ b/tests/TurnerSoftware.BuildVersioning.Tests/TurnerSoftware.BuildVersioning.Tests.csproj @@ -1,17 +1,20 @@  - net5.0 + net8.0 false - - - - - + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + From e7278bf1a1f188b589fa123286662f2e57b8bec3 Mon Sep 17 00:00:00 2001 From: Turnerj Date: Mon, 29 Apr 2024 23:06:59 +0930 Subject: [PATCH 2/2] Build fixes --- .../BuildVersioner.cs | 7 ++++- .../Program.cs | 15 +++++----- .../VersionDetailsProvider.cs | 28 ++++++++++--------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs index 815f0df..ef13064 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/BuildVersioner.cs @@ -33,7 +33,12 @@ public BuildVersion GetBuildVersion(BuildVersioningOptions options) var fileVersion = FormatVersion(options.FileVersionFormat, versionDetails); var assemblyVersion = FormatVersion(options.AssemblyVersionFormat, versionDetails); - return new BuildVersion(fullVersion, fileVersion, assemblyVersion); + return new BuildVersion + { + FullVersion = fullVersion, + FileVersion = fileVersion, + AssemblyVersion = assemblyVersion + }; } private static string FormatFullVersion(string format, VersionDetails versionDetails) diff --git a/src/TurnerSoftware.BuildVersioning.Tool/Program.cs b/src/TurnerSoftware.BuildVersioning.Tool/Program.cs index ea4d614..7dd58cb 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/Program.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/Program.cs @@ -35,13 +35,14 @@ rootCommand.Handler = CommandHandler.Create((fullVersionFormat, fileVersionFormat, assemblyVersionFormat, preReleaseFormat, buildMetadataFormat) => { var buildVersioner = new BuildVersioner(new VersionDetailsProvider(new GitCommandRunner())); - var buildVersion = buildVersioner.GetBuildVersion(new BuildVersioningOptions( - fullVersionFormat, - fileVersionFormat, - assemblyVersionFormat, - preReleaseFormat, - buildMetadataFormat - )); + var buildVersion = buildVersioner.GetBuildVersion(new BuildVersioningOptions + { + FullVersionFormat = fullVersionFormat, + FileVersionFormat = fileVersionFormat, + AssemblyVersionFormat = assemblyVersionFormat, + PreReleaseFormat = preReleaseFormat, + BuildMetadataFormat = buildMetadataFormat + }); Console.WriteLine($"{buildVersion.FullVersion};{buildVersion.FileVersion};{buildVersion.AssemblyVersion}"); return 0; diff --git a/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs b/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs index 8d7ae8a..660e774 100644 --- a/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs +++ b/src/TurnerSoftware.BuildVersioning.Tool/VersionDetailsProvider.cs @@ -31,22 +31,24 @@ public VersionDetails GetVersionDetails() if (matchedGroups["major"].Success) { - return new VersionDetails( - MajorVersion: int.Parse(matchedGroups["major"].Value), - MinorVersion: int.Parse(matchedGroups["minor"].Value), - PatchVersion: int.Parse(matchedGroups["patch"].Value), - PreRelease: matchedGroups["preRelease"].Success ? matchedGroups["preRelease"].Value : default, - BuildMetadata: matchedGroups["buildMetadata"].Success ? matchedGroups["buildMetadata"].Value : default, - CommitHeight: int.Parse(matchedGroups["commitHeight"].Value), - IsTaggedRelease: int.Parse(matchedGroups["commitHeight"].Value) == 0, - CommitHash: matchedGroups["commitHash"].Value - ); + return new VersionDetails + { + MajorVersion = int.Parse(matchedGroups["major"].Value), + MinorVersion = int.Parse(matchedGroups["minor"].Value), + PatchVersion = int.Parse(matchedGroups["patch"].Value), + PreRelease = matchedGroups["preRelease"].Success ? matchedGroups["preRelease"].Value : default, + BuildMetadata = matchedGroups["buildMetadata"].Success ? matchedGroups["buildMetadata"].Value : default, + CommitHeight = int.Parse(matchedGroups["commitHeight"].Value), + IsTaggedRelease = int.Parse(matchedGroups["commitHeight"].Value) == 0, + CommitHash = matchedGroups["commitHash"].Value + }; } else { - return new VersionDetails( - matchedGroups["commitHash"].Value - ); + return new VersionDetails + { + CommitHash = matchedGroups["commitHash"].Value + }; } } }