diff --git a/Chocolatey.Cake.Recipe/Content/build.cake b/Chocolatey.Cake.Recipe/Content/build.cake index 665832b..0bace18 100644 --- a/Chocolatey.Cake.Recipe/Content/build.cake +++ b/Chocolatey.Cake.Recipe/Content/build.cake @@ -19,7 +19,7 @@ Setup(context => context.Log.Verbosity = Verbosity.Diagnostic; } - RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitVersionGlobalTool : ToolSettings.GitVersionTool, () => { + RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitVersionGlobalTool : ToolSettings.GitVersionTool, () => { BuildParameters.SetBuildVersion( BuildVersion.CalculatingSemanticVersion( context: Context, @@ -74,7 +74,7 @@ BuildParameters.Tasks.RestoreTask = Task("Restore") }); }); -BuildParameters.Tasks.DotNetCoreRestoreTask = Task("DotNetCoreRestore") +BuildParameters.Tasks.DotNetRestoreTask = Task("DotNetRestore") .IsDependentOn("Clean") .Does(() => { @@ -156,9 +156,9 @@ BuildParameters.Tasks.BuildTask = Task("Build") CopyBuildOutput(); })); -BuildParameters.Tasks.DotNetCoreBuildTask = Task("DotNetCoreBuild") +BuildParameters.Tasks.DotNetBuildTask = Task("DotNetBuild") .IsDependentOn("Clean") - .IsDependentOn("DotNetCoreRestore") + .IsDependentOn("DotNetRestore") .Does(() => { Information("Building {0}", BuildParameters.SolutionFilePath); @@ -226,7 +226,7 @@ public void CopyBuildOutput() Information("AssemblyName: {0}", parsedProject.AssemblyName); Information("IsLibrary: {0}", parsedProject.IsLibrary()); - if (BuildParameters.IsDotNetCoreBuild) + if (BuildParameters.IsDotNetBuild) { Information("IsGlobalTool: {0}", parsedProject.IsGlobalTool()); } @@ -304,7 +304,7 @@ public void CopyBuildOutput() foreach (var targetFramework in parsedProject.NetCore.TargetFrameworks) { - Information("Running DotNetCorePublish for {0}...", project.Path.FullPath); + Information("Running dotnet publish for {0}...", project.Path.FullPath); DotNetCorePublish(project.Path.FullPath, new DotNetCorePublishSettings { OutputDirectory = outputFolder.Combine(targetFramework), @@ -366,7 +366,7 @@ public void CopyBuildOutput() foreach (var targetFramework in parsedProject.NetCore.TargetFrameworks) { - Information("Running DotNetCorePublish for {0}...", project.Path.FullPath); + Information("Running dotnet publish for {0}...", project.Path.FullPath); DotNetCorePublish(project.Path.FullPath, new DotNetCorePublishSettings { OutputDirectory = outputFolder.Combine(targetFramework), @@ -421,23 +421,7 @@ BuildParameters.Tasks.DefaultTask = Task("Default") .IsDependentOn("Package"); -BuildParameters.Tasks.UploadArtifactsTask = Task("Upload-Artifacts") - .IsDependentOn("Package") - .WithCriteria(() => !BuildParameters.IsLocalBuild || BuildParameters.ForceContinuousIntegration, "Skipping because this is a local build, and force isn't being applied") - .WithCriteria(() => DirectoryExists(BuildParameters.Paths.Directories.NuGetPackages) || DirectoryExists(BuildParameters.Paths.Directories.ChocolateyPackages), "Skipping because no packages to upload") - .Does(() => -{ - // Concatenating FilePathCollections should make sure we get unique FilePaths - foreach (var package in GetFiles(BuildParameters.Paths.Directories.Packages + "/*") + - GetFiles(BuildParameters.Paths.Directories.NuGetPackages + "/*") + - GetFiles(BuildParameters.Paths.Directories.ChocolateyPackages + "/*")) - { - BuildParameters.BuildProvider.UploadArtifact(package); - } -}); - BuildParameters.Tasks.ContinuousIntegrationTask = Task("CI") - .IsDependentOn("Upload-Artifacts") .IsDependentOn("Publish-PreRelease-Packages") .IsDependentOn("Publish-Release-Packages") .IsDependentOn("Publish-GitHub-Release") @@ -478,25 +462,25 @@ public class Builder public void Run() { - BuildParameters.IsDotNetCoreBuild = false; + BuildParameters.IsDotNetBuild = false; - SetupTasks(BuildParameters.IsDotNetCoreBuild); + SetupTasks(BuildParameters.IsDotNetBuild); _action(BuildParameters.Target); } - public void RunDotNetCore() + public void RunDotNet() { - BuildParameters.IsDotNetCoreBuild = true; + BuildParameters.IsDotNetBuild = true; - SetupTasks(BuildParameters.IsDotNetCoreBuild); + SetupTasks(BuildParameters.IsDotNetBuild); _action(BuildParameters.Target); } - private static void SetupTasks(bool isDotNetCoreBuild) + private static void SetupTasks(bool isDotNetBuild) { - var prefix = isDotNetCoreBuild ? "DotNetCore" : ""; + var prefix = isDotNetBuild ? "DotNet" : ""; BuildParameters.Tasks.PackageTask.IsDependentOn("Test"); BuildParameters.Tasks.PackageTask.IsDependentOn("Analyze"); @@ -521,9 +505,9 @@ public class Builder BuildParameters.Tasks.ConfigurationBuilderTask.IsDependentOn(prefix + "Build"); BuildParameters.Tasks.TestTask.IsDependentOn(prefix + "Build"); - if (!isDotNetCoreBuild) + if (!isDotNetBuild) { - if (BuildParameters.TransifexEnabled) + if (BuildParameters.ShouldRunTransifex) { BuildParameters.Tasks.BuildTask.IsDependentOn("Transifex-Pull-Translations"); } @@ -541,9 +525,9 @@ public class Builder } else { - if (BuildParameters.TransifexEnabled) + if (BuildParameters.ShouldRunTransifex) { - BuildParameters.Tasks.DotNetCoreBuildTask.IsDependentOn("Transifex-Pull-Translations"); + BuildParameters.Tasks.DotNetBuildTask.IsDependentOn("Transifex-Pull-Translations"); } BuildParameters.Tasks.PackageTask.IsDependentOn(prefix + "Pack"); diff --git a/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake b/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake index 175f3f0..b3f9abd 100644 --- a/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake +++ b/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake @@ -3,8 +3,8 @@ /////////////////////////////////////////////////////////////////////////////// BuildParameters.Tasks.CreateReleaseNotesTask = Task("Create-Release-Notes") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { - if (BuildParameters.CanUseGitReleaseManager) + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { + if (BuildParameters.CanRunGitReleaseManager) { var settings = new GitReleaseManagerCreateSettings { @@ -33,8 +33,8 @@ BuildParameters.Tasks.ExportReleaseNotesTask = Task("Export-Release-Notes") .WithCriteria(() => !BuildParameters.IsPullRequest || BuildParameters.PrepareLocalRelease, "Skipping because this is pull request, and is not preparing local release") .WithCriteria(() => BuildParameters.BranchType == BranchType.Master || BuildParameters.BranchType == BranchType.Release || BuildParameters.BranchType == BranchType.HotFix || BuildParameters.PrepareLocalRelease, "Skipping because this is not a releasable branch, and is not preparing local release") .WithCriteria(() => BuildParameters.IsTagged || BuildParameters.PrepareLocalRelease, "Skipping because this is not a tagged build, and is not preparing local release") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { - if (BuildParameters.CanUseGitReleaseManager) + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { + if (BuildParameters.CanRunGitReleaseManager) { if (BuildParameters.ShouldDownloadMilestoneReleaseNotes) { @@ -64,9 +64,9 @@ BuildParameters.Tasks.PublishGitHubReleaseTask = Task("Publish-GitHub-Release") .WithCriteria(() => !BuildParameters.IsPullRequest, "Skipping because this is pull request") .WithCriteria(() => BuildParameters.BranchType == BranchType.Master || BuildParameters.BranchType == BranchType.Release || BuildParameters.BranchType == BranchType.HotFix, "Skipping because this is not a releasable branch") .WithCriteria(() => BuildParameters.IsTagged, "Skipping because this is not a tagged build") - .WithCriteria(() => BuildParameters.ShouldPublishGitHub, "Skipping because this publishing GitHub Release is disabled via parameters (perhaps the default value?") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { - if (BuildParameters.CanUseGitReleaseManager) + .WithCriteria(() => BuildParameters.ShouldRunGitReleaseManager, "Skipping because this publishing running GitReleaseManager is disabled via parameters (perhaps the default value?") + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { + if (BuildParameters.CanRunGitReleaseManager) { // Concatenating FilePathCollections should make sure we get unique FilePaths foreach (var package in GetFiles(BuildParameters.Paths.Directories.Packages + "/*") + @@ -92,8 +92,8 @@ BuildParameters.Tasks.PublishGitHubReleaseTask = Task("Publish-GitHub-Release") }); BuildParameters.Tasks.CreateDefaultLabelsTask = Task("Create-Default-Labels") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { - if (BuildParameters.CanUseGitReleaseManager) + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { + if (BuildParameters.CanRunGitReleaseManager) { GitReleaseManagerLabel(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName); } diff --git a/Chocolatey.Cake.Recipe/Content/gitversion.cake b/Chocolatey.Cake.Recipe/Content/gitversion.cake index 1e67218..b2b3729 100644 --- a/Chocolatey.Cake.Recipe/Content/gitversion.cake +++ b/Chocolatey.Cake.Recipe/Content/gitversion.cake @@ -20,6 +20,23 @@ public class BuildVersion string cakeVersion = typeof(ICakeContext).Assembly.GetName().Version.ToString(); + if (!BuildParameters.ShouldRunGitVersion) + { + context.Information("Running GitVersion is not enabled, so returning default values..."); + + return new BuildVersion + { + MajorMinorPatch = "0.1.0", + SemVersion = "0.1.0-alpha.0", + Milestone = "0.1.0", + CakeVersion = cakeVersion, + FileVersion = "0.1.0.0", + PackageVersion = "0.1.0-alpha-20220317-13", + InformationalVersion = "0.1.0-alpha.0+Branch.develop.Sha.528f9bf572a52f0660cbe3f4d109599eab1e9866", + FullSemVersion = "0.1.0-alpha.0", + }; + } + try { context.Information("Testing to see if valid git repository..."); diff --git a/Chocolatey.Cake.Recipe/Content/ilmerge.cake b/Chocolatey.Cake.Recipe/Content/ilmerge.cake index 7a1954a..fff47da 100644 --- a/Chocolatey.Cake.Recipe/Content/ilmerge.cake +++ b/Chocolatey.Cake.Recipe/Content/ilmerge.cake @@ -1,5 +1,6 @@ BuildParameters.Tasks.ILMergeTask = Task("Run-ILMerge") .IsDependeeOf("Copy-Nuspec-Folders") + .WithCriteria(() => BuildParameters.ShouldRunILMerge, "Skipping because ILMerge is not enabled") .WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping because not running on Windows") .Does(() => RequireTool(ToolSettings.ILMergeTool, () => { @@ -16,7 +17,7 @@ BuildParameters.Tasks.ILMergeTask = Task("Run-ILMerge") Information("Running ILMerge..."); ILMerge(ilMergeConfig.Output, ilMergeConfig.PrimaryAssemblyName, ilMergeConfig.AssemblyPaths, settings); - + if (FileExists(ilMergeConfig.LogFile)) { BuildParameters.BuildProvider.UploadArtifact(ilMergeConfig.LogFile); diff --git a/Chocolatey.Cake.Recipe/Content/packages.cake b/Chocolatey.Cake.Recipe/Content/packages.cake index 5a7f5c4..267bcf1 100644 --- a/Chocolatey.Cake.Recipe/Content/packages.cake +++ b/Chocolatey.Cake.Recipe/Content/packages.cake @@ -95,9 +95,9 @@ BuildParameters.Tasks.CreateNuGetPackagesTask = Task("Create-NuGet-Packages") } }); -BuildParameters.Tasks.DotNetCorePackTask = Task("DotNetCorePack") - .IsDependentOn("DotNetCoreBuild") - .WithCriteria(() => BuildParameters.ShouldRunDotNetCorePack, "Skipping because packaging through .NET Core is disabled") +BuildParameters.Tasks.DotNetPackTask = Task("DotNetPack") + .IsDependentOn("DotNetBuild") + .WithCriteria(() => BuildParameters.ShouldRunDotNetPack, "Skipping because packaging through .NET Core is disabled") .Does(() => { var projects = GetFiles(BuildParameters.SourceDirectoryPath + "/**/*.csproj") @@ -119,7 +119,7 @@ BuildParameters.Tasks.DotNetCorePackTask = Task("DotNetCorePack") .WithProperty("FileVersion", BuildParameters.Version.FileVersion) .WithProperty("AssemblyInformationalVersion", BuildParameters.Version.InformationalVersion); - if (BuildParameters.ShouldBuildNugetSourcePackage) + if (BuildParameters.ShouldBuildNuGetSourcePackage) { msBuildSettings.WithProperty("SymbolPackageFormat", "snupkg"); } @@ -130,8 +130,8 @@ BuildParameters.Tasks.DotNetCorePackTask = Task("DotNetCorePack") Configuration = BuildParameters.Configuration, OutputDirectory = BuildParameters.Paths.Directories.NuGetPackages, MSBuildSettings = msBuildSettings, - IncludeSource = BuildParameters.ShouldBuildNugetSourcePackage, - IncludeSymbols = BuildParameters.ShouldBuildNugetSourcePackage, + IncludeSource = BuildParameters.ShouldBuildNuGetSourcePackage, + IncludeSymbols = BuildParameters.ShouldBuildNuGetSourcePackage, }; foreach (var project in projects) @@ -141,6 +141,7 @@ BuildParameters.Tasks.DotNetCorePackTask = Task("DotNetCorePack") }); BuildParameters.Tasks.PublishPreReleasePackagesTask = Task("Publish-PreRelease-Packages") + .WithCriteria(() => BuildParameters.ShouldPublishPreReleasePackages, "Skipping because publishing of pre-release packages is not enabled") .WithCriteria(() => !BuildParameters.IsLocalBuild || BuildParameters.ForceContinuousIntegration, "Skipping because this is a local build, and force isn't being applied") .WithCriteria(() => !BuildParameters.IsPullRequest, "Skipping because current build is from a Pull Request") .WithCriteria(() => !BuildParameters.IsTagged, "Skipping because current commit is tagged") @@ -162,6 +163,7 @@ BuildParameters.Tasks.PublishPreReleasePackagesTask = Task("Publish-PreRelease-P }); BuildParameters.Tasks.PublishReleasePackagesTask = Task("Publish-Release-Packages") + .WithCriteria(() => BuildParameters.ShouldPublishReleasePackages, "Skipping because publishing of release packages is not enabled") .WithCriteria(() => !BuildParameters.IsLocalBuild || BuildParameters.ForceContinuousIntegration, "Skipping because this is a local build, and force isn't being applied") .WithCriteria(() => !BuildParameters.IsPullRequest, "Skipping because current build is from a Pull Request") .WithCriteria(() => BuildParameters.IsTagged, "Skipping because current commit is not tagged") diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index 2ab9b5c..2e58626 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -31,10 +31,9 @@ public static class BuildParameters public static string MasterBranchName { get; private set; } public static string DevelopBranchName { get; private set; } public static bool PrepareLocalRelease { get; set; } - public static bool TransifexEnabled { get; set; } public static BranchType BranchType { get; private set; } public static bool IsTagged { get; private set; } - public static bool IsDotNetCoreBuild { get; set; } + public static bool IsDotNetBuild { get; set; } public static bool TreatWarningsAsErrors { get; set; } public static BuildVersion Version { get; private set; } public static BuildPaths Paths { get; private set; } @@ -60,26 +59,39 @@ public static class BuildParameters public static string ProductTrademark { get; private set; } public static ICollection ProductCustomAttributes { get; private set; } public static bool ObfuscateAssembly { get; private set; } - public static bool ShouldRunInspectCode { get; private set; } - public static bool ShouldRunDotNetCorePack { get; private set; } + public static bool ShouldAuthenticodeSignMsis { get; private set; } + public static bool ShouldAuthenticodeSignOutputAssemblies { get; private set; } + public static bool ShouldAuthenticodeSignPowerShellScripts { get; private set; } + public static bool ShouldBuildMsi { get; private set; } + public static bool ShouldBuildNuGetSourcePackage { get; private set; } + public static bool ShouldDownloadFullReleaseNotes { get; private set;} + public static bool ShouldDownloadMilestoneReleaseNotes { get; private set;} + public static bool ShouldObfuscateOutputAssemblies { get; private set; } + public static bool ShouldPublishPreReleasePackages { get; private set; } + public static bool ShouldPublishReleasePackages { get; private set; } + public static bool ShouldReportCodeCoverageMetrics { get; private set; } + public static bool ShouldReportUnitTestResults { get; private set; } public static bool ShouldRunChocolatey { get; private set; } + public static bool ShouldRunDotNetPack { get; private set; } + public static bool ShouldRunDotNetTest { get; private set; } + public static bool ShouldRunGitReleaseManager { get; private set; } + public static bool ShouldRunGitVersion { get; private set; } + public static bool ShouldRunILMerge { get; private set; } + public static bool ShouldRunInspectCode { get; private set; } public static bool ShouldRunNuGet { get; private set; } - public static bool ShouldBuildNugetSourcePackage { get; private set; } - + public static bool ShouldRunNUnit { get; private set; } + public static bool ShouldRunOpenCover { get; private set; } + public static bool ShouldRunReportGenerator { get; private set; } + public static bool ShouldRunReportUnit { get; private set; } + public static bool ShouldRunTransifex { get; set; } + public static bool ShouldRunxUnit { get; private set; } + public static bool ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken { get; private set; } public static bool ShouldStrongNameOutputAssemblies { get; private set; } - public static bool ShouldObfuscateOutputAssemblies { get; private set; } - public static bool ShouldAuthenticodeSignOutputAssemblies { get; private set; } - public static bool ShouldAuthenticodeSignMsis { get; private set; } - public static bool ShouldBuildMsi { get; private set; } - - public static bool ShouldAuthenticodeSignPowerShellScripts { get; private set; } public static bool ShouldStrongNameSignDependentAssemblies { get; private set; } public static string StrongNameDependentAssembliesInputPath { get; private set; } - public static bool ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken { get; private set; } public static string AssemblyNamesRegexPattern { get; private set; } public static bool UseChocolateyGuiStrongNameKey { get; private set; } - - public static FilePath NugetConfig { get; private set; } + public static FilePath NuGetConfig { get; private set; } public static ICollection NuGetSources { get; private set; } public static DirectoryPath RestorePackagesDirectory { get; private set; } public static Func GetFilesToObfuscate { get; private set; } @@ -92,20 +104,12 @@ public static class BuildParameters public static bool ForceContinuousIntegration { get; private set; } public static List AllowedAssemblyNames { get; private set; } public static IBuildProvider BuildProvider { get; private set; } - - public static bool ShouldPublishGitHub { get; private set; } - public static bool ShouldDownloadMilestoneReleaseNotes { get; private set;} - public static bool ShouldDownloadFullReleaseNotes { get; private set;} - public static FilePath MilestoneReleaseNotesFilePath { get; private set; } public static FilePath FullReleaseNotesFilePath { get; private set; } - public static GitHubCredentials GitHub { get; private set; } public static TransifexCredentials Transifex { get; private set; } - public static TransifexMode TransifexPullMode { get; private set; } public static int TransifexPullPercentage { get; private set; } - public static bool PreferDotNetGlobalToolUsage { get; private set; } static BuildParameters() @@ -113,7 +117,7 @@ public static class BuildParameters Tasks = new BuildTasks(); } - public static bool CanUseGitReleaseManager + public static bool CanRunGitReleaseManager { get { @@ -146,12 +150,10 @@ public static class BuildParameters context.Information("IsPullRequest: {0}", IsPullRequest); context.Information("IsTagged: {0}", IsTagged); context.Information("PrepareLocalRelease: {0}", BuildParameters.PrepareLocalRelease); - context.Information("ShouldDownloadMilestoneReleaseNotes: {0}", BuildParameters.ShouldDownloadMilestoneReleaseNotes); - context.Information("ShouldDownloadFullReleaseNotes: {0}", BuildParameters.ShouldDownloadFullReleaseNotes); context.Information("Repository Name: {0}", BuildProvider.Repository.Name); context.Information("Branch Type: {0}", BranchType); context.Information("Branch Name: {0}", BuildProvider.Repository.Branch); - context.Information("IsDotNetCoreBuild: {0}", IsDotNetCoreBuild); + context.Information("IsDotNetBuild: {0}", IsDotNetBuild); context.Information("Solution FilePath: {0}", context.MakeAbsolute((FilePath)SolutionFilePath)); context.Information("Solution DirectoryPath: {0}", context.MakeAbsolute((DirectoryPath)SolutionDirectoryPath)); context.Information("Source DirectoryPath: {0}", context.MakeAbsolute(SourceDirectoryPath)); @@ -160,7 +162,7 @@ public static class BuildParameters context.Information("BuildAgentOperatingSystem: {0}", BuildAgentOperatingSystem); context.Information("RepositoryOwner: {0}", RepositoryOwner); context.Information("RepositoryName: {0}", RepositoryName); - context.Information("NugetConfig: {0} ({1})", NugetConfig, context.FileExists(NugetConfig)); + context.Information("NuGetConfig: {0} ({1})", NuGetConfig, context.FileExists(NuGetConfig)); context.Information("Build Counter: {0}", BuildCounter); context.Information("Test Execution Type: {0}", TestExecutionType); context.Information("RestorePackagesDirectory: {0}", RestorePackagesDirectory); @@ -175,16 +177,43 @@ public static class BuildParameters context.Information("ForceContinuousIntegration: {0}", ForceContinuousIntegration); context.Information("NuGetSources: {0}", string.Join(", ", NuGetSources)); context.Information("StrongNameDependentAssembliesInputPath: {0}", StrongNameDependentAssembliesInputPath); - context.Information("ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken: {0}", ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken); + context.Information("ShouldAuthenticodeSignMsis: {0}", BuildParameters.ShouldAuthenticodeSignMsis); + context.Information("ShouldAuthenticodeSignOutputAssemblies: {0}", BuildParameters.ShouldAuthenticodeSignOutputAssemblies); + context.Information("ShouldAuthenticodeSignPowerShellScripts: {0}", BuildParameters.ShouldAuthenticodeSignPowerShellScripts); + context.Information("ShouldBuildMsi: {0}", BuildParameters.ShouldBuildMsi); + context.Information("ShouldBuildNuGetSourcePackage: {0}", BuildParameters.ShouldBuildNuGetSourcePackage); + context.Information("ShouldDownloadFullReleaseNotes: {0}", BuildParameters.ShouldDownloadFullReleaseNotes); + context.Information("ShouldDownloadMilestoneReleaseNotes: {0}", BuildParameters.ShouldDownloadMilestoneReleaseNotes); + context.Information("ShouldObfuscateOutputAssemblies: {0}", BuildParameters.ShouldObfuscateOutputAssemblies); + context.Information("ShouldPublishPreReleasePackages: {0}", BuildParameters.ShouldPublishPreReleasePackages); + context.Information("ShouldPublishReleasePackages: {0}", BuildParameters.ShouldPublishReleasePackages); + context.Information("ShouldReportCodeCoverageMetrics: {0}", BuildParameters.ShouldReportCodeCoverageMetrics); + context.Information("ShouldReportUnitTestResults: {0}", BuildParameters.ShouldReportUnitTestResults); + context.Information("ShouldRunChocolatey: {0}", BuildParameters.ShouldRunChocolatey); + context.Information("ShouldRunDotNetPack: {0}", BuildParameters.ShouldRunDotNetPack); + context.Information("ShouldRunDotNetTest: {0}", BuildParameters.ShouldRunDotNetTest); + context.Information("ShouldRunGitReleaseManager: {0}", BuildParameters.ShouldRunGitReleaseManager); + context.Information("ShouldRunGitVersion: {0}", BuildParameters.ShouldRunGitVersion); + context.Information("ShouldRunILMerge: {0}", BuildParameters.ShouldRunILMerge); + context.Information("ShouldRunInspectCode: {0}", BuildParameters.ShouldRunInspectCode); + context.Information("ShouldRunNuGet: {0}", BuildParameters.ShouldRunNuGet); + context.Information("ShouldRunNUnit: {0}", BuildParameters.ShouldRunNUnit); + context.Information("ShouldRunOpenCover: {0}", BuildParameters.ShouldRunOpenCover); + context.Information("ShouldRunReportGenerator: {0}", BuildParameters.ShouldRunReportGenerator); + context.Information("ShouldRunReportUnit: {0}", BuildParameters.ShouldRunReportUnit); + context.Information("ShouldRunTransifex: {0}", BuildParameters.ShouldRunTransifex); + context.Information("ShouldRunxUnit: {0}", BuildParameters.ShouldRunxUnit); + context.Information("ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken: {0}", BuildParameters.ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken); + context.Information("ShouldStrongNameOutputAssemblies: {0}", BuildParameters.ShouldStrongNameOutputAssemblies); + context.Information("ShouldStrongNameSignDependentAssemblies: {0}", BuildParameters.ShouldStrongNameSignDependentAssemblies); context.Information("AssemblyNamesRegexPattern: {0}", AssemblyNamesRegexPattern); context.Information("TestAssemblyFilePattern: {0}", TestAssemblyFilePattern); context.Information("TestAssemblyProjectPattern: {0}", TestAssemblyProjectPattern); context.Information("UseChocolateyGuiStrongNameKey: {0}", UseChocolateyGuiStrongNameKey); context.Information("AllowedAssemblyName: {0}", string.Join(", ", AllowedAssemblyNames)); - context.Information("TransifexEnabled: {0}", TransifexEnabled); context.Information("PreferDotNetGlobalToolUsage: {0}", PreferDotNetGlobalToolUsage); - if (TransifexEnabled) + if (ShouldRunTransifex) { context.Information("TransifexPullMode: {0}", TransifexPullMode); context.Information("TransifexPullPercentage: {0}", TransifexPullPercentage); @@ -217,21 +246,37 @@ public static class BuildParameters string resharperSettingsFileName = null, string repositoryOwner = null, string repositoryName = null, - bool shouldRunInspectCode = true, - bool shouldRunDotNetCorePack = false, + bool shouldAuthenticodeSignMsis = true, + bool shouldAuthenticodeSignOutputAssemblies = true, + bool shouldAuthenticodeSignPowerShellScripts = true, + bool shouldBuildMsi = false, + bool shouldBuildNuGetSourcePackage = false, + bool shouldDownloadFullReleaseNotes = false, + bool shouldDownloadMilestoneReleaseNotes = false, + bool shouldObfuscateOutputAssemblies = true, + bool shouldPublishPreReleasePackages = true, + bool shouldPublishReleasePackages = true, + bool shouldReportCodeCoverageMetrics = true, + bool shouldReportUnitTestResults = true, bool shouldRunChocolatey = true, + bool shouldRunDotNetPack = false, + bool shouldRunDotNetTest = true, + bool shouldRunGitReleaseManager = false, + bool shouldRunGitVersion = true, + bool shouldRunILMerge = true, + bool shouldRunInspectCode = true, bool shouldRunNuGet = true, - bool shouldBuildNugetSourcePackage = false, + bool shouldRunNUnit = true, + bool shouldRunOpenCover = true, + bool shouldRunReportGenerator = true, + bool shouldRunReportUnit = true, + bool? shouldRunTransifex = null, + bool shouldRunxUnit = true, + bool shouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken = false, bool shouldStrongNameOutputAssemblies = true, - bool shouldObfuscateOutputAssemblies = true, - bool shouldAuthenticodeSignOutputAssemblies = true, - bool shouldAuthenticodeSignMsis = true, - bool shouldBuildMsi = false, - bool shouldAuthenticodeSignPowerShellScripts = true, bool shouldStrongNameSignDependentAssemblies = true, bool useChocolateyGuiStrongNameKey = false, string strongNameDependentAssembliesInputPath = null, - bool shouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken = false, string assemblyNamesRegexPattern = null, FilePath nugetConfig = null, ICollection nuGetSources = null, @@ -255,14 +300,10 @@ public static class BuildParameters List packageSourceDatas = null, List allowedAssemblyNames = null, string certificateSubjectName = null, - bool shouldPublishGitHub = false, string masterBranchName = "master", string developBranchName = "develop", - bool shouldDownloadMilestoneReleaseNotes = false, - bool shouldDownloadFullReleaseNotes = false, FilePath milestoneReleaseNotesFilePath = null, FilePath fullReleaseNotesFilePath = null, - bool? transifexEnabled = null, TransifexMode transifexPullMode = TransifexMode.OnlyTranslated, int transifexPullPercentage = 60, bool preferDotNetGlobalToolUsage = false @@ -289,7 +330,6 @@ public static class BuildParameters MasterBranchName = masterBranchName; DevelopBranchName = developBranchName; - TransifexEnabled = transifexEnabled ?? TransifexIsConfiguredForRepository(context); TransifexPullMode = transifexPullMode; TransifexPullPercentage = transifexPullPercentage; @@ -304,25 +344,42 @@ public static class BuildParameters RepositoryOwner = repositoryOwner ?? string.Empty; RepositoryName = repositoryName ?? Title; - ShouldRunInspectCode = shouldRunInspectCode; - ShouldRunDotNetCorePack = shouldRunDotNetCorePack; + ShouldAuthenticodeSignMsis = shouldAuthenticodeSignMsis; + ShouldAuthenticodeSignOutputAssemblies = shouldAuthenticodeSignOutputAssemblies; + ShouldAuthenticodeSignPowerShellScripts = shouldAuthenticodeSignPowerShellScripts; + ShouldBuildMsi = shouldBuildMsi; + ShouldBuildNuGetSourcePackage = shouldBuildNuGetSourcePackage; + ShouldDownloadFullReleaseNotes = shouldDownloadFullReleaseNotes; + ShouldDownloadMilestoneReleaseNotes = shouldDownloadMilestoneReleaseNotes; + ShouldObfuscateOutputAssemblies = shouldObfuscateOutputAssemblies; + ShouldRunGitReleaseManager = shouldRunGitReleaseManager; + ShouldPublishPreReleasePackages = shouldPublishPreReleasePackages; + ShouldPublishReleasePackages = shouldPublishReleasePackages; + ShouldReportCodeCoverageMetrics = shouldReportCodeCoverageMetrics; + ShouldReportUnitTestResults = shouldReportUnitTestResults; ShouldRunChocolatey = shouldRunChocolatey; + ShouldRunDotNetPack = shouldRunDotNetPack; + ShouldRunDotNetTest = shouldRunDotNetTest; + ShouldRunGitVersion = shouldRunGitVersion; + ShouldRunILMerge = shouldRunILMerge; + ShouldRunInspectCode = shouldRunInspectCode; ShouldRunNuGet = shouldRunNuGet; - ShouldBuildNugetSourcePackage = shouldBuildNugetSourcePackage; - + ShouldRunNUnit = shouldRunNUnit; + ShouldRunOpenCover = shouldRunOpenCover; + ShouldRunReportGenerator = shouldRunReportGenerator; + ShouldRunReportUnit = shouldRunReportUnit; + ShouldRunTransifex = shouldRunTransifex ?? TransifexIsConfiguredForRepository(context); + ShouldRunxUnit = shouldRunxUnit; + ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken = shouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken; ShouldStrongNameOutputAssemblies = shouldStrongNameOutputAssemblies; - ShouldObfuscateOutputAssemblies = shouldObfuscateOutputAssemblies; - ShouldAuthenticodeSignOutputAssemblies = shouldAuthenticodeSignOutputAssemblies; - ShouldAuthenticodeSignMsis = shouldAuthenticodeSignMsis; - ShouldBuildMsi = shouldBuildMsi; - ShouldAuthenticodeSignPowerShellScripts = shouldAuthenticodeSignPowerShellScripts; ShouldStrongNameSignDependentAssemblies = shouldStrongNameSignDependentAssemblies; + StrongNameDependentAssembliesInputPath = strongNameDependentAssembliesInputPath ?? SourceDirectoryPath.Combine("packages").FullPath; - ShouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken = shouldStrongNameChocolateyDependenciesWithCurrentPublicKeyToken; + AssemblyNamesRegexPattern = assemblyNamesRegexPattern ?? "chocolatey.lib|chocolatey-licensed.lib|ChocolateyGui.Common|ChocolateyGui.Common.Windows"; UseChocolateyGuiStrongNameKey = useChocolateyGuiStrongNameKey; - NugetConfig = context.MakeAbsolute(nugetConfig ?? (FilePath)"./NuGet.Config"); + NuGetConfig = context.MakeAbsolute(nugetConfig ?? (FilePath)"./NuGet.Config"); NuGetSources = nuGetSources; RestorePackagesDirectory = restorePackagesDirectory; GetFilesToObfuscate = getFilesToObfuscate; @@ -345,10 +402,10 @@ public static class BuildParameters if (nuGetSources == null) { - if (context.FileExists(NugetConfig)) + if (context.FileExists(NuGetConfig)) { NuGetSources = ( - from configuration in System.Xml.Linq.XDocument.Load(NugetConfig.FullPath).Elements("configuration") + from configuration in System.Xml.Linq.XDocument.Load(NuGetConfig.FullPath).Elements("configuration") from packageSources in configuration.Elements("packageSources") from add in packageSources.Elements("add") from value in add.Attributes("value") @@ -391,7 +448,7 @@ public static class BuildParameters Target = context.Argument("target", "Default"); BuildCounter = context.Argument("buildCounter", BuildProvider.Build.Number); - TestExecutionType = context.Argument("testExecutionType", "unit"); + TestExecutionType = context.Argument("testExecutionType", "unit").ToLowerInvariant(); if (TestExecutionType == "unit") { @@ -492,11 +549,6 @@ public static class BuildParameters SetBuildPaths(BuildPaths.GetPaths()); - ShouldDownloadFullReleaseNotes = shouldDownloadFullReleaseNotes; - ShouldDownloadMilestoneReleaseNotes = shouldDownloadMilestoneReleaseNotes; - - ShouldPublishGitHub = shouldPublishGitHub; - if (packageSourceDatas?.Any() ?? false) { context.Information("Setting Package Sources to passed in variable..."); diff --git a/Chocolatey.Cake.Recipe/Content/strongname.cake b/Chocolatey.Cake.Recipe/Content/strongname.cake index 958acf6..12989ff 100644 --- a/Chocolatey.Cake.Recipe/Content/strongname.cake +++ b/Chocolatey.Cake.Recipe/Content/strongname.cake @@ -332,7 +332,7 @@ BuildParameters.Tasks.ChangeStrongNameSignaturesTask = Task("Change-Strong-Name- var regularExpressionPattern = string.Format("", BuildParameters.AssemblyNamesRegexPattern); var formatReplacement = "{0}/packages/{1}.{2}/lib"; - if (BuildParameters.IsDotNetCoreBuild) + if (BuildParameters.IsDotNetBuild) { packageReferenceFiles = GetFiles(BuildParameters.SourceDirectoryPath + "/**/*.csproj"); regularExpressionPattern = string.Format("", BuildParameters.AssemblyNamesRegexPattern); diff --git a/Chocolatey.Cake.Recipe/Content/tasks.cake b/Chocolatey.Cake.Recipe/Content/tasks.cake index a64c519..fa85513 100644 --- a/Chocolatey.Cake.Recipe/Content/tasks.cake +++ b/Chocolatey.Cake.Recipe/Content/tasks.cake @@ -10,12 +10,11 @@ public class BuildTasks // Build Tasks public CakeTaskBuilder CleanTask { get; set; } public CakeTaskBuilder RestoreTask { get; set; } - public CakeTaskBuilder DotNetCoreRestoreTask { get; set; } + public CakeTaskBuilder DotNetRestoreTask { get; set; } public CakeTaskBuilder BuildTask { get; set; } - public CakeTaskBuilder DotNetCoreBuildTask { get; set; } + public CakeTaskBuilder DotNetBuildTask { get; set; } public CakeTaskBuilder PackageTask { get; set; } public CakeTaskBuilder DefaultTask { get; set; } - public CakeTaskBuilder UploadArtifactsTask { get; set; } public CakeTaskBuilder ContinuousIntegrationTask { get; set; } public CakeTaskBuilder BuildMsiTask { get; set; } @@ -31,7 +30,7 @@ public class BuildTasks public CakeTaskBuilder CopyNuspecFolderTask { get; set; } public CakeTaskBuilder CreateChocolateyPackagesTask { get; set; } public CakeTaskBuilder CreateNuGetPackagesTask { get; set; } - public CakeTaskBuilder DotNetCorePackTask { get; set; } + public CakeTaskBuilder DotNetPackTask { get; set; } public CakeTaskBuilder PublishPreReleasePackagesTask { get; set; } public CakeTaskBuilder PublishReleasePackagesTask { get; set; } @@ -39,7 +38,7 @@ public class BuildTasks public CakeTaskBuilder InstallOpenCoverTask { get; set; } public CakeTaskBuilder TestNUnitTask { get; set; } public CakeTaskBuilder TestxUnitTask { get; set; } - public CakeTaskBuilder DotNetCoreTestTask { get; set; } + public CakeTaskBuilder DotNetTestTask { get; set; } public CakeTaskBuilder GenerateFriendlyTestReportTask { get; set; } public CakeTaskBuilder ReportUnitTestResultsTask { get; set; } public CakeTaskBuilder ReportCodeCoverageMetricsTask { get; set; } diff --git a/Chocolatey.Cake.Recipe/Content/testing.cake b/Chocolatey.Cake.Recipe/Content/testing.cake index c8acd5a..59d72b0 100644 --- a/Chocolatey.Cake.Recipe/Content/testing.cake +++ b/Chocolatey.Cake.Recipe/Content/testing.cake @@ -12,11 +12,18 @@ BuildParameters.Tasks.InstallOpenCoverTask = Task("Install-OpenCover") BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit") .IsDependentOn("Install-OpenCover") + .WithCriteria(() => BuildParameters.ShouldRunNUnit, "Skipping because NUnit is not enabled") .WithCriteria(() => DirectoryExists(BuildParameters.Paths.Directories.PublishedNUnitTests), "Skipping because there are no published NUnit tests") .Does(() => RequireTool(ToolSettings.NUnitTool, () => { EnsureDirectoryExists(BuildParameters.Paths.Directories.NUnitTestResults); - if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows) + if (BuildParameters.TestExecutionType == "none") + { + Information("The TestExecutionType parameter has been set to 'none', so no tests will be executed"); + return; + } + + if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows && BuildParameters.ShouldRunOpenCover) { Information("Running OpenCover and NUnit..."); @@ -49,11 +56,18 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit") BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") .IsDependentOn("Install-OpenCover") + .WithCriteria(() => BuildParameters.ShouldRunxUnit, "Skipping because xUnit is not enabled") .WithCriteria(() => DirectoryExists(BuildParameters.Paths.Directories.PublishedxUnitTests), "Skipping because there are no published xUnit tests") .Does(() => RequireTool(ToolSettings.XUnitTool, () => { EnsureDirectoryExists(BuildParameters.Paths.Directories.xUnitTestResults); - if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows) + if (BuildParameters.TestExecutionType == "none") + { + Information("The TestExecutionType parameter has been set to 'none', so no tests will be executed"); + return; + } + + if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows && BuildParameters.ShouldRunOpenCover) { Information("Running OpenCover and xUnit..."); @@ -88,121 +102,128 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") }) ); -BuildParameters.Tasks.DotNetCoreTestTask = Task("DotNetCoreTest") +BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest") .IsDependentOn("Install-OpenCover") + .WithCriteria(() => BuildParameters.ShouldRunDotNetTest, "Skipping because dotnet test is not enabled") .Does(() => { + if (BuildParameters.TestExecutionType == "none") + { + Information("The TestExecutionType parameter has been set to 'none', so no tests will be executed"); + return; + } - var msBuildSettings = new DotNetCoreMSBuildSettings() - .WithProperty("Version", BuildParameters.Version.SemVersion) - .WithProperty("AssemblyVersion", BuildParameters.Version.FileVersion) - .WithProperty("FileVersion", BuildParameters.Version.FileVersion) - .WithProperty("AssemblyInformationalVersion", BuildParameters.Version.InformationalVersion); + var msBuildSettings = new DotNetCoreMSBuildSettings() + .WithProperty("Version", BuildParameters.Version.SemVersion) + .WithProperty("AssemblyVersion", BuildParameters.Version.FileVersion) + .WithProperty("FileVersion", BuildParameters.Version.FileVersion) + .WithProperty("AssemblyInformationalVersion", BuildParameters.Version.InformationalVersion); - if (BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) - { - var frameworkPathOverride = new FilePath(typeof(object).Assembly.Location).GetDirectory().FullPath + "/"; + if (BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) + { + var frameworkPathOverride = new FilePath(typeof(object).Assembly.Location).GetDirectory().FullPath + "/"; - // Use FrameworkPathOverride when not running on Windows. - Information("Restore will use FrameworkPathOverride={0} since not building on Windows.", frameworkPathOverride); - msBuildSettings.WithProperty("FrameworkPathOverride", frameworkPathOverride); - } + // Use FrameworkPathOverride when not running on Windows. + Information("Restore will use FrameworkPathOverride={0} since not building on Windows.", frameworkPathOverride); + msBuildSettings.WithProperty("FrameworkPathOverride", frameworkPathOverride); + } - var projects = GetFiles(BuildParameters.TestDirectoryPath + BuildParameters.TestAssemblyProjectPattern); - // We create the coverlet settings here so we don't have to create the filters several times - var coverletSettings = new CoverletSettings - { - CollectCoverage = true, - // It is problematic to merge the reports into one, as such we use a custom directory for coverage results - CoverletOutputDirectory = BuildParameters.Paths.Directories.TestCoverage.Combine("coverlet"), - CoverletOutputFormat = CoverletOutputFormat.opencover, - ExcludeByFile = ToolSettings.TestCoverageExcludeByFile.Split(new [] {';' }, StringSplitOptions.None).ToList(), - ExcludeByAttribute = ToolSettings.TestCoverageExcludeByAttribute.Split(new [] {';' }, StringSplitOptions.None).ToList() - }; - - foreach (var filter in ToolSettings.TestCoverageFilter.Split(new [] {' ' }, StringSplitOptions.None)) - { - if (filter[0] == '+') + var projects = GetFiles(BuildParameters.TestDirectoryPath + BuildParameters.TestAssemblyProjectPattern); + // We create the coverlet settings here so we don't have to create the filters several times + var coverletSettings = new CoverletSettings { - coverletSettings.WithInclusion(filter.TrimStart('+')); - } - else if (filter[0] == '-') + CollectCoverage = true, + // It is problematic to merge the reports into one, as such we use a custom directory for coverage results + CoverletOutputDirectory = BuildParameters.Paths.Directories.TestCoverage.Combine("coverlet"), + CoverletOutputFormat = CoverletOutputFormat.opencover, + ExcludeByFile = ToolSettings.TestCoverageExcludeByFile.Split(new [] {';' }, StringSplitOptions.None).ToList(), + ExcludeByAttribute = ToolSettings.TestCoverageExcludeByAttribute.Split(new [] {';' }, StringSplitOptions.None).ToList() + }; + + foreach (var filter in ToolSettings.TestCoverageFilter.Split(new [] {' ' }, StringSplitOptions.None)) { - coverletSettings.WithFilter(filter.TrimStart('-')); + if (filter[0] == '+') + { + coverletSettings.WithInclusion(filter.TrimStart('+')); + } + else if (filter[0] == '-') + { + coverletSettings.WithFilter(filter.TrimStart('-')); + } } - } - var settings = new DotNetCoreTestSettings - { - Configuration = BuildParameters.Configuration, - NoBuild = true - }; - - foreach (var project in projects) - { - Action testAction = tool => + var settings = new DotNetCoreTestSettings { - tool.DotNetCoreTest(project.FullPath, settings); + Configuration = BuildParameters.Configuration, + NoBuild = true }; - var parsedProject = ParseProject(project, BuildParameters.Configuration); - - var coverletPackage = parsedProject.GetPackage("coverlet.msbuild"); - bool shouldAddSourceLinkArgument = false; // Set it to false by default due to OpenCover - if (coverletPackage != null) + foreach (var project in projects) { - // If the version is a pre-release, we will assume that it is a later - // version than what we need, and thus TryParse will return false. - // If TryParse is successful we need to compare the coverlet version - // to ensure it is higher or equal to the version that includes the fix - // for using the SourceLink argument. - // https://github.com/coverlet-coverage/coverlet/issues/882 - Version coverletVersion; - shouldAddSourceLinkArgument = !Version.TryParse(coverletPackage.Version, out coverletVersion) - || coverletVersion >= Version.Parse("2.9.1"); - } + Action testAction = tool => + { + tool.DotNetCoreTest(project.FullPath, settings); + }; + + var parsedProject = ParseProject(project, BuildParameters.Configuration); - settings.ArgumentCustomization = args => { - args.AppendMSBuildSettings(msBuildSettings, Context.Environment); - if (shouldAddSourceLinkArgument && parsedProject.HasPackage("Microsoft.SourceLink.GitHub")) + var coverletPackage = parsedProject.GetPackage("coverlet.msbuild"); + bool shouldAddSourceLinkArgument = false; // Set it to false by default due to OpenCover + if (coverletPackage != null) { - args.Append("/p:UseSourceLink=true"); + // If the version is a pre-release, we will assume that it is a later + // version than what we need, and thus TryParse will return false. + // If TryParse is successful we need to compare the coverlet version + // to ensure it is higher or equal to the version that includes the fix + // for using the SourceLink argument. + // https://github.com/coverlet-coverage/coverlet/issues/882 + Version coverletVersion; + shouldAddSourceLinkArgument = !Version.TryParse(coverletPackage.Version, out coverletVersion) + || coverletVersion >= Version.Parse("2.9.1"); } - return args; - }; - if (parsedProject.IsNetCore && coverletPackage != null) - { - coverletSettings.CoverletOutputName = parsedProject.RootNameSpace.Replace('.', '-'); - DotNetCoreTest(project.FullPath, settings, coverletSettings); - } - else if (BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) - { - testAction(Context); - } - else - { - if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows) + settings.ArgumentCustomization = args => { + args.AppendMSBuildSettings(msBuildSettings, Context.Environment); + if (shouldAddSourceLinkArgument && parsedProject.HasPackage("Microsoft.SourceLink.GitHub")) + { + args.Append("/p:UseSourceLink=true"); + } + return args; + }; + + if (parsedProject.IsNetCore && coverletPackage != null) + { + coverletSettings.CoverletOutputName = parsedProject.RootNameSpace.Replace('.', '-'); + DotNetCoreTest(project.FullPath, settings, coverletSettings); + } + else if (BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) + { + testAction(Context); + } + else { - // We can not use msbuild properties together with opencover - settings.ArgumentCustomization = null; - OpenCover(testAction, - BuildParameters.Paths.Files.TestCoverageOutputFilePath, - new OpenCoverSettings { - ReturnTargetCodeOffset = 0, - OldStyle = true, - Register = "user", - MergeOutput = FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath) - } - .WithFilter(ToolSettings.TestCoverageFilter) - .ExcludeByAttribute(ToolSettings.TestCoverageExcludeByAttribute) - .ExcludeByFile(ToolSettings.TestCoverageExcludeByFile)); + if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows && BuildParameters.ShouldRunOpenCover) + { + // We can not use msbuild properties together with opencover + settings.ArgumentCustomization = null; + OpenCover(testAction, + BuildParameters.Paths.Files.TestCoverageOutputFilePath, + new OpenCoverSettings { + ReturnTargetCodeOffset = 0, + OldStyle = true, + Register = "user", + MergeOutput = FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath) + } + .WithFilter(ToolSettings.TestCoverageFilter) + .ExcludeByAttribute(ToolSettings.TestCoverageExcludeByAttribute) + .ExcludeByFile(ToolSettings.TestCoverageExcludeByFile)); + } } } - } }); BuildParameters.Tasks.GenerateFriendlyTestReportTask = Task("Generate-FriendlyTestReport") .IsDependentOn("Test-NUnit") .IsDependentOn("Test-xUnit") + .WithCriteria(() => BuildParameters.ShouldRunReportUnit, "Skipping because ReportUnit is not enabled") .WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows") .Does(() => RequireTool(ToolSettings.ReportUnitTool, () => { @@ -226,6 +247,7 @@ BuildParameters.Tasks.GenerateFriendlyTestReportTask = Task("Generate-FriendlyTe ); BuildParameters.Tasks.ReportUnitTestResultsTask = Task("Report-UnitTestResults") + .WithCriteria(() => BuildParameters.ShouldReportUnitTestResults, "Skipping because reporting of unit test results is not enabled") .WithCriteria(() => BuildSystem.IsRunningOnTeamCity, "Skipping due to not running on TeamCity") .Does(() => { Information("Reporting Unit Test results to TeamCity if any exist..."); @@ -244,6 +266,7 @@ BuildParameters.Tasks.ReportUnitTestResultsTask = Task("Report-UnitTestResults") BuildParameters.Tasks.ReportCodeCoverageMetricsTask = Task("Report-Code-Coverage-Metrics") .IsDependentOn("Convert-OpenCoverToLcov") + .WithCriteria(() => BuildParameters.ShouldReportCodeCoverageMetrics, "Skipping because reporting of code coverage metrics is not enabled") .WithCriteria(() => BuildSystem.IsRunningOnTeamCity, "Skipping due to not running on TeamCity") .Does(() => { var coverageFiles = GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/coverlet/*.xml"); @@ -324,7 +347,8 @@ private void ReportCoverageMetric( } BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-FriendlyCoverageReport") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.ReportGeneratorGlobalTool : ToolSettings.ReportGeneratorTool, () => { + .WithCriteria(() => BuildParameters.ShouldRunReportGenerator, "Skipping because ReportGenarator is not enabled") + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.ReportGeneratorGlobalTool : ToolSettings.ReportGeneratorTool, () => { var coverageFiles = GetFiles(BuildParameters.Paths.Directories.TestCoverage + "/coverlet/*.xml"); if (FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath)) { @@ -334,7 +358,7 @@ BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-FriendlyC if (coverageFiles.Any()) { var settings = new ReportGeneratorSettings(); - if (BuildParameters.IsDotNetCoreBuild && BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) + if (BuildParameters.IsDotNetBuild && BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) { // Workaround until 0.38.5+ version of cake is released // https://github.com/cake-build/cake/pull/2824 @@ -362,8 +386,9 @@ BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-FriendlyC ); BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Convert-OpenCoverToLcov") + .WithCriteria(() => BuildParameters.ShouldRunReportGenerator, "Skipping because ReportGenarator is not enabled") .WithCriteria(() => BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows, "Skipping due to not running on Windows") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.ReportGeneratorGlobalTool : ToolSettings.ReportGeneratorTool, () => { + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.ReportGeneratorGlobalTool : ToolSettings.ReportGeneratorTool, () => { if (FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath)) { var settings = new ReportGeneratorSettings(); @@ -371,7 +396,7 @@ BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Convert-OpenCoverT // Workaround until 0.38.5+ version of Cake is used in the Recipe settings.ArgumentCustomization = args => args.Append("-reporttypes:lcov"); - if (BuildParameters.IsDotNetCoreBuild && BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) + if (BuildParameters.IsDotNetBuild && BuildParameters.BuildAgentOperatingSystem != PlatformFamily.Windows) { // Workaround until 0.38.5+ version of cake is released // https://github.com/cake-build/cake/pull/2824 diff --git a/Chocolatey.Cake.Recipe/Content/transifex.cake b/Chocolatey.Cake.Recipe/Content/transifex.cake index bce386d..14e27cb 100644 --- a/Chocolatey.Cake.Recipe/Content/transifex.cake +++ b/Chocolatey.Cake.Recipe/Content/transifex.cake @@ -20,7 +20,7 @@ public static bool TransifexIsConfiguredForRepository(ICakeContext context) // Because we expect the repository to already be configured to use // transifex, we cannot run tx init, or it would replace the repository configuration file. BuildParameters.Tasks.TransifexSetupTask = Task("Transifex-Setup") - .WithCriteria(() => BuildParameters.TransifexEnabled, "Skipping because Transifex is not enabled") + .WithCriteria(() => BuildParameters.ShouldRunTransifex, "Skipping because Transifex is not enabled") .WithCriteria(() => !TransifexUserSettingsExists(Context), "Skipping because Transifex user settings already exist") .WithCriteria(() => BuildParameters.Transifex.HasCredentials, "Skipping because the Transifex credentials are missing") .Does(() => @@ -32,7 +32,7 @@ BuildParameters.Tasks.TransifexSetupTask = Task("Transifex-Setup") }); BuildParameters.Tasks.TransifexPushSourceResourceTask = Task("Transifex-Push-SourceFiles") - .WithCriteria(() => BuildParameters.TransifexEnabled, "Skipping because Transifex is not enabled") + .WithCriteria(() => BuildParameters.ShouldRunTransifex, "Skipping because Transifex is not enabled") .WithCriteria(() => BuildParameters.Transifex.HasCredentials, "Skipping because the Transifex credentials are missing") .WithCriteria(() => !BuildParameters.IsPullRequest, "Skipping because current build is from a Pull Request") .WithCriteria(() => !BuildParameters.IsLocalBuild || string.Equals(BuildParameters.Target, "Transifex-Push-Translations", StringComparison.OrdinalIgnoreCase), "Skipping because this is a local build, and target name is not Transifex-Push-Translations") @@ -46,7 +46,7 @@ BuildParameters.Tasks.TransifexPushSourceResourceTask = Task("Transifex-Push-Sou }); BuildParameters.Tasks.TransifexPullTranslationsTask = Task("Transifex-Pull-Translations") - .WithCriteria(() => BuildParameters.TransifexEnabled, "Skipping because Transifex is not enabled") + .WithCriteria(() => BuildParameters.ShouldRunTransifex, "Skipping because Transifex is not enabled") .WithCriteria(() => BuildParameters.Transifex.HasCredentials, "Skipping because the Transifex credentials are missing") .WithCriteria(() => !BuildParameters.IsPullRequest, "Skipping because current build is from a Pull Request") .WithCriteria(() => !BuildParameters.IsLocalBuild || string.Equals(BuildParameters.Target, "Transifex-Pull-Translations", StringComparison.OrdinalIgnoreCase), "Skipping because this is a local build, and target name is not Transifex-Pull-Translations")