1515 "continuous" ,
1616 GitHubActionsImage . UbuntuLatest ,
1717 On = [ GitHubActionsTrigger . Push ] ,
18+ InvokedTargets = [ nameof ( Test ) , nameof ( Pack ) ] ) ]
19+ [ GitHubActions (
20+ "release" ,
21+ GitHubActionsImage . UbuntuLatest ,
22+ OnPushBranches = [ "main" ] ,
23+ OnPushTags = [ "[0-9]+.[0-9]+.[0-9]+" ] ,
1824 ImportSecrets = [ nameof ( NuGetApiKey ) ] ,
1925 InvokedTargets = [ nameof ( Publish ) ] ) ]
2026[ GitHubActions (
@@ -32,27 +38,21 @@ class Build : NukeBuild {
3238 [ Parameter ( $ "NuGet API key - Required for target { nameof ( Publish ) } ") , Secret ]
3339 readonly string NuGetApiKey = null ! ;
3440
35- string ? CurrSemVer => Repository . Tags . SingleOrDefault ( ) ;
41+ bool IsRelease => Version . TryParse ( Repository . Tags . SingleOrDefault ( ) , out _ ) ;
42+
43+ string CurrSemVer => Repository . Tags . Single ( ) ;
3644
3745 string ? prevSemVer ;
3846 string PrevSemVer => prevSemVer ??= Git ( $ "describe --tags --abbrev=0 HEAD^") . Single ( ) . Text ;
3947
40- string SemVer => CurrSemVer ?? $ "{ PrevSemVer } -{ Repository . Branch } -{ Repository . Commit [ ..7 ] } ";
48+ string SemVer => IsRelease ? CurrSemVer : $ "{ PrevSemVer } -{ Repository . Branch } -{ Repository . Commit [ ..7 ] } ";
4149
4250 string ? releaseNotes ;
4351 string ReleaseNotes => releaseNotes ??= Git ( $ "log { PrevSemVer } .. --format=%s") . Select ( o => o . Text ) . Join ( Environment . NewLine ) ;
4452
4553 AbsolutePath ArtifactsDir => RootDirectory / "artifacts" ;
4654 AbsolutePath PackagePath => ArtifactsDir / $ "{ Solution . Json5 . Name } .{ SemVer } .nupkg";
4755
48- Target Info => t => t
49- . Executes ( ( ) => {
50- Log . Information ( "CurrSemVer {0}" , CurrSemVer ) ;
51- Log . Information ( "PrevSemVer {0}" , PrevSemVer ) ;
52- Log . Information ( "SemVer {0}" , SemVer ) ;
53- Log . Information ( "ReleaseNotes {0}" , ReleaseNotes ) ;
54- } ) ;
55-
5656 Target Clean => t => t
5757 . Executes ( ( ) => ArtifactsDir . DeleteDirectory ( ) ) ;
5858
@@ -90,9 +90,8 @@ class Build : NukeBuild {
9090
9191 Target Publish => t => t
9292 . DependsOn ( Test , Pack )
93- . Requires ( ( ) => Repository . IsOnMainBranch ( ) )
9493 . Requires ( ( ) => NuGetApiKey )
95- . OnlyWhenDynamic ( ( ) => Repository . Tags . Count != 0 )
94+ . Requires ( ( ) => Repository . IsOnMainBranch ( ) && IsRelease )
9695 . Executes ( ( ) => /*DotNetNuGetPush(opts => opts
9796 .SetTargetPath(PackagePath)
9897 .SetSource("https://api.nuget.org/v3/index.json")
0 commit comments