15
15
"continuous" ,
16
16
GitHubActionsImage . UbuntuLatest ,
17
17
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]+" ] ,
18
24
ImportSecrets = [ nameof ( NuGetApiKey ) ] ,
19
25
InvokedTargets = [ nameof ( Publish ) ] ) ]
20
26
[ GitHubActions (
@@ -32,27 +38,21 @@ class Build : NukeBuild {
32
38
[ Parameter ( $ "NuGet API key - Required for target { nameof ( Publish ) } ") , Secret ]
33
39
readonly string NuGetApiKey = null ! ;
34
40
35
- string ? CurrSemVer => Repository . Tags . SingleOrDefault ( ) ;
41
+ bool IsRelease => Version . TryParse ( Repository . Tags . SingleOrDefault ( ) , out _ ) ;
42
+
43
+ string CurrSemVer => Repository . Tags . Single ( ) ;
36
44
37
45
string ? prevSemVer ;
38
46
string PrevSemVer => prevSemVer ??= Git ( $ "describe --tags --abbrev=0 HEAD^") . Single ( ) . Text ;
39
47
40
- string SemVer => CurrSemVer ?? $ "{ PrevSemVer } -{ Repository . Branch } -{ Repository . Commit [ ..7 ] } ";
48
+ string SemVer => IsRelease ? CurrSemVer : $ "{ PrevSemVer } -{ Repository . Branch } -{ Repository . Commit [ ..7 ] } ";
41
49
42
50
string ? releaseNotes ;
43
51
string ReleaseNotes => releaseNotes ??= Git ( $ "log { PrevSemVer } .. --format=%s") . Select ( o => o . Text ) . Join ( Environment . NewLine ) ;
44
52
45
53
AbsolutePath ArtifactsDir => RootDirectory / "artifacts" ;
46
54
AbsolutePath PackagePath => ArtifactsDir / $ "{ Solution . Json5 . Name } .{ SemVer } .nupkg";
47
55
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
-
56
56
Target Clean => t => t
57
57
. Executes ( ( ) => ArtifactsDir . DeleteDirectory ( ) ) ;
58
58
@@ -90,9 +90,8 @@ class Build : NukeBuild {
90
90
91
91
Target Publish => t => t
92
92
. DependsOn ( Test , Pack )
93
- . Requires ( ( ) => Repository . IsOnMainBranch ( ) )
94
93
. Requires ( ( ) => NuGetApiKey )
95
- . OnlyWhenDynamic ( ( ) => Repository . Tags . Count != 0 )
94
+ . Requires ( ( ) => Repository . IsOnMainBranch ( ) && IsRelease )
96
95
. Executes ( ( ) => /*DotNetNuGetPush(opts => opts
97
96
.SetTargetPath(PackagePath)
98
97
.SetSource("https://api.nuget.org/v3/index.json")
0 commit comments