@@ -26,7 +26,7 @@ BuildParameters buildParameters;
2626Setup ( context =>
2727{
2828 buildParameters = new BuildParameters ( Context ) ;
29-
29+
3030 // Executed BEFORE the first task.
3131 Information ( "Xer.DomainDriven" ) ;
3232 Information ( "Parameters" ) ;
@@ -40,9 +40,9 @@ Setup(context =>
4040 Information ( "Dev branch: {0}" , buildParameters . IsDevBranch ) ;
4141 Information ( "Hotfix branch: {0}" , buildParameters . IsHotFixBranch ) ;
4242 Information ( "Pull request: {0}" , buildParameters . IsPullRequest ) ;
43+ Information ( "Apply git tag: {0} | {1}" , buildParameters . ShouldApplyGitTag , buildParameters . GitTagName ) ;
4344 Information ( "Publish to myget: {0}" , buildParameters . ShouldPublishMyGet ) ;
4445 Information ( "Publish to nuget: {0}" , buildParameters . ShouldPublishNuGet ) ;
45- Information ( "Execute git tag: {0}" , buildParameters . ShouldExecuteGitTag ) ;
4646
4747 if ( DirectoryExists ( buildParameters . BuildArtifactsDirectory ) )
4848 {
@@ -108,8 +108,6 @@ Task("Restore")
108108
109109Task ( "Build" )
110110 . Description ( "Builds all the different parts of the project." )
111- . IsDependentOn ( "Clean" )
112- . IsDependentOn ( "Restore" )
113111 . Does ( ( ) =>
114112{
115113 if ( solutions . Count ( ) == 0 )
@@ -158,8 +156,17 @@ Task("Test")
158156 }
159157} ) ;
160158
159+ Task ( "ApplyGitTag" )
160+ . Description ( "Apply a git tag." )
161+ . WithCriteria ( ( ) => buildParameters . ShouldApplyGitTag )
162+ . Does ( ( ) =>
163+ {
164+ Information ( $ "Applying git tag: { buildParameters . GitTagName } ") ;
165+ GitTag ( "./" , buildParameters . GitTagName ) ;
166+ } ) ;
167+
161168Task ( "Pack" )
162- . IsDependentOn ( "Test ")
169+ . Description ( "Create NuGet packages. ")
163170 . Does ( ( ) =>
164171{
165172 var projects = GetFiles ( "./Src/**/*.csproj" ) ;
@@ -185,6 +192,7 @@ Task("Pack")
185192} ) ;
186193
187194Task ( "PublishMyGet" )
195+ . Description ( "Publish NuGet packages to MyGet." )
188196 . WithCriteria ( ( ) => buildParameters . ShouldPublishMyGet )
189197 . IsDependentOn ( "Pack" )
190198 . Does ( ( ) =>
@@ -210,6 +218,7 @@ Task("PublishMyGet")
210218} ) ;
211219
212220Task ( "PublishNuGet" )
221+ . Description ( "Publish NuGet packages to NuGet." )
213222 . WithCriteria ( ( ) => buildParameters . ShouldPublishNuGet )
214223 . IsDependentOn ( "Pack" )
215224 . Does ( ( ) =>
@@ -234,13 +243,13 @@ Task("PublishNuGet")
234243 }
235244} ) ;
236245
237- Task ( "GitTag" )
238- . WithCriteria ( ( ) => buildParameters . ShouldExecuteGitTag )
239- . IsDependentOn ( "PublishNuGet" )
246+ Task ( "PushGitTag" )
247+ . Description ( "Push git tag to remote repository." )
248+ . WithCriteria ( ( ) => buildParameters . ShouldPushGitTag )
249+ . IsDependentOn ( "ApplyGitTag" )
240250 . Does ( ( ) =>
241251{
242- Information ( $ "Creating git tag: { buildParameters . GitTagName } ") ;
243- GitTag ( "./" , buildParameters . GitTagName ) ;
252+ Information ( $ "Pushing git tag: { buildParameters . GitTagName } ") ;
244253 GitPushRef ( "./" , buildParameters . GitHubUsername , buildParameters . GitHubPassword , "origin" , buildParameters . GitTagName ) ;
245254} ) ;
246255
@@ -250,14 +259,15 @@ Task("GitTag")
250259
251260Task ( "Default" )
252261 . Description ( "This is the default task which will be ran if no specific target is passed in." )
253- . IsDependentOn ( "GitTag" )
254- . IsDependentOn ( "PublishNuGet" )
255- . IsDependentOn ( "PublishMyGet" )
256- . IsDependentOn ( "Pack" )
257- . IsDependentOn ( "Test" )
258- . IsDependentOn ( "Build" )
262+ . IsDependentOn ( "Clean" )
259263 . IsDependentOn ( "Restore" )
260- . IsDependentOn ( "Clean" ) ;
264+ . IsDependentOn ( "Build" )
265+ . IsDependentOn ( "Test" )
266+ . IsDependentOn ( "ApplyGitTag" )
267+ . IsDependentOn ( "Pack" )
268+ . IsDependentOn ( "PublishMyGet" )
269+ . IsDependentOn ( "PublishNuGet" )
270+ . IsDependentOn ( "PushGitTag" ) ;
261271
262272///////////////////////////////////////////////////////////////////////////////
263273// EXECUTION
@@ -268,15 +278,13 @@ RunTarget(target);
268278public class BuildParameters
269279{
270280 private ICakeContext _context ;
271- private GitVersion _gitVersion ;
272281
273282 public BuildParameters ( ICakeContext context )
274283 {
275284 _context = context ;
276- _gitVersion = context . GitVersion ( ) ;
277285 }
278286
279- public GitVersion GitVersion => _gitVersion ;
287+ public GitVersion GitVersion => _context . GitVersion ( ) ;
280288
281289 public bool IsAppVeyorBuild => _context . BuildSystem ( ) . AppVeyor . IsRunningOnAppVeyor ;
282290
@@ -321,9 +329,12 @@ public class BuildParameters
321329 && ( IsMasterBranch || IsHotFixBranch || IsReleaseBranch )
322330 && ! IsPullRequest ;
323331
324- public bool ShouldExecuteGitTag => ShouldPublishNuGet ;
332+ public bool ShouldApplyGitTag => ! _context . GitTags ( "./" ) . Any ( t => t . FriendlyName == GitTagName ) ;
333+ public bool ShouldPushGitTag => ! string . IsNullOrWhiteSpace ( GitHubUsername ) &&
334+ ! string . IsNullOrWhiteSpace ( GitHubPassword ) &&
335+ ShouldApplyGitTag ;
325336
326- public string GitTagName => $ "v{ GitVersion . SemVer } ";
337+ public string GitTagName => $ "v{ GitVersion . LegacySemVerPadded } ";
327338
328339 public string BuildArtifactsDirectory => "./BuildArtifacts" ;
329340
0 commit comments