1
1
using Nuke . Common ;
2
+ using Nuke . Common . CI . GitHubActions ;
2
3
using Nuke . Common . Git ;
3
4
using Nuke . Common . IO ;
4
5
using Nuke . Common . ProjectModel ;
5
6
using Nuke . Common . Tooling ;
6
7
using Nuke . Common . Tools . DotNet ;
7
8
using Nuke . Common . Utilities ;
8
- using Nuke . Common . Utilities . Collections ;
9
9
10
10
using Serilog ;
11
11
12
12
using static Nuke . Common . Tools . DotNet . DotNetTasks ;
13
13
14
+ [ GitHubActions (
15
+ "continuous" ,
16
+ GitHubActionsImage . UbuntuLatest ,
17
+ On = [ GitHubActionsTrigger . Push ] ,
18
+ ImportSecrets = [ nameof ( NuGetApiKey ) ] ,
19
+ InvokedTargets = [ nameof ( Publish ) ] ) ]
20
+ [ GitHubActions (
21
+ "pr" ,
22
+ GitHubActionsImage . UbuntuLatest ,
23
+ On = [ GitHubActionsTrigger . PullRequest ] ,
24
+ InvokedTargets = [ nameof ( Test ) , nameof ( Pack ) ] ) ]
14
25
class Build : NukeBuild {
15
26
public static int Main ( ) => Execute < Build > ( x => x . Compile ) ;
16
27
@@ -19,15 +30,29 @@ class Build : NukeBuild {
19
30
[ PathVariable ] readonly Tool Git = null ! ;
20
31
21
32
[ Parameter ( $ "NuGet API key - Required for target { nameof ( Publish ) } ") , Secret ]
22
- readonly string NugetApiKey = null ! ;
33
+ readonly string NuGetApiKey = null ! ;
23
34
24
- string SemVer => Repository . Tags . SingleOrError ( $ "Last commit { Repository . Commit [ ..7 ] } wasn't tagged.") ;
25
- string PrevSemVer => Git ( "describe --tags --abbrev=0 HEAD^" ) . Single ( ) . Text ;
26
- string CommitMsgsSinceLastSemVer => Git ( $ "log { PrevSemVer } ..HEAD --format=%s") . Select ( o => o . Text ) . Join ( Environment . NewLine ) ;
35
+ string ? CurrSemVer => Repository . Tags . SingleOrDefault ( ) ;
36
+
37
+ string ? prevSemVer ;
38
+ string PrevSemVer => prevSemVer ??= Git ( $ "describe --tags --abbrev=0 HEAD^") . Single ( ) . Text ;
39
+
40
+ string SemVer => CurrSemVer ?? $ "{ PrevSemVer } -{ Repository . Branch } -{ Repository . Commit [ ..7 ] } ";
41
+
42
+ string ? releaseNotes ;
43
+ string ReleaseNotes => releaseNotes ??= Git ( $ "log { PrevSemVer } .. --format=%s") . Select ( o => o . Text ) . Join ( Environment . NewLine ) ;
27
44
28
45
AbsolutePath ArtifactsDir => RootDirectory / "artifacts" ;
29
46
AbsolutePath PackagePath => ArtifactsDir / $ "{ Solution . Json5 . Name } .{ SemVer } .nupkg";
30
47
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
+
31
56
Target Clean => t => t
32
57
. Executes ( ( ) => ArtifactsDir . DeleteDirectory ( ) ) ;
33
58
@@ -44,6 +69,7 @@ class Build : NukeBuild {
44
69
45
70
Target Pack => t => t
46
71
. DependsOn ( Clean , Compile )
72
+ . Produces ( ArtifactsDir / "*.nupkg" , ArtifactsDir / "*.snupkg" )
47
73
. Executes ( ( ) => DotNetPack ( opts => opts
48
74
. SetProject ( Solution . Json5 )
49
75
. SetNoBuild ( true )
@@ -52,7 +78,7 @@ class Build : NukeBuild {
52
78
. SetTitle ( "JSON5" )
53
79
. SetDescription ( "JSON5 for your dotnet appsettings files." )
54
80
. SetPackageTags ( "JSON5 JSON parser translator deserializer appsettings configuration hosting" )
55
- . SetPackageReleaseNotes ( CommitMsgsSinceLastSemVer )
81
+ . SetPackageReleaseNotes ( ReleaseNotes )
56
82
. SetAuthors ( "Robert Hofmann" )
57
83
. AddProcessAdditionalArguments ( "-p:PackageLicenseExpression=MIT" )
58
84
. SetRepositoryUrl ( "https://github.com/bert2/json5-dotnet.git" )
@@ -65,10 +91,11 @@ class Build : NukeBuild {
65
91
Target Publish => t => t
66
92
. DependsOn ( Test , Pack )
67
93
. Requires ( ( ) => Repository . IsOnMainBranch ( ) )
68
- . Requires ( ( ) => NugetApiKey )
94
+ . Requires ( ( ) => NuGetApiKey )
95
+ . OnlyWhenDynamic ( ( ) => Repository . Tags . Count != 0 )
69
96
. Executes ( ( ) => /*DotNetNuGetPush(opts => opts
70
97
.SetTargetPath(PackagePath)
71
- .SetSource("https://www .nuget.org/")
98
+ .SetSource("https://api .nuget.org/v3/index.json ")
72
99
.SetApiKey(NugetApiKey)));*/
73
- Log . Information ( $ "{ string . Join ( "," , Repository . Tags ) } dotnet nuget push { PackagePath } --source https://www .nuget.org/ --api-key { NugetApiKey } ") ) ;
100
+ Log . Information ( $ "{ string . Join ( "," , Repository . Tags ) } dotnet nuget push { PackagePath } --source https://api .nuget.org/v3/index.json --api-key { NuGetApiKey } ") ) ;
74
101
}
0 commit comments