Skip to content

Commit 6801444

Browse files
authored
Merge pull request #3836 from arturcic/build/choco-version
Revert chocolatey package version format
2 parents 940a0aa + 361fefa commit 6801444

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

build/build/Tasks/Package/PackageChocolatey.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public override void Run(BuildContext context)
3737

3838
metaPackageSettings.Dependencies = new[]
3939
{
40-
new ChocolateyNuSpecDependency { Id = "GitVersion.Portable", Version = context.Version?.NugetVersion }
40+
new ChocolateyNuSpecDependency { Id = "GitVersion.Portable", Version = context.Version?.ChocolateyVersion }
4141
};
4242

4343
context.ChocolateyPack(metaPackageSettings);
@@ -48,7 +48,7 @@ private static ChocolateyPackSettings GetChocolateyPackSettings(BuildContextBase
4848
var chocolateySettings = new ChocolateyPackSettings
4949
{
5050
Id = id,
51-
Version = context.Version?.NugetVersion,
51+
Version = context.Version?.ChocolateyVersion,
5252
Title = "GitVersion",
5353
Description = "Derives SemVer information from a repository following GitFlow or GitHubFlow.",
5454
Authors = new[] { "GitTools and Contributors" },
@@ -61,7 +61,7 @@ private static ChocolateyPackSettings GetChocolateyPackSettings(BuildContextBase
6161
IconUrl = new Uri("https://raw.githubusercontent.com/GitTools/graphics/master/GitVersion/Color/icon_100x100.png"),
6262
RequireLicenseAcceptance = false,
6363
Tags = new[] { "Git", "Versioning", "GitVersion", "GitFlowVersion", "GitFlow", "GitHubFlow", "SemVer" },
64-
ReleaseNotes = new[] { $"https://github.com/GitTools/GitVersion/releases/tag/{context.Version?.NugetVersion}" },
64+
ReleaseNotes = new[] { $"https://github.com/GitTools/GitVersion/releases/tag/{context.Version?.ChocolateyVersion}" },
6565
OutputDirectory = Paths.Nuget,
6666
LimitOutput = true,
6767
};

build/common/Utilities/Models.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,28 @@ public record DockerHubCredentials(string Username, string Password);
1515

1616
public record ChocolateyCredentials(string ApiKey);
1717

18-
public record BuildVersion(GitVersion GitVersion, string? Version, string? Milestone, string? SemVersion, string? NugetVersion, bool IsPreRelease)
18+
public record BuildVersion(GitVersion GitVersion, string? Version, string? Milestone, string? SemVersion, string? NugetVersion, string? ChocolateyVersion, bool IsPreRelease)
1919
{
2020
public static BuildVersion Calculate(GitVersion gitVersion)
2121
{
2222
var version = gitVersion.MajorMinorPatch;
2323
var semVersion = gitVersion.SemVer;
2424
var nugetVersion = gitVersion.SemVer;
25+
var chocolateyVersion = gitVersion.MajorMinorPatch;
26+
27+
if (!string.IsNullOrWhiteSpace(gitVersion.PreReleaseTag))
28+
{
29+
// Chocolatey does not support pre-release tags with dots, so we replace them with dashes
30+
// if the pre-release tag is a number, we add a "a" prefix to the pre-release tag
31+
// the trick should be removed when Chocolatey supports semver 2.0
32+
var prefix = int.TryParse(gitVersion.PreReleaseLabel, out _) ? "a" : string.Empty;
33+
chocolateyVersion += $"-{prefix}{gitVersion.PreReleaseTag?.Replace(".", "-")}";
34+
}
2535

2636
if (!string.IsNullOrWhiteSpace(gitVersion.BuildMetaData))
2737
{
2838
semVersion += $"-{gitVersion.BuildMetaData}";
39+
chocolateyVersion += $"-{gitVersion.BuildMetaData}";
2940
nugetVersion += $".{gitVersion.BuildMetaData}";
3041
}
3142

@@ -35,6 +46,7 @@ public static BuildVersion Calculate(GitVersion gitVersion)
3546
Milestone: semVersion,
3647
SemVersion: semVersion,
3748
NugetVersion: nugetVersion?.ToLowerInvariant(),
49+
ChocolateyVersion: chocolateyVersion?.ToLowerInvariant(),
3850
IsPreRelease: !gitVersion.PreReleaseLabel.IsNullOrEmpty()
3951
);
4052
}

0 commit comments

Comments
 (0)