Skip to content

Commit

Permalink
Updated build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ravensorb committed Jul 27, 2019
1 parent 22c1ce8 commit 36114ca
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 77 deletions.
178 changes: 125 additions & 53 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#l "tools/versionUtils.cake"
#l "tools/settingsUtils.cake"
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.9.0"
#addin "Cake.Incubator"
#addin "nuget:?package=Cake.Incubator&version=5.0.1"

///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
Expand Down Expand Up @@ -161,12 +161,13 @@ Task("Build")
if (!string.IsNullOrEmpty(versionInfo.ToVersionSuffix()))
dotNetCoreBuildSettings.SetVersionSuffix(versionInfo.ToVersionSuffix());
if (!string.IsNullOrEmpty(versionInfo.ToString()))
dotNetCoreBuildSettings.SetFileVersion(versionInfo.ToString(true));
dotNetCoreBuildSettings.SetFileVersion(versionInfo.ToString(false));

DotNetCoreBuild(solution.ToString(), new DotNetCoreBuildSettings
{
Configuration = settings.Configuration,
MSBuildSettings = dotNetCoreBuildSettings
MSBuildSettings = dotNetCoreBuildSettings,
Verbosity = DotNetCoreVerbosity.Minimal
}
);
break;
Expand All @@ -193,10 +194,54 @@ Task("UnitTest")
.WithCriteria(settings.ExecuteUnitTest)
.IsDependentOn("Build")
.Does(() =>
{
switch (settings.Test.Framework)
{
case TestFrameworkTypes.DotNetCore:
RunTarget("UnitTest-DotNetCore");

break;
default:
RunTarget("UnitTest-CLI");

break;
}
});

Task("UnitTest-DotNetCore")
.Description("Run dotnetcore based unit tests for the solution.")
.WithCriteria(settings.ExecuteUnitTest)
.Does(() =>
{
// Run all unit tests we can find.

var assemplyFilePath = string.Format("{0}/**/bin/{1}/{2}", settings.Test.SourcePath, settings.Configuration, settings.Test.AssemblyFileSpec);
var filePath = string.Format("{0}/**/{1}", settings.Test.SourcePath, settings.Test.FileSpec);

Information("Unit Test Files: {0}", filePath);

var testProjects = GetFiles(filePath);
var testSettings = new DotNetCoreTestSettings()
{
Configuration = settings.Configuration,
NoBuild = true
};

foreach(var p in testProjects)
{
Information("Executing Tests for {0}", p);

DotNetCoreTest(p.ToString(), testSettings);
}
});

Task("UnitTest-CLI")
.Description("Run unit tests for the solution.")
.WithCriteria(settings.ExecuteUnitTest)
.Does(() =>
{
// Run all unit tests we can find.

var assemplyFilePath = string.Format("{0}/**/bin/{1}/**/{2}", settings.Test.SourcePath, settings.Configuration, settings.Test.FileSpec);

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

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

var dncps = new DotNetCorePackSettings
{
Configuration = settings.Configuration,
OutputDirectory = artifactsPath,
IncludeSymbols = settings.NuGet.IncludeSymbols,
NoBuild = true,
NoRestore = true,
MSBuildSettings = dotNetCoreBuildSettings
};

Information("Location of Artifacts: {0}", artifactsPath);

foreach(var solution in solutions)
{
var opts = new DotNetCorePackSettings
{
Configuration = settings.Configuration,
OutputDirectory = artifactsPath,
NoBuild = true,
NoRestore = true,
MSBuildSettings = dotNetCoreBuildSettings
};

if (!string.IsNullOrEmpty(versionInfo.ToVersionSuffix()))
opts.VersionSuffix = versionInfo.ToVersionSuffix();

if (settings.NuGet.IncludeSymbols) {
opts.ArgumentCustomization = args => args.Append("--include-symbols -p:SymbolPackageFormat=snupkg");
}

Information("Location of Artifacts: {0}", artifactsPath);

foreach(var solution in solutions)
{
Information("Building Packages for {0}", solution);

try {
//DotNetCorePack("./src/**/*.csproj", dncps);
DotNetCorePack(solution.ToString(), dncps);
//DotNetCorePack("./src/**/*.csproj", opts);
DotNetCorePack(solution.ToString(), opts);
}
catch (Exception ex)
{
Debug(ex.Message);
Information("There was a problem with packing some of the projects in {0}", solution);
}
}
Expand All @@ -324,6 +376,19 @@ Task("Nuget-Package-CLI")
CreateDirectory(artifactsPath);

var nuspecFiles = GetFiles(settings.NuGet.NuSpecFileSpec);

var opts = new NuGetPackSettings {
Version = versionInfo.ToString(),
ReleaseNotes = versionInfo.ReleaseNotes,
Properties = nugetProps,
OutputDirectory = artifactsPath,
Symbols = settings.NuGet.IncludeSymbols
};

//if (settings.NuGet.IncludeSymbols) {
// opts.ArgumentCustomization = args => args.Append("-Symbols -SymbolPackageFormat snupkg");
//}

foreach(var nsf in nuspecFiles)
{
Information("Packaging {0}", nsf);
Expand All @@ -336,13 +401,7 @@ Task("Nuget-Package-CLI")
VersionUtils.UpdateNuSpecVersionDependency(Context, settings, versionInfo, nsf.ToString());
}

NuGetPack(nsf, new NuGetPackSettings {
Version = versionInfo.ToString(),
ReleaseNotes = versionInfo.ReleaseNotes,
Symbols = true,
Properties = nugetProps,
OutputDirectory = artifactsPath
});
NuGetPack(nsf, opts);
}
});

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

CreateDirectory(artifactsPath);

if (settings.NuGet.FeedApiKey.ToLower() == "local")
switch (settings.NuGet.FeedApiKey.ToUpper())
{
settings.NuGet.FeedUrl = Directory(settings.NuGet.FeedUrl).Path.FullPath;
//Information("Using Local repository: {0}", settings.NuGet.FeedUrl);
case "LOCAL":
settings.NuGet.FeedUrl = Directory(settings.NuGet.FeedUrl).Path.FullPath;
//Information("Using Local repository: {0}", settings.NuGet.FeedUrl);
break;
case "NUGETAPIKEY":
if (!System.IO.File.Exists("nugetapi.key"))
{
Error("Could not load nugetapi.key");
return;
}

settings.NuGet.FeedApiKey = System.IO.File.ReadAllText("nugetapi.key");
break;
case "AzureDevOps":
case "VSTS":
if (BuildSystem.IsRunningOnAzurePipelinesHosted)
{
//settings.NuGet.FeedApiKey = EnvironmentVariable("SYSTEM_ACCESSTOKEN");
settings.NuGet.FeedApiKey = "AzureDevOps";
}
break;
}

if (settings.NuGet.FeedApiKey == "NUGETAPIKEY")
{
if (!System.IO.File.Exists("nugetapi.key"))
{
Error("Could not load nugetapi.key");
return;
}

settings.NuGet.FeedApiKey = System.IO.File.ReadAllText("nugetapi.key");
}

if (string.IsNullOrEmpty(settings.NuGet.NuGetConfig)) settings.NuGet.NuGetConfig = null;

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

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

var dncps = new DotNetCoreNuGetPushSettings
var opts = new DotNetCoreNuGetPushSettings
{
Source = settings.NuGet.FeedUrl,
ApiKey = settings.NuGet.FeedApiKey
// ,Verbosity = DotNetCoreVerbosity.Detailed
};


//if (settings.NuGet.IncludeSymbols) {
// opts.ArgumentCustomization = args => args.Append("-Symbols -SymbolPackageFormat snupkg");
//}

foreach (var n in nupkgFiles)
{
//Information("Pushing Package: {0}", n);
Information("Pushing Package: {0}", n);

try {
DotNetCoreNuGetPush(n.ToString(), dncps);
DotNetCoreNuGetPush(n.ToString(), opts);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -446,24 +518,24 @@ Task("Nuget-Publish-CLI")

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

if (BuildSystem.IsRunningOnVSTS)
{
settings.NuGet.FeedApiKey = EnvironmentVariable("SYSTEM_ACCESSTOKEN");
}
// if (BuildSystem.IsRunningOnAzurePipelinesHosted)
// {
// settings.NuGet.FeedApiKey = EnvironmentVariable("SYSTEM_ACCESSTOKEN");
// }

var nugetSettings = new NuGetPushSettings {
var opts = new NuGetPushSettings {
Source = settings.NuGet.FeedUrl,
ApiKey = settings.NuGet.FeedApiKey,
Verbosity = NuGetVerbosity.Detailed
};

foreach (var n in nupkgFiles)
{
Information("Pushing Package: {0}", n);

try
{
NuGetPush(n, nugetSettings);
NuGetPush(n, opts);
}
catch (Exception ex)
{
Expand Down
35 changes: 16 additions & 19 deletions tools/settingsUtils.cake
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#addin "Cake.Json&version=3.0.1"
#addin "nuget:?package=Newtonsoft.Json&version=9.0.1"
#addin "nuget:?package=Cake.Json&version=3.0.1"
#addin "nuget:?package=Newtonsoft.Json&version=12.0.2"

using Newtonsoft.Json;

public class SettingsUtils
Expand Down Expand Up @@ -59,6 +60,7 @@ public class SettingsUtils
obj.Version.VersionFile = obj.VersionFile;
obj.Version.AutoIncrementVersion = GetBoolArgument(context, "autoincrementversion", obj.Version.AutoIncrementVersion);
obj.Version.AutoIncrementVersion = GetBoolArgument(context, "autoversion", obj.Version.AutoIncrementVersion);
obj.Version.LoadFrom = context.Argument<VersionSourceTypes>("loadVersionFrom", obj.Version.LoadFrom);

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

Expand All @@ -71,10 +73,10 @@ public class SettingsUtils

obj.NuGet.BuildType = context.Argument<string>("BuildType", obj.NuGet.BuildType);
obj.NuGet.PublishType = context.Argument<string>("PublishType", obj.NuGet.PublishType);
obj.NuGet.FeedUrl = GetStringArgument(context, "nugetFeed", obj.NuGet.FeedUrl, true);
obj.NuGet.FeedUrl = GetStringArgument(context, "nugetFeedUrl", obj.NuGet.FeedUrl, true);
obj.NuGet.FeedUrl = context.Argument<string>("nugetFeed", obj.NuGet.FeedUrl);
obj.NuGet.FeedUrl = context.Argument<string>("nugetFeedUrl", obj.NuGet.FeedUrl);

obj.NuGet.FeedApiKey = GetStringArgument(context, "nugetApiKey", obj.NuGet.FeedApiKey, true);
obj.NuGet.FeedApiKey = context.Argument<string>("nugetApiKey", obj.NuGet.FeedApiKey);

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

return result;
}

private static string GetStringArgument(ICakeContext context, string argumentName, string defaultValue, bool useDefaultIfEmptyOrNull)
{
var result = context.Argument<string>(argumentName, defaultValue);

if (string.IsNullOrEmpty(result)) return defaultValue;

return result;
}


private static string ExpandSettingsPath(string settingsPath, string rootPath)
{
if (settingsPath.StartsWith("./")) settingsPath = settingsPath.Replace("./", rootPath);
Expand Down Expand Up @@ -296,21 +289,21 @@ public class TestSettings
{
SourcePath = "./tests";
ResultsPath = "./tests";
AssemblyFileSpec = "*.UnitTests.dll";
FileSpec = "*.UnitTests.dll";
Framework = TestFrameworkTypes.NUnit3;
}

public string SourcePath {get;set;}
public string ResultsPath {get;set;}
public string AssemblyFileSpec {get;set;}
public string FileSpec {get;set;}
public TestFrameworkTypes Framework {get;set;}

public void Display(ICakeContext context)
{
context.Information("Test Settings:");
context.Information("\tSource Path: {0}", SourcePath);
context.Information("\tResults Path: {0}", ResultsPath);
context.Information("\tTest Assemploes File Spec: {0}", AssemblyFileSpec);
context.Information("\tTest Assemploes File Spec: {0}", FileSpec);
}
}

Expand All @@ -327,6 +320,7 @@ public class NuGetSettings
UpdateLibraryDependencies = false;
LibraryNamespaceBase = null;
LibraryMinVersionDependency = null;
IncludeSymbols = true;
}

public string BuildType {get;set;}
Expand Down Expand Up @@ -391,6 +385,8 @@ public enum VersionSourceTypes {
versionfile,
assemblyinfo,
git,
commandline,
azuredevops,
tfs
}

Expand All @@ -399,5 +395,6 @@ public enum TestFrameworkTypes {
NUnit2,
NUnit3,
XUnit,
XUnit2
XUnit2,
DotNetCore
}
Loading

0 comments on commit 36114ca

Please sign in to comment.