@@ -26,33 +26,22 @@ BuildParameters buildParameters;
2626Setup ( context =>
2727{
2828 buildParameters = new BuildParameters ( Context ) ;
29-
29+
3030 // Executed BEFORE the first task.
3131 Information ( "Xer.DomainDriven" ) ;
32- Information ( "Parameters" ) ;
33- Information ( "///////////////////////////////////////////////////////////////////////////////" ) ;
34- Information ( "Branch: {0}" , buildParameters . BranchName ) ;
35- Information ( "Version semver: {0}" , buildParameters . GitVersion . LegacySemVerPadded ) ;
36- Information ( "Version assembly: {0}" , buildParameters . GitVersion . AssemblySemVer ) ;
37- Information ( "Version informational: {0}" , buildParameters . GitVersion . InformationalVersion ) ;
38- Information ( "Master branch: {0}" , buildParameters . IsMasterBranch ) ;
39- Information ( "Release branch: {0}" , buildParameters . IsReleaseBranch ) ;
40- Information ( "Dev branch: {0}" , buildParameters . IsDevBranch ) ;
41- Information ( "Hotfix branch: {0}" , buildParameters . IsHotFixBranch ) ;
42- Information ( "Pull request: {0}" , buildParameters . IsPullRequest ) ;
43- Information ( "Apply git tag: {0} | {1}" , buildParameters . ShouldApplyGitTag , buildParameters . GitTagName ) ;
44- Information ( "Push git tag: {0} | {1}" , buildParameters . ShouldPushGitTag , buildParameters . GitTagName ) ;
45- Information ( "Publish to myget: {0}" , buildParameters . ShouldPublishMyGet ) ;
46- Information ( "Publish to nuget: {0}" , buildParameters . ShouldPublishNuGet ) ;
47-
32+ Information ( "===========================================================================================" ) ;
33+ Information ( "Git Version" ) ;
34+ Information ( "Semver: {0}" , buildParameters . GitVersion . LegacySemVerPadded ) ;
35+ Information ( "Major minor patch: {0}" , buildParameters . GitVersion . MajorMinorPatch ) ;
36+ Information ( "Assembly: {0}" , buildParameters . GitVersion . AssemblySemVer ) ;
37+ Information ( "Informational: {0}" , buildParameters . GitVersion . InformationalVersion ) ;
4838 if ( DirectoryExists ( buildParameters . BuildArtifactsDirectory ) )
4939 {
5040 // Cleanup build artifacts.
5141 Information ( $ "Cleaning up { buildParameters . BuildArtifactsDirectory } directory.") ;
5242 DeleteDirectory ( buildParameters . BuildArtifactsDirectory , new DeleteDirectorySettings { Recursive = true } ) ;
53- }
54-
55- Information ( "///////////////////////////////////////////////////////////////////////////////" ) ;
43+ }
44+ Information ( "===========================================================================================" ) ;
5645} ) ;
5746
5847Teardown ( context =>
@@ -109,6 +98,8 @@ Task("Restore")
10998
11099Task ( "Build" )
111100 . Description ( "Builds all the different parts of the project." )
101+ . IsDependentOn ( "Clean" )
102+ . IsDependentOn ( "Restore" )
112103 . Does ( ( ) =>
113104{
114105 if ( solutions . Count ( ) == 0 )
@@ -157,17 +148,9 @@ Task("Test")
157148 }
158149} ) ;
159150
160- Task ( "ApplyGitTag" )
161- . Description ( "Apply a git tag." )
162- . WithCriteria ( ( ) => buildParameters . ShouldApplyGitTag )
163- . Does ( ( ) =>
164- {
165- Information ( $ "Applying git tag: { buildParameters . GitTagName } ") ;
166- GitTag ( "./" , buildParameters . GitTagName ) ;
167- } ) ;
168-
169151Task ( "Pack" )
170152 . Description ( "Create NuGet packages." )
153+ . IsDependentOn ( "Test" )
171154 . Does ( ( ) =>
172155{
173156 var projects = GetFiles ( "./Src/**/*.csproj" ) ;
@@ -192,83 +175,17 @@ Task("Pack")
192175 }
193176} ) ;
194177
195- Task ( "PublishMyGet" )
196- . Description ( "Publish NuGet packages to MyGet." )
197- . WithCriteria ( ( ) => buildParameters . ShouldPublishMyGet )
198- . IsDependentOn ( "Pack" )
199- . Does ( ( ) =>
200- {
201- // Nupkgs in BuildArtifacts folder.
202- var nupkgs = GetFiles ( buildParameters . BuildArtifactsDirectory + "/*.nupkg" ) ;
203-
204- if ( nupkgs . Count ( ) == 0 )
205- {
206- Information ( "No nupkgs found." ) ;
207- return ;
208- }
209-
210- foreach ( var nupkgFile in nupkgs )
211- {
212- Information ( "Pulishing to myget {0}" , nupkgFile ) ;
213- NuGetPush ( nupkgFile , new NuGetPushSettings
214- {
215- Source = buildParameters . MyGetFeed ,
216- ApiKey = buildParameters . MyGetApiKey
217- } ) ;
218- }
219- } ) ;
220-
221- Task ( "PublishNuGet" )
222- . Description ( "Publish NuGet packages to NuGet." )
223- . WithCriteria ( ( ) => buildParameters . ShouldPublishNuGet )
224- . IsDependentOn ( "Pack" )
225- . Does ( ( ) =>
226- {
227- // Nupkgs in BuildArtifacts folder.
228- var nupkgs = GetFiles ( buildParameters . BuildArtifactsDirectory + "/*.nupkg" ) ;
229-
230- if ( nupkgs . Count ( ) == 0 )
231- {
232- Information ( "No nupkgs found." ) ;
233- return ;
234- }
235-
236- foreach ( var nupkgFile in nupkgs )
237- {
238- Information ( "Pulishing to nuget {0}" , nupkgFile ) ;
239- NuGetPush ( nupkgFile , new NuGetPushSettings
240- {
241- Source = buildParameters . NuGetFeed ,
242- ApiKey = buildParameters . NuGetApiKey
243- } ) ;
244- }
245- } ) ;
246-
247- Task ( "PushGitTag" )
248- . Description ( "Push git tag to remote repository." )
249- . WithCriteria ( ( ) => buildParameters . ShouldPushGitTag )
250- . IsDependentOn ( "ApplyGitTag" )
251- . Does ( ( ) =>
252- {
253- Information ( $ "Pushing git tag: { buildParameters . GitTagName } ") ;
254- GitPushRef ( "./" , buildParameters . GitHubUsername , buildParameters . GitHubPassword , "origin" , buildParameters . GitTagName ) ;
255- } ) ;
256-
257178///////////////////////////////////////////////////////////////////////////////
258179// TARGETS
259180///////////////////////////////////////////////////////////////////////////////
260181
261182Task ( "Default" )
262183 . Description ( "This is the default task which will be ran if no specific target is passed in." )
263- . IsDependentOn ( "Clean" )
264- . IsDependentOn ( "Restore" )
265- . IsDependentOn ( "Build" )
266- . IsDependentOn ( "Test" )
267- . IsDependentOn ( "ApplyGitTag" )
268184 . IsDependentOn ( "Pack" )
269- . IsDependentOn ( "PublishMyGet" )
270- . IsDependentOn ( "PublishNuGet" )
271- . IsDependentOn ( "PushGitTag" ) ;
185+ . IsDependentOn ( "Test" )
186+ . IsDependentOn ( "Build" )
187+ . IsDependentOn ( "Restore" )
188+ . IsDependentOn ( "Clean" ) ;
272189
273190///////////////////////////////////////////////////////////////////////////////
274191// EXECUTION
@@ -279,66 +196,15 @@ RunTarget(target);
279196public class BuildParameters
280197{
281198 private ICakeContext _context ;
282- private bool _shouldApplyGitTag ;
199+ private GitVersion _gitVersion ;
283200
284201 public BuildParameters ( ICakeContext context )
285202 {
286203 _context = context ;
287- _shouldApplyGitTag = ! context . GitTags ( "./" ) . Any ( t => t . FriendlyName == GitTagName ) ;
288- }
289-
290- public GitVersion GitVersion => _context . GitVersion ( ) ;
291-
292- public bool IsAppVeyorBuild => _context . BuildSystem ( ) . AppVeyor . IsRunningOnAppVeyor ;
293-
294- public bool IsLocalBuild => _context . BuildSystem ( ) . IsLocalBuild ;
295-
296- public bool IsPullRequest => _context . BuildSystem ( ) . AppVeyor . Environment . PullRequest . IsPullRequest ;
297-
298- public string BranchName
299- {
300- get
301- {
302- return IsLocalBuild
303- ? _context . GitBranchCurrent ( "." ) . FriendlyName
304- : _context . BuildSystem ( ) . AppVeyor . Environment . Repository . Branch ;
305- }
204+ _gitVersion = context . GitVersion ( ) ;
306205 }
307-
308- public string GitHubUsername => _context . EnvironmentVariable ( "GITHUB_USERNAME" ) ;
309-
310- public string GitHubPassword => _context . EnvironmentVariable ( "GITHUB_PASSWORD" ) ;
311-
312- public string MyGetFeed => _context . EnvironmentVariable ( "MYGET_SOURCE" ) ;
313-
314- public string MyGetApiKey => _context . EnvironmentVariable ( "MYGET_API_KEY" ) ;
315-
316- public string NuGetFeed => _context . EnvironmentVariable ( "NUGET_SOURCE" ) ;
317-
318- public string NuGetApiKey => _context . EnvironmentVariable ( "NUGET_API_KEY" ) ;
319-
320- public bool IsMasterBranch => StringComparer . OrdinalIgnoreCase . Equals ( "master" , BranchName ) ;
321-
322- public bool IsDevBranch => StringComparer . OrdinalIgnoreCase . Equals ( "dev" , BranchName ) ;
323-
324- public bool IsReleaseBranch => BranchName . StartsWith ( "release" , StringComparison . OrdinalIgnoreCase ) ;
325-
326- public bool IsHotFixBranch => BranchName . StartsWith ( "hotfix" , StringComparison . OrdinalIgnoreCase ) ;
327-
328- public bool ShouldPublishMyGet => ! string . IsNullOrWhiteSpace ( MyGetApiKey ) && ! string . IsNullOrWhiteSpace ( MyGetFeed ) ;
329-
330- public bool ShouldPublishNuGet => ! string . IsNullOrWhiteSpace ( NuGetApiKey )
331- && ! string . IsNullOrWhiteSpace ( NuGetFeed )
332- && ( IsMasterBranch || IsHotFixBranch || IsReleaseBranch )
333- && ! IsPullRequest ;
334-
335- public bool ShouldApplyGitTag => _shouldApplyGitTag ;
336-
337- public bool ShouldPushGitTag => ! string . IsNullOrWhiteSpace ( GitHubUsername ) &&
338- ! string . IsNullOrWhiteSpace ( GitHubPassword ) &&
339- ShouldApplyGitTag ;
340206
341- public string GitTagName => $ "v { GitVersion . LegacySemVerPadded } " ;
207+ public GitVersion GitVersion => _gitVersion ;
342208
343209 public string BuildArtifactsDirectory => "./BuildArtifacts" ;
344210
0 commit comments