@@ -17,43 +17,31 @@ var configuration = Argument<string>("configuration", "Release");
1717
1818var solutions = GetFiles ( "./**/*.sln" ) ;
1919var projects = GetFiles ( "./**/*.csproj" ) . Select ( x => x . GetDirectory ( ) ) ;
20- string buildArtifactsDirectory = "./BuildArtifacts" ;
21-
22- GitVersion gitVersion ;
20+ BuildParameters buildParameters ;
2321
2422///////////////////////////////////////////////////////////////////////////////
2523// SETUP / TEARDOWN
2624///////////////////////////////////////////////////////////////////////////////
2725
2826Setup ( context =>
2927{
30- gitVersion = GitVersion ( new GitVersionSettings {
31- UpdateAssemblyInfo = true
32- } ) ;
33-
34- BuildParameters . Initialize ( Context ) ;
28+ buildParameters = new BuildParameters ( Context ) ;
3529
3630 // Executed BEFORE the first task.
3731 Information ( "Xer.Cqrs.Extensions.SimpleInjector" ) ;
38- Information ( "Parameters" ) ;
39- Information ( "///////////////////////////////////////////////////////////////////////////////" ) ;
40- Information ( "Branch: {0}" , BuildParameters . Instance . BranchName ) ;
41- Information ( "Version semver: {0}" , gitVersion . LegacySemVerPadded ) ;
42- Information ( "Version assembly: {0}" , gitVersion . MajorMinorPatch ) ;
43- Information ( "Version informational: {0}" , gitVersion . InformationalVersion ) ;
44- Information ( "Master branch: {0}" , BuildParameters . Instance . IsMasterBranch ) ;
45- Information ( "Dev branch: {0}" , BuildParameters . Instance . IsDevBranch ) ;
46- Information ( "Hotfix branch: {0}" , BuildParameters . Instance . IsHotFixBranch ) ;
47- Information ( "Publish to myget: {0}" , BuildParameters . Instance . ShouldPublishMyGet ) ;
48- Information ( "Publish to nuget: {0}" , BuildParameters . Instance . ShouldPublishNuGet ) ;
49- Information ( "///////////////////////////////////////////////////////////////////////////////" ) ;
50-
51- if ( DirectoryExists ( buildArtifactsDirectory ) )
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 ) ;
38+ if ( DirectoryExists ( buildParameters . BuildArtifactsDirectory ) )
5239 {
5340 // Cleanup build artifacts.
54- Information ( $ "Cleaning up { buildArtifactsDirectory } directory.") ;
55- DeleteDirectory ( buildArtifactsDirectory , new DeleteDirectorySettings { Recursive = true } ) ;
41+ Information ( $ "Cleaning up { buildParameters . BuildArtifactsDirectory } directory.") ;
42+ DeleteDirectory ( buildParameters . BuildArtifactsDirectory , new DeleteDirectorySettings { Recursive = true } ) ;
5643 }
44+ Information ( "===========================================================================================" ) ;
5745} ) ;
5846
5947Teardown ( context =>
@@ -96,11 +84,7 @@ Task("Restore")
9684
9785 var settings = new DotNetCoreRestoreSettings
9886 {
99- ArgumentCustomization = args => args
100- . Append ( "/p:Version={0}" , gitVersion . LegacySemVerPadded )
101- . Append ( "/p:AssemblyVersion={0}" , gitVersion . MajorMinorPatch )
102- . Append ( "/p:FileVersion={0}" , gitVersion . MajorMinorPatch )
103- . Append ( "/p:AssemblyInformationalVersion={0}" , gitVersion . InformationalVersion )
87+ ArgumentCustomization = args => buildParameters . AppendVersionArguments ( args )
10488 } ;
10589
10690 // Restore all NuGet packages.
@@ -127,11 +111,7 @@ Task("Build")
127111 var settings = new DotNetCoreBuildSettings
128112 {
129113 Configuration = configuration ,
130- ArgumentCustomization = args => args
131- . Append ( "/p:Version={0}" , gitVersion . LegacySemVerPadded )
132- . Append ( "/p:AssemblyVersion={0}" , gitVersion . MajorMinorPatch )
133- . Append ( "/p:FileVersion={0}" , gitVersion . MajorMinorPatch )
134- . Append ( "/p:AssemblyInformationalVersion={0}" , gitVersion . InformationalVersion )
114+ ArgumentCustomization = args => buildParameters . AppendVersionArguments ( args )
135115 } ;
136116
137117 // Build all solutions.
@@ -169,6 +149,7 @@ Task("Test")
169149} ) ;
170150
171151Task ( "Pack" )
152+ . Description ( "Create NuGet packages." )
172153 . IsDependentOn ( "Test" )
173154 . Does ( ( ) =>
174155{
@@ -182,14 +163,10 @@ Task("Pack")
182163
183164 var settings = new DotNetCorePackSettings
184165 {
185- OutputDirectory = buildArtifactsDirectory ,
166+ OutputDirectory = buildParameters . BuildArtifactsDirectory ,
186167 Configuration = configuration ,
187168 NoBuild = true ,
188- ArgumentCustomization = ( args ) => args
189- . Append ( "/p:Version={0}" , gitVersion . LegacySemVerPadded )
190- . Append ( "/p:AssemblyVersion={0}" , gitVersion . MajorMinorPatch )
191- . Append ( "/p:FileVersion={0}" , gitVersion . MajorMinorPatch )
192- . Append ( "/p:AssemblyInformationalVersion={0}" , gitVersion . InformationalVersion )
169+ ArgumentCustomization = args => buildParameters . AppendVersionArguments ( args )
193170 } ;
194171
195172 foreach ( var project in projects )
@@ -198,66 +175,17 @@ Task("Pack")
198175 }
199176} ) ;
200177
201- Task ( "PublishMyGet" )
202- . WithCriteria ( ( ) => BuildParameters . Instance . ShouldPublishMyGet )
203- . IsDependentOn ( "Pack" )
204- . Does ( ( ) =>
205- {
206- // Nupkgs in BuildArtifacts folder.
207- var nupkgs = GetFiles ( buildArtifactsDirectory + "/*.nupkg" ) ;
208-
209- if ( nupkgs . Count ( ) == 0 )
210- {
211- Information ( "No nupkgs found." ) ;
212- return ;
213- }
214-
215- foreach ( var nupkgFile in nupkgs )
216- {
217- Information ( "Pulishing to myget {0}" , nupkgFile ) ;
218-
219- NuGetPush ( nupkgFile , new NuGetPushSettings
220- {
221- Source = BuildParameters . Instance . MyGetFeed ,
222- ApiKey = BuildParameters . Instance . MyGetApiKey
223- } ) ;
224- }
225- } ) ;
226-
227- Task ( "PublishNuGet" )
228- . WithCriteria ( ( ) => BuildParameters . Instance . ShouldPublishNuGet )
229- . IsDependentOn ( "Pack" )
230- . Does ( ( ) =>
231- {
232- // Nupkgs in BuildArtifacts folder.
233- var nupkgs = GetFiles ( buildArtifactsDirectory + "/*.nupkg" ) ;
234-
235- if ( nupkgs . Count ( ) == 0 )
236- {
237- Information ( "No nupkgs found." ) ;
238- return ;
239- }
240-
241- foreach ( var nupkgFile in nupkgs )
242- {
243- Information ( "Pulishing to nuget {0}" , nupkgFile ) ;
244- NuGetPush ( nupkgFile , new NuGetPushSettings
245- {
246- Source = BuildParameters . Instance . NuGetFeed ,
247- ApiKey = BuildParameters . Instance . NuGetApiKey
248- } ) ;
249- }
250- } ) ;
251-
252-
253178///////////////////////////////////////////////////////////////////////////////
254179// TARGETS
255180///////////////////////////////////////////////////////////////////////////////
256181
257182Task ( "Default" )
258183 . Description ( "This is the default task which will be ran if no specific target is passed in." )
259- . IsDependentOn ( "PublishNuGet" )
260- . IsDependentOn ( "PublishMyGet" ) ;
184+ . IsDependentOn ( "Pack" )
185+ . IsDependentOn ( "Test" )
186+ . IsDependentOn ( "Build" )
187+ . IsDependentOn ( "Restore" )
188+ . IsDependentOn ( "Clean" ) ;
261189
262190///////////////////////////////////////////////////////////////////////////////
263191// EXECUTION
@@ -266,61 +194,23 @@ Task("Default")
266194RunTarget ( target ) ;
267195
268196public class BuildParameters
269- {
270- private static BuildParameters _buildParameters ;
271-
272- public static BuildParameters Instance => _buildParameters ;
273-
197+ {
274198 private ICakeContext _context ;
199+ private GitVersion _gitVersion ;
275200
276- private BuildParameters ( ICakeContext context )
201+ public BuildParameters ( ICakeContext context )
277202 {
278203 _context = context ;
204+ _gitVersion = context . GitVersion ( ) ;
279205 }
280206
281- public static void Initialize ( ICakeContext context )
282- {
283- if ( _buildParameters != null )
284- {
285- return ;
286- }
287-
288- _buildParameters = new BuildParameters ( context ) ;
289- }
290-
291- public bool IsAppVeyorBuild => _context . BuildSystem ( ) . AppVeyor . IsRunningOnAppVeyor ;
292-
293- public bool IsLocalBuild => _context . BuildSystem ( ) . IsLocalBuild ;
294-
295- public string BranchName
296- {
297- get
298- {
299- return IsLocalBuild
300- ? _context . GitBranchCurrent ( "." ) . FriendlyName
301- : _context . BuildSystem ( ) . AppVeyor . Environment . Repository . Branch ;
302- }
303- }
304-
305- public string MyGetFeed => _context . EnvironmentVariable ( "MYGET_SOURCE" ) ;
306-
307- public string MyGetApiKey => _context . EnvironmentVariable ( "MYGET_API_KEY" ) ;
308-
309- public string NuGetFeed => _context . EnvironmentVariable ( "NUGET_SOURCE" ) ;
310-
311- public string NuGetApiKey => _context . EnvironmentVariable ( "NUGET_API_KEY" ) ;
312-
313- public bool IsMasterBranch => StringComparer . OrdinalIgnoreCase . Equals ( "master" , BranchName ) ;
314-
315- public bool IsDevBranch => StringComparer . OrdinalIgnoreCase . Equals ( "dev" , BranchName ) ;
316-
317- public bool IsReleaseBranch => BranchName . StartsWith ( "release" , StringComparison . OrdinalIgnoreCase ) ;
318-
319- public bool IsHotFixBranch => BranchName . StartsWith ( "hotfix" , StringComparison . OrdinalIgnoreCase ) ;
207+ public GitVersion GitVersion => _gitVersion ;
320208
321- public bool ShouldPublishMyGet => ! string . IsNullOrWhiteSpace ( MyGetApiKey ) && ! string . IsNullOrWhiteSpace ( MyGetFeed ) ;
209+ public string BuildArtifactsDirectory => "./BuildArtifacts" ;
322210
323- public bool ShouldPublishNuGet => ! string . IsNullOrWhiteSpace ( NuGetApiKey )
324- && ! string . IsNullOrWhiteSpace ( NuGetFeed )
325- && ( IsMasterBranch || IsHotFixBranch ) ;
211+ public ProcessArgumentBuilder AppendVersionArguments ( ProcessArgumentBuilder args ) => args
212+ . Append ( "/p:Version={0}" , GitVersion . LegacySemVerPadded )
213+ . Append ( "/p:AssemblyVersion={0}" , GitVersion . MajorMinorPatch )
214+ . Append ( "/p:FileVersion={0}" , GitVersion . MajorMinorPatch )
215+ . Append ( "/p:AssemblyInformationalVersion={0}" , GitVersion . InformationalVersion ) ;
326216}
0 commit comments