From 361fefa0fba647a645053932ed80787908549a70 Mon Sep 17 00:00:00 2001 From: Artur Stolear Date: Wed, 13 Dec 2023 17:02:15 +0100 Subject: [PATCH] Revert chocolatey package version format Revert chocolatey package version format to non-semver as the Chocolatey Community Repo does not support semver yet --- build/build/Tasks/Package/PackageChocolatey.cs | 6 +++--- build/common/Utilities/Models.cs | 14 +++++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/build/build/Tasks/Package/PackageChocolatey.cs b/build/build/Tasks/Package/PackageChocolatey.cs index 974877642a..73fbe63878 100644 --- a/build/build/Tasks/Package/PackageChocolatey.cs +++ b/build/build/Tasks/Package/PackageChocolatey.cs @@ -37,7 +37,7 @@ public override void Run(BuildContext context) metaPackageSettings.Dependencies = new[] { - new ChocolateyNuSpecDependency { Id = "GitVersion.Portable", Version = context.Version?.NugetVersion } + new ChocolateyNuSpecDependency { Id = "GitVersion.Portable", Version = context.Version?.ChocolateyVersion } }; context.ChocolateyPack(metaPackageSettings); @@ -48,7 +48,7 @@ private static ChocolateyPackSettings GetChocolateyPackSettings(BuildContextBase var chocolateySettings = new ChocolateyPackSettings { Id = id, - Version = context.Version?.NugetVersion, + Version = context.Version?.ChocolateyVersion, Title = "GitVersion", Description = "Derives SemVer information from a repository following GitFlow or GitHubFlow.", Authors = new[] { "GitTools and Contributors" }, @@ -61,7 +61,7 @@ private static ChocolateyPackSettings GetChocolateyPackSettings(BuildContextBase IconUrl = new Uri("https://raw.githubusercontent.com/GitTools/graphics/master/GitVersion/Color/icon_100x100.png"), RequireLicenseAcceptance = false, Tags = new[] { "Git", "Versioning", "GitVersion", "GitFlowVersion", "GitFlow", "GitHubFlow", "SemVer" }, - ReleaseNotes = new[] { $"https://github.com/GitTools/GitVersion/releases/tag/{context.Version?.NugetVersion}" }, + ReleaseNotes = new[] { $"https://github.com/GitTools/GitVersion/releases/tag/{context.Version?.ChocolateyVersion}" }, OutputDirectory = Paths.Nuget, LimitOutput = true, }; diff --git a/build/common/Utilities/Models.cs b/build/common/Utilities/Models.cs index 005f0729b8..d36317d0a9 100644 --- a/build/common/Utilities/Models.cs +++ b/build/common/Utilities/Models.cs @@ -15,17 +15,28 @@ public record DockerHubCredentials(string Username, string Password); public record ChocolateyCredentials(string ApiKey); -public record BuildVersion(GitVersion GitVersion, string? Version, string? Milestone, string? SemVersion, string? NugetVersion, bool IsPreRelease) +public record BuildVersion(GitVersion GitVersion, string? Version, string? Milestone, string? SemVersion, string? NugetVersion, string? ChocolateyVersion, bool IsPreRelease) { public static BuildVersion Calculate(GitVersion gitVersion) { var version = gitVersion.MajorMinorPatch; var semVersion = gitVersion.SemVer; var nugetVersion = gitVersion.SemVer; + var chocolateyVersion = gitVersion.MajorMinorPatch; + + if (!string.IsNullOrWhiteSpace(gitVersion.PreReleaseTag)) + { + // Chocolatey does not support pre-release tags with dots, so we replace them with dashes + // if the pre-release tag is a number, we add a "a" prefix to the pre-release tag + // the trick should be removed when Chocolatey supports semver 2.0 + var prefix = int.TryParse(gitVersion.PreReleaseLabel, out _) ? "a" : string.Empty; + chocolateyVersion += $"-{prefix}{gitVersion.PreReleaseTag?.Replace(".", "-")}"; + } if (!string.IsNullOrWhiteSpace(gitVersion.BuildMetaData)) { semVersion += $"-{gitVersion.BuildMetaData}"; + chocolateyVersion += $"-{gitVersion.BuildMetaData}"; nugetVersion += $".{gitVersion.BuildMetaData}"; } @@ -35,6 +46,7 @@ public static BuildVersion Calculate(GitVersion gitVersion) Milestone: semVersion, SemVersion: semVersion, NugetVersion: nugetVersion?.ToLowerInvariant(), + ChocolateyVersion: chocolateyVersion?.ToLowerInvariant(), IsPreRelease: !gitVersion.PreReleaseLabel.IsNullOrEmpty() ); }