Skip to content

Commit a1be3b7

Browse files
committedJul 27, 2019
Updated build scripts
1 parent a3078dc commit a1be3b7

File tree

5 files changed

+198
-79
lines changed

5 files changed

+198
-79
lines changed
 

‎build.cake

+125-53
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#l "tools/versionUtils.cake"
77
#l "tools/settingsUtils.cake"
88
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.9.0"
9-
#addin "Cake.Incubator"
9+
#addin "nuget:?package=Cake.Incubator&version=5.0.1"
1010

1111
///////////////////////////////////////////////////////////////////////////////
1212
// ARGUMENTS
@@ -161,12 +161,13 @@ Task("Build")
161161
if (!string.IsNullOrEmpty(versionInfo.ToVersionSuffix()))
162162
dotNetCoreBuildSettings.SetVersionSuffix(versionInfo.ToVersionSuffix());
163163
if (!string.IsNullOrEmpty(versionInfo.ToString()))
164-
dotNetCoreBuildSettings.SetFileVersion(versionInfo.ToString(true));
165-
164+
dotNetCoreBuildSettings.SetFileVersion(versionInfo.ToString(false));
165+
166166
DotNetCoreBuild(solution.ToString(), new DotNetCoreBuildSettings
167167
{
168168
Configuration = settings.Configuration,
169-
MSBuildSettings = dotNetCoreBuildSettings
169+
MSBuildSettings = dotNetCoreBuildSettings,
170+
Verbosity = DotNetCoreVerbosity.Minimal
170171
}
171172
);
172173
break;
@@ -193,10 +194,54 @@ Task("UnitTest")
193194
.WithCriteria(settings.ExecuteUnitTest)
194195
.IsDependentOn("Build")
195196
.Does(() =>
197+
{
198+
switch (settings.Test.Framework)
199+
{
200+
case TestFrameworkTypes.DotNetCore:
201+
RunTarget("UnitTest-DotNetCore");
202+
203+
break;
204+
default:
205+
RunTarget("UnitTest-CLI");
206+
207+
break;
208+
}
209+
});
210+
211+
Task("UnitTest-DotNetCore")
212+
.Description("Run dotnetcore based unit tests for the solution.")
213+
.WithCriteria(settings.ExecuteUnitTest)
214+
.Does(() =>
196215
{
197216
// Run all unit tests we can find.
198217

199-
var assemplyFilePath = string.Format("{0}/**/bin/{1}/{2}", settings.Test.SourcePath, settings.Configuration, settings.Test.AssemblyFileSpec);
218+
var filePath = string.Format("{0}/**/{1}", settings.Test.SourcePath, settings.Test.FileSpec);
219+
220+
Information("Unit Test Files: {0}", filePath);
221+
222+
var testProjects = GetFiles(filePath);
223+
var testSettings = new DotNetCoreTestSettings()
224+
{
225+
Configuration = settings.Configuration,
226+
NoBuild = true
227+
};
228+
229+
foreach(var p in testProjects)
230+
{
231+
Information("Executing Tests for {0}", p);
232+
233+
DotNetCoreTest(p.ToString(), testSettings);
234+
}
235+
});
236+
237+
Task("UnitTest-CLI")
238+
.Description("Run unit tests for the solution.")
239+
.WithCriteria(settings.ExecuteUnitTest)
240+
.Does(() =>
241+
{
242+
// Run all unit tests we can find.
243+
244+
var assemplyFilePath = string.Format("{0}/**/bin/{1}/**/{2}", settings.Test.SourcePath, settings.Configuration, settings.Test.FileSpec);
200245

201246
Information("Unit Test Files: {0}", assemplyFilePath);
202247

@@ -286,28 +331,35 @@ Task("Nuget-Package-DotNetCore")
286331
if (!string.IsNullOrEmpty(versionInfo.ToString()))
287332
dotNetCoreBuildSettings.SetFileVersion(versionInfo.ToString(true));
288333

289-
var dncps = new DotNetCorePackSettings
290-
{
291-
Configuration = settings.Configuration,
292-
OutputDirectory = artifactsPath,
293-
IncludeSymbols = settings.NuGet.IncludeSymbols,
294-
NoBuild = true,
295-
NoRestore = true,
296-
MSBuildSettings = dotNetCoreBuildSettings
297-
};
298-
299-
Information("Location of Artifacts: {0}", artifactsPath);
300-
301-
foreach(var solution in solutions)
302-
{
334+
var opts = new DotNetCorePackSettings
335+
{
336+
Configuration = settings.Configuration,
337+
OutputDirectory = artifactsPath,
338+
NoBuild = true,
339+
NoRestore = true,
340+
MSBuildSettings = dotNetCoreBuildSettings
341+
};
342+
343+
if (!string.IsNullOrEmpty(versionInfo.ToVersionSuffix()))
344+
opts.VersionSuffix = versionInfo.ToVersionSuffix();
345+
346+
if (settings.NuGet.IncludeSymbols) {
347+
opts.ArgumentCustomization = args => args.Append("--include-symbols -p:SymbolPackageFormat=snupkg");
348+
}
349+
350+
Information("Location of Artifacts: {0}", artifactsPath);
351+
352+
foreach(var solution in solutions)
353+
{
303354
Information("Building Packages for {0}", solution);
304355

305356
try {
306-
//DotNetCorePack("./src/**/*.csproj", dncps);
307-
DotNetCorePack(solution.ToString(), dncps);
357+
//DotNetCorePack("./src/**/*.csproj", opts);
358+
DotNetCorePack(solution.ToString(), opts);
308359
}
309360
catch (Exception ex)
310361
{
362+
Debug(ex.Message);
311363
Information("There was a problem with packing some of the projects in {0}", solution);
312364
}
313365
}
@@ -324,6 +376,19 @@ Task("Nuget-Package-CLI")
324376
CreateDirectory(artifactsPath);
325377

326378
var nuspecFiles = GetFiles(settings.NuGet.NuSpecFileSpec);
379+
380+
var opts = new NuGetPackSettings {
381+
Version = versionInfo.ToString(),
382+
ReleaseNotes = versionInfo.ReleaseNotes,
383+
Properties = nugetProps,
384+
OutputDirectory = artifactsPath,
385+
Symbols = settings.NuGet.IncludeSymbols
386+
};
387+
388+
//if (settings.NuGet.IncludeSymbols) {
389+
// opts.ArgumentCustomization = args => args.Append("-Symbols -SymbolPackageFormat snupkg");
390+
//}
391+
327392
foreach(var nsf in nuspecFiles)
328393
{
329394
Information("Packaging {0}", nsf);
@@ -336,13 +401,7 @@ Task("Nuget-Package-CLI")
336401
VersionUtils.UpdateNuSpecVersionDependency(Context, settings, versionInfo, nsf.ToString());
337402
}
338403

339-
NuGetPack(nsf, new NuGetPackSettings {
340-
Version = versionInfo.ToString(),
341-
ReleaseNotes = versionInfo.ReleaseNotes,
342-
Symbols = true,
343-
Properties = nugetProps,
344-
OutputDirectory = artifactsPath
345-
});
404+
NuGetPack(nsf, opts);
346405
}
347406
});
348407

@@ -355,23 +414,31 @@ Task("Nuget-Publish")
355414

356415
CreateDirectory(artifactsPath);
357416

358-
if (settings.NuGet.FeedApiKey.ToLower() == "local")
417+
switch (settings.NuGet.FeedApiKey.ToUpper())
359418
{
360-
settings.NuGet.FeedUrl = Directory(settings.NuGet.FeedUrl).Path.FullPath;
361-
//Information("Using Local repository: {0}", settings.NuGet.FeedUrl);
419+
case "LOCAL":
420+
settings.NuGet.FeedUrl = Directory(settings.NuGet.FeedUrl).Path.FullPath;
421+
//Information("Using Local repository: {0}", settings.NuGet.FeedUrl);
422+
break;
423+
case "NUGETAPIKEY":
424+
if (!System.IO.File.Exists("nugetapi.key"))
425+
{
426+
Error("Could not load nugetapi.key");
427+
return;
428+
}
429+
430+
settings.NuGet.FeedApiKey = System.IO.File.ReadAllText("nugetapi.key");
431+
break;
432+
case "AzureDevOps":
433+
case "VSTS":
434+
if (BuildSystem.IsRunningOnAzurePipelinesHosted)
435+
{
436+
//settings.NuGet.FeedApiKey = EnvironmentVariable("SYSTEM_ACCESSTOKEN");
437+
settings.NuGet.FeedApiKey = "AzureDevOps";
438+
}
439+
break;
362440
}
363441

364-
if (settings.NuGet.FeedApiKey == "NUGETAPIKEY")
365-
{
366-
if (!System.IO.File.Exists("nugetapi.key"))
367-
{
368-
Error("Could not load nugetapi.key");
369-
return;
370-
}
371-
372-
settings.NuGet.FeedApiKey = System.IO.File.ReadAllText("nugetapi.key");
373-
}
374-
375442
if (string.IsNullOrEmpty(settings.NuGet.NuGetConfig)) settings.NuGet.NuGetConfig = null;
376443

377444
switch (settings.NuGet.BuildType)
@@ -401,18 +468,23 @@ Task("Nuget-Publish-DotNetCore")
401468

402469
Information("\t{0}", string.Join("\n\t", nupkgFiles.Select(x => x.GetFilename().ToString()).ToList()));
403470

404-
var dncps = new DotNetCoreNuGetPushSettings
471+
var opts = new DotNetCoreNuGetPushSettings
405472
{
406473
Source = settings.NuGet.FeedUrl,
407474
ApiKey = settings.NuGet.FeedApiKey
475+
// ,Verbosity = DotNetCoreVerbosity.Detailed
408476
};
409-
477+
478+
//if (settings.NuGet.IncludeSymbols) {
479+
// opts.ArgumentCustomization = args => args.Append("-Symbols -SymbolPackageFormat snupkg");
480+
//}
481+
410482
foreach (var n in nupkgFiles)
411483
{
412-
//Information("Pushing Package: {0}", n);
484+
Information("Pushing Package: {0}", n);
413485

414486
try {
415-
DotNetCoreNuGetPush(n.ToString(), dncps);
487+
DotNetCoreNuGetPush(n.ToString(), opts);
416488
}
417489
catch (Exception ex)
418490
{
@@ -446,24 +518,24 @@ Task("Nuget-Publish-CLI")
446518

447519
Information("\t{0}", string.Join("\n\t", nupkgFiles.Select(x => x.GetFilename().ToString()).ToList()));
448520

449-
if (BuildSystem.IsRunningOnVSTS)
450-
{
451-
settings.NuGet.FeedApiKey = EnvironmentVariable("SYSTEM_ACCESSTOKEN");
452-
}
521+
// if (BuildSystem.IsRunningOnAzurePipelinesHosted)
522+
// {
523+
// settings.NuGet.FeedApiKey = EnvironmentVariable("SYSTEM_ACCESSTOKEN");
524+
// }
453525

454-
var nugetSettings = new NuGetPushSettings {
526+
var opts = new NuGetPushSettings {
455527
Source = settings.NuGet.FeedUrl,
456528
ApiKey = settings.NuGet.FeedApiKey,
457529
Verbosity = NuGetVerbosity.Detailed
458530
};
459-
531+
460532
foreach (var n in nupkgFiles)
461533
{
462534
Information("Pushing Package: {0}", n);
463535

464536
try
465537
{
466-
NuGetPush(n, nugetSettings);
538+
NuGetPush(n, opts);
467539
}
468540
catch (Exception ex)
469541
{

‎build.version.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"major":1,"minor":1,"build":19,"preRelease":4,"releaseNotes":["Added support for .NET core","Added a new ArrayConverter","Fixed a bug in the DateConverter"]}
1+
{"major":1,"minor":1,"build":19,"preRelease":0,"releaseNotes":[]}

‎tools/packages.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Cake" version="0.31.0" />
3+
<package id="Cake" version="0.33.0" />
44
</packages>

‎tools/settingsUtils.cake

+16-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#addin "Cake.Json&version=3.0.1"
2-
#addin "nuget:?package=Newtonsoft.Json&version=9.0.1"
1+
#addin "nuget:?package=Cake.Json&version=3.0.1"
2+
#addin "nuget:?package=Newtonsoft.Json&version=12.0.2"
3+
34
using Newtonsoft.Json;
45

56
public class SettingsUtils
@@ -59,6 +60,7 @@ public class SettingsUtils
5960
obj.Version.VersionFile = obj.VersionFile;
6061
obj.Version.AutoIncrementVersion = GetBoolArgument(context, "autoincrementversion", obj.Version.AutoIncrementVersion);
6162
obj.Version.AutoIncrementVersion = GetBoolArgument(context, "autoversion", obj.Version.AutoIncrementVersion);
63+
obj.Version.LoadFrom = context.Argument<VersionSourceTypes>("loadVersionFrom", obj.Version.LoadFrom);
6264

6365
if (obj.Xamarin == null) obj.Xamarin = new XamarinSettings();
6466

@@ -71,10 +73,10 @@ public class SettingsUtils
7173

7274
obj.NuGet.BuildType = context.Argument<string>("BuildType", obj.NuGet.BuildType);
7375
obj.NuGet.PublishType = context.Argument<string>("PublishType", obj.NuGet.PublishType);
74-
obj.NuGet.FeedUrl = GetStringArgument(context, "nugetFeed", obj.NuGet.FeedUrl, true);
75-
obj.NuGet.FeedUrl = GetStringArgument(context, "nugetFeedUrl", obj.NuGet.FeedUrl, true);
76+
obj.NuGet.FeedUrl = context.Argument<string>("nugetFeed", obj.NuGet.FeedUrl);
77+
obj.NuGet.FeedUrl = context.Argument<string>("nugetFeedUrl", obj.NuGet.FeedUrl);
7678

77-
obj.NuGet.FeedApiKey = GetStringArgument(context, "nugetApiKey", obj.NuGet.FeedApiKey, true);
79+
obj.NuGet.FeedApiKey = context.Argument<string>("nugetApiKey", obj.NuGet.FeedApiKey);
7880

7981
obj.NuGet.LibraryMinVersionDependency = (context.Argument<string>("dependencyVersion", obj.NuGet.LibraryMinVersionDependency)).Replace(":",".");
8082
obj.NuGet.VersionDependencyTypeForLibrary = context.Argument<VersionDependencyTypes>("dependencyType", obj.NuGet.VersionDependencyTypeForLibrary);
@@ -94,16 +96,7 @@ public class SettingsUtils
9496

9597
return result;
9698
}
97-
98-
private static string GetStringArgument(ICakeContext context, string argumentName, string defaultValue, bool useDefaultIfEmptyOrNull)
99-
{
100-
var result = context.Argument<string>(argumentName, defaultValue);
101-
102-
if (string.IsNullOrEmpty(result)) return defaultValue;
103-
104-
return result;
105-
}
106-
99+
107100
private static string ExpandSettingsPath(string settingsPath, string rootPath)
108101
{
109102
if (settingsPath.StartsWith("./")) settingsPath = settingsPath.Replace("./", rootPath);
@@ -296,21 +289,21 @@ public class TestSettings
296289
{
297290
SourcePath = "./tests";
298291
ResultsPath = "./tests";
299-
AssemblyFileSpec = "*.UnitTests.dll";
292+
FileSpec = "*.UnitTests.dll";
300293
Framework = TestFrameworkTypes.NUnit3;
301294
}
302295

303296
public string SourcePath {get;set;}
304297
public string ResultsPath {get;set;}
305-
public string AssemblyFileSpec {get;set;}
298+
public string FileSpec {get;set;}
306299
public TestFrameworkTypes Framework {get;set;}
307300

308301
public void Display(ICakeContext context)
309302
{
310303
context.Information("Test Settings:");
311304
context.Information("\tSource Path: {0}", SourcePath);
312305
context.Information("\tResults Path: {0}", ResultsPath);
313-
context.Information("\tTest Assemploes File Spec: {0}", AssemblyFileSpec);
306+
context.Information("\tTest Assemploes File Spec: {0}", FileSpec);
314307
}
315308
}
316309

@@ -327,6 +320,7 @@ public class NuGetSettings
327320
UpdateLibraryDependencies = false;
328321
LibraryNamespaceBase = null;
329322
LibraryMinVersionDependency = null;
323+
IncludeSymbols = true;
330324
}
331325

332326
public string BuildType {get;set;}
@@ -391,6 +385,8 @@ public enum VersionSourceTypes {
391385
versionfile,
392386
assemblyinfo,
393387
git,
388+
commandline,
389+
azuredevops,
394390
tfs
395391
}
396392

@@ -399,5 +395,6 @@ public enum TestFrameworkTypes {
399395
NUnit2,
400396
NUnit3,
401397
XUnit,
402-
XUnit2
398+
XUnit2,
399+
DotNetCore
403400
}

‎tools/versionUtils.cake

+55-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#addin "Cake.Json&version=3.0.1"
2-
#addin "Cake.FileHelpers&version=3.1.0"
3-
#addin "nuget:?package=Newtonsoft.Json&version=9.0.1"
1+
#addin "nuget:?package=Cake.Json&version=3.0.1"
2+
#addin "nuget:?package=Cake.FileHelpers&version=3.2.0"
3+
#addin "nuget:?package=Newtonsoft.Json&version=12.0.2"
44
#tool "nuget:?package=GitVersion.CommandLine&version=4.0.0"
55

66
using Newtonsoft.Json;
@@ -29,9 +29,15 @@ public class VersionUtils
2929
case VersionSourceTypes.git:
3030
verInfo = LoadVersionFromGit(context);
3131
break;
32+
case VersionSourceTypes.azuredevops:
33+
//verInfo = LoadVersionFromAzureDevOps(context);
34+
break;
3235
case VersionSourceTypes.tfs:
3336
//verInfo = LoadVersionFromTfs(context);
3437
break;
38+
case VersionSourceTypes.commandline:
39+
verInfo = LoadVersionFromCommandLine(context);
40+
break;
3541
}
3642

3743
if (verInfo != null)
@@ -87,7 +93,7 @@ public class VersionUtils
8793

8894
private static VersionInfo LoadVersionFromGit(ICakeContext context)
8995
{
90-
context.Information("Fetching Verson Infop from Git");
96+
context.Information("Fetching Verson Info from Git");
9197

9298
try {
9399
GitVersion assertedVersions = context.GitVersion(new GitVersionSettings
@@ -111,6 +117,50 @@ public class VersionUtils
111117
return null;
112118
}
113119

120+
private static VersionInfo LoadVersionFromAzureDevOps(ICakeContext context)
121+
{
122+
context.Information("Fetching Verson Info from Azure DevOps");
123+
124+
try {
125+
126+
// var verInfo = new VersionInfo {
127+
// Major = assertedVersions.Major,
128+
// Minor = assertedVersions.Minor,
129+
// Build = assertedVersions.Patch,
130+
// Semantic = assertedVersions.LegacySemVerPadded,
131+
// Milestone = string.Concat("v", assertedVersions.MajorMinorPatch)
132+
// };
133+
134+
// context.Information("Calculated Semantic Version: {0}", verInfo.Semantic);
135+
136+
// return verInfo;
137+
} catch {}
138+
139+
return null;
140+
}
141+
142+
private static VersionInfo LoadVersionFromCommandLine(ICakeContext context)
143+
{
144+
context.Information("Fetching Verson Info from Command Line");
145+
146+
try {
147+
148+
var verInfo = new VersionInfo {
149+
Major = context.Argument<int?>("versionMajor"),
150+
Minor = context.Argument<int?>("versionMinor"),
151+
Build = context.Argument<int?>("versionBuild"),
152+
PreRelease = context.Argument<int?>("versionPreRelease")
153+
};
154+
155+
context.Information("Calculated Semantic Version: {0}", verInfo.Semantic);
156+
157+
return verInfo;
158+
} catch {}
159+
160+
return null;
161+
}
162+
163+
114164
public static void UpdateVersion(ICakeContext context, Settings settings, VersionInfo verInfo)
115165
{
116166
if (context == null)
@@ -251,6 +301,6 @@ public class VersionInfo
251301
context.Information("\tMilestone: {0}", Milestone);
252302
context.Information("\tCake Version: {0}", CakeVersion);
253303

254-
if (ReleaseNotes != null) context.Information("\tRelease Notes: \n\t\t{0}", string.Join("\n\t\t",ReleaseNotes));
304+
if (ReleaseNotes != null) context.Information("\tRelease Notes: {0}", ReleaseNotes);
255305
}
256306
}

0 commit comments

Comments
 (0)
Please sign in to comment.