@@ -15,17 +15,28 @@ public record DockerHubCredentials(string Username, string Password);
1515
1616public 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