diff --git a/build.cake b/build.cake index 24471d2..6e0c49e 100644 --- a/build.cake +++ b/build.cake @@ -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 @@ -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; @@ -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); @@ -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); } } @@ -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); @@ -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); } }); @@ -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) @@ -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) { @@ -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) { diff --git a/tools/settingsUtils.cake b/tools/settingsUtils.cake index ca6653e..07137b7 100644 --- a/tools/settingsUtils.cake +++ b/tools/settingsUtils.cake @@ -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 @@ -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("loadVersionFrom", obj.Version.LoadFrom); if (obj.Xamarin == null) obj.Xamarin = new XamarinSettings(); @@ -71,10 +73,10 @@ public class SettingsUtils obj.NuGet.BuildType = context.Argument("BuildType", obj.NuGet.BuildType); obj.NuGet.PublishType = context.Argument("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("nugetFeed", obj.NuGet.FeedUrl); + obj.NuGet.FeedUrl = context.Argument("nugetFeedUrl", obj.NuGet.FeedUrl); - obj.NuGet.FeedApiKey = GetStringArgument(context, "nugetApiKey", obj.NuGet.FeedApiKey, true); + obj.NuGet.FeedApiKey = context.Argument("nugetApiKey", obj.NuGet.FeedApiKey); obj.NuGet.LibraryMinVersionDependency = (context.Argument("dependencyVersion", obj.NuGet.LibraryMinVersionDependency)).Replace(":","."); obj.NuGet.VersionDependencyTypeForLibrary = context.Argument("dependencyType", obj.NuGet.VersionDependencyTypeForLibrary); @@ -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(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); @@ -296,13 +289,13 @@ 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) @@ -310,7 +303,7 @@ public class TestSettings 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); } } @@ -327,6 +320,7 @@ public class NuGetSettings UpdateLibraryDependencies = false; LibraryNamespaceBase = null; LibraryMinVersionDependency = null; + IncludeSymbols = true; } public string BuildType {get;set;} @@ -391,6 +385,8 @@ public enum VersionSourceTypes { versionfile, assemblyinfo, git, + commandline, + azuredevops, tfs } @@ -399,5 +395,6 @@ public enum TestFrameworkTypes { NUnit2, NUnit3, XUnit, - XUnit2 + XUnit2, + DotNetCore } \ No newline at end of file diff --git a/tools/versionUtils.cake b/tools/versionUtils.cake index ae299ba..0f8c5c8 100644 --- a/tools/versionUtils.cake +++ b/tools/versionUtils.cake @@ -1,6 +1,6 @@ -#addin "Cake.Json&version=3.0.1" -#addin "Cake.FileHelpers&version=3.1.0" -#addin "nuget:?package=Newtonsoft.Json&version=9.0.1" +#addin "nuget:?package=Cake.Json&version=3.0.1" +#addin "nuget:?package=Cake.FileHelpers&version=3.2.0" +#addin "nuget:?package=Newtonsoft.Json&version=12.0.2" #tool "nuget:?package=GitVersion.CommandLine&version=4.0.0" using Newtonsoft.Json; @@ -29,9 +29,15 @@ public class VersionUtils case VersionSourceTypes.git: verInfo = LoadVersionFromGit(context); break; + case VersionSourceTypes.azuredevops: + //verInfo = LoadVersionFromAzureDevOps(context); + break; case VersionSourceTypes.tfs: //verInfo = LoadVersionFromTfs(context); break; + case VersionSourceTypes.commandline: + verInfo = LoadVersionFromCommandLine(context); + break; } if (verInfo != null) @@ -87,7 +93,7 @@ public class VersionUtils private static VersionInfo LoadVersionFromGit(ICakeContext context) { - context.Information("Fetching Verson Infop from Git"); + context.Information("Fetching Verson Info from Git"); try { GitVersion assertedVersions = context.GitVersion(new GitVersionSettings @@ -111,6 +117,50 @@ public class VersionUtils return null; } + private static VersionInfo LoadVersionFromAzureDevOps(ICakeContext context) + { + context.Information("Fetching Verson Info from Azure DevOps"); + + try { + + // var verInfo = new VersionInfo { + // Major = assertedVersions.Major, + // Minor = assertedVersions.Minor, + // Build = assertedVersions.Patch, + // Semantic = assertedVersions.LegacySemVerPadded, + // Milestone = string.Concat("v", assertedVersions.MajorMinorPatch) + // }; + + // context.Information("Calculated Semantic Version: {0}", verInfo.Semantic); + + // return verInfo; + } catch {} + + return null; + } + + private static VersionInfo LoadVersionFromCommandLine(ICakeContext context) + { + context.Information("Fetching Verson Info from Command Line"); + + try { + + var verInfo = new VersionInfo { + Major = context.Argument("versionMajor"), + Minor = context.Argument("versionMinor"), + Build = context.Argument("versionBuild"), + PreRelease = context.Argument("versionPreRelease") + }; + + context.Information("Calculated Semantic Version: {0}", verInfo.Semantic); + + return verInfo; + } catch {} + + return null; + } + + public static void UpdateVersion(ICakeContext context, Settings settings, VersionInfo verInfo) { if (context == null) @@ -251,6 +301,6 @@ public class VersionInfo context.Information("\tMilestone: {0}", Milestone); context.Information("\tCake Version: {0}", CakeVersion); - if (ReleaseNotes != null) context.Information("\tRelease Notes: \n\t\t{0}", string.Join("\n\t\t",ReleaseNotes)); + if (ReleaseNotes != null) context.Information("\tRelease Notes: {0}", ReleaseNotes); } } \ No newline at end of file