1
1
using System ;
2
2
using System . Linq ;
3
+ using System . Threading . Tasks ;
3
4
using Newtonsoft . Json ;
4
5
using Nuke . Common ;
5
6
using Nuke . Common . CI ;
12
13
using Nuke . Common . Tools . DotNet ;
13
14
using Nuke . Common . Tools . GitVersion ;
14
15
using Nuke . Common . Utilities . Collections ;
16
+ using Nuke . GitHub ;
15
17
using static Nuke . Common . EnvironmentInfo ;
16
18
using static Nuke . Common . IO . FileSystemTasks ;
17
19
using static Nuke . Common . IO . PathConstruction ;
@@ -42,7 +44,8 @@ class Build : NukeBuild
42
44
43
45
[ Parameter ] string NugetApiUrl = "https://api.nuget.org/v3/index.json" ; //default
44
46
[ Parameter ] string NugetApiKey ;
45
-
47
+ [ Parameter ] string GitHubAuthenticationToken ;
48
+
46
49
[ Solution ] readonly Solution Solution ;
47
50
[ GitRepository ] readonly GitRepository GitRepository ;
48
51
[ GitVersion ( Framework = "netcoreapp3.1" ) ] readonly GitVersion GitVersion ;
@@ -120,17 +123,9 @@ class Build : NukeBuild
120
123
}
121
124
) ;
122
125
123
- Target DeployToGithubPackage => _ => _
124
- . DependsOn ( Pack )
125
- . Executes ( ( ) =>
126
- {
127
-
128
- }
129
- ) ;
130
-
131
126
Target Deploy => _ => _
132
127
. DependsOn ( Pack )
133
- . OnlyWhenStatic ( ( ) => GitRepository . Branch == "master" )
128
+ . OnlyWhenStatic ( ( ) => GitRepository . IsOnMasterBranch ( ) )
134
129
. Requires ( ( ) => NugetApiUrl )
135
130
. Requires ( ( ) => NugetApiKey )
136
131
. Requires ( ( ) => Configuration . Equals ( Configuration . Release ) )
@@ -152,6 +147,33 @@ class Build : NukeBuild
152
147
}
153
148
) ;
154
149
150
+ Target PublishGithubRelease => _ => _
151
+ . DependsOn ( Deploy )
152
+ . OnlyWhenStatic ( ( ) => GitRepository . IsOnMasterBranch ( ) )
153
+ . Requires ( ( ) => GitHubAuthenticationToken )
154
+ . Requires ( ( ) => Configuration . Equals ( Configuration . Release ) )
155
+ . Executes ( async ( ) =>
156
+ {
157
+ var releaseTag = GitVersion . MajorMinorPatch ;
158
+ var nugets = GlobFiles ( NugetDestinationDirectory , "*.nupkg" )
159
+ . NotEmpty ( )
160
+ . Where ( x => ! x . EndsWith ( "symbols.nupkg" ) )
161
+ . ToArray ( ) ;
162
+
163
+ var repo = GitHubTasks . GetGitHubRepositoryInfo ( GitRepository ) ;
164
+
165
+ await GitHubTasks
166
+ . PublishRelease ( s => s
167
+ . SetArtifactPaths ( nugets )
168
+ . SetCommitSha ( GitVersion . Sha )
169
+ . SetTag ( releaseTag )
170
+ . SetRepositoryName ( repo . repositoryName )
171
+ . SetRepositoryOwner ( repo . gitHubOwner )
172
+ . SetToken ( GitHubAuthenticationToken )
173
+ ) ;
174
+ }
175
+ ) ;
176
+
155
177
Target ContinousIntegration => _ => _
156
- . DependsOn ( Deploy ) ;
178
+ . DependsOn ( PublishGithubRelease ) ;
157
179
}
0 commit comments