From 3ef439ddd16c40d19a089393bef2bc6a2d0bfaee Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 08:46:26 +0100 Subject: [PATCH 01/11] (maint) Remove Upload-Artifacts-Task The artifacts generated by the build are now uploaded as they are created, therefore an overall task for uploading artifacts is not required, and actually will cause duplicates to be created. --- Chocolatey.Cake.Recipe/Content/build.cake | 16 ---------------- Chocolatey.Cake.Recipe/Content/tasks.cake | 1 - 2 files changed, 17 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/build.cake b/Chocolatey.Cake.Recipe/Content/build.cake index 665832b..0fe7e24 100644 --- a/Chocolatey.Cake.Recipe/Content/build.cake +++ b/Chocolatey.Cake.Recipe/Content/build.cake @@ -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") diff --git a/Chocolatey.Cake.Recipe/Content/tasks.cake b/Chocolatey.Cake.Recipe/Content/tasks.cake index a64c519..cec522e 100644 --- a/Chocolatey.Cake.Recipe/Content/tasks.cake +++ b/Chocolatey.Cake.Recipe/Content/tasks.cake @@ -15,7 +15,6 @@ public class BuildTasks public CakeTaskBuilder DotNetCoreBuildTask { 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; } From 51b17d7ef65dbbed3d532b6875e53c9e2bc04faa Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 09:13:01 +0100 Subject: [PATCH 02/11] (maint) Renamed all DotNetCore tasks To just be DotNet tasks. In an upcomgin version of Cake, this change is implemented, and the aliases are all going to change, so makes sense to make this jump sooner rather than later. --- Chocolatey.Cake.Recipe/Content/build.cake | 36 +++++++++---------- .../Content/gitreleasemanager.cake | 8 ++--- Chocolatey.Cake.Recipe/Content/packages.cake | 6 ++-- .../Content/parameters.cake | 8 ++--- .../Content/strongname.cake | 2 +- Chocolatey.Cake.Recipe/Content/tasks.cake | 8 ++--- Chocolatey.Cake.Recipe/Content/testing.cake | 10 +++--- 7 files changed, 39 insertions(+), 39 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/build.cake b/Chocolatey.Cake.Recipe/Content/build.cake index 0fe7e24..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), @@ -462,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"); @@ -505,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"); } @@ -525,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..65a1ab1 100644 --- a/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake +++ b/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake @@ -3,7 +3,7 @@ /////////////////////////////////////////////////////////////////////////////// BuildParameters.Tasks.CreateReleaseNotesTask = Task("Create-Release-Notes") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { if (BuildParameters.CanUseGitReleaseManager) { var settings = new GitReleaseManagerCreateSettings @@ -33,7 +33,7 @@ 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, () => { + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { if (BuildParameters.CanUseGitReleaseManager) { if (BuildParameters.ShouldDownloadMilestoneReleaseNotes) @@ -65,7 +65,7 @@ BuildParameters.Tasks.PublishGitHubReleaseTask = Task("Publish-GitHub-Release") .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, () => { + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { if (BuildParameters.CanUseGitReleaseManager) { // Concatenating FilePathCollections should make sure we get unique FilePaths @@ -92,7 +92,7 @@ BuildParameters.Tasks.PublishGitHubReleaseTask = Task("Publish-GitHub-Release") }); BuildParameters.Tasks.CreateDefaultLabelsTask = Task("Create-Default-Labels") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { + .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { if (BuildParameters.CanUseGitReleaseManager) { GitReleaseManagerLabel(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName); diff --git a/Chocolatey.Cake.Recipe/Content/packages.cake b/Chocolatey.Cake.Recipe/Content/packages.cake index 5a7f5c4..d34a02f 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") diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index 2ab9b5c..0f2cbc4 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -34,7 +34,7 @@ public static class BuildParameters 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; } @@ -61,7 +61,7 @@ public static class BuildParameters 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 ShouldRunDotNetPack { get; private set; } public static bool ShouldRunChocolatey { get; private set; } public static bool ShouldRunNuGet { get; private set; } public static bool ShouldBuildNugetSourcePackage { get; private set; } @@ -151,7 +151,7 @@ public static class BuildParameters 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)); @@ -305,7 +305,7 @@ public static class BuildParameters RepositoryName = repositoryName ?? Title; ShouldRunInspectCode = shouldRunInspectCode; - ShouldRunDotNetCorePack = shouldRunDotNetCorePack; + ShouldRunDotNetPack = shouldRunDotNetPack; ShouldRunChocolatey = shouldRunChocolatey; ShouldRunNuGet = shouldRunNuGet; ShouldBuildNugetSourcePackage = shouldBuildNugetSourcePackage; 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 cec522e..fa85513 100644 --- a/Chocolatey.Cake.Recipe/Content/tasks.cake +++ b/Chocolatey.Cake.Recipe/Content/tasks.cake @@ -10,9 +10,9 @@ 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 ContinuousIntegrationTask { get; set; } @@ -30,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; } @@ -38,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..9805a06 100644 --- a/Chocolatey.Cake.Recipe/Content/testing.cake +++ b/Chocolatey.Cake.Recipe/Content/testing.cake @@ -88,7 +88,7 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") }) ); -BuildParameters.Tasks.DotNetCoreTestTask = Task("DotNetCoreTest") +BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest") .IsDependentOn("Install-OpenCover") .Does(() => { @@ -324,7 +324,7 @@ private void ReportCoverageMetric( } BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-FriendlyCoverageReport") - .Does(() => RequireTool(BuildParameters.IsDotNetCoreBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.ReportGeneratorGlobalTool : ToolSettings.ReportGeneratorTool, () => { + .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 +334,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 @@ -363,7 +363,7 @@ BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-FriendlyC BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Convert-OpenCoverToLcov") .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 +371,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 From e8de4aef71d0b92632d5c329dec9f2aef2dc58de Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 09:56:16 +0100 Subject: [PATCH 03/11] (#61) Alphabetical all the things! Made all the properties and usage of them within the parameters.cake file alphabetical. This should make them easier to find going forward. Also, for similar reasons, changes TransifexEnabled to ShouldRunTransifex. --- .../Content/parameters.cake | 158 ++++++++++++------ Chocolatey.Cake.Recipe/Content/transifex.cake | 6 +- 2 files changed, 106 insertions(+), 58 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index 0f2cbc4..7721ac1 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -31,7 +31,6 @@ 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 IsDotNetBuild { get; set; } @@ -60,25 +59,37 @@ 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 ShouldRunDotNetPack { 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 ShouldPublishGitHub { 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 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 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 ICollection NuGetSources { get; private set; } public static DirectoryPath RestorePackagesDirectory { get; private set; } @@ -92,20 +103,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() @@ -146,8 +149,6 @@ 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); @@ -175,16 +176,42 @@ 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("ShouldPublishGitHub: {0}", BuildParameters.ShouldPublishGitHub); + 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("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("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 +244,36 @@ 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 shouldPublishGitHub = false, + bool shouldPublishPreReleasePackages = true, + bool shouldPublishReleasePackages = true, + bool shouldReportCodeCoverageResults = true, + bool shouldReportUnitTestResults = true, bool shouldRunChocolatey = true, + bool shouldRunDotNetPack = false, + bool shouldRunDotNetTest = true, + bool shouldRunGitVersion = true, + bool shouldRunILMerge = true, + bool shouldRunInspectCode = true, bool shouldRunNuGet = true, - bool shouldBuildNugetSourcePackage = false, + bool shouldRunNUnit = 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 +297,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 +327,6 @@ public static class BuildParameters MasterBranchName = masterBranchName; DevelopBranchName = developBranchName; - TransifexEnabled = transifexEnabled ?? TransifexIsConfiguredForRepository(context); TransifexPullMode = transifexPullMode; TransifexPullPercentage = transifexPullPercentage; @@ -304,21 +341,37 @@ public static class BuildParameters RepositoryOwner = repositoryOwner ?? string.Empty; RepositoryName = repositoryName ?? Title; - ShouldRunInspectCode = shouldRunInspectCode; - ShouldRunDotNetPack = shouldRunDotNetPack; + ShouldAuthenticodeSignMsis = shouldAuthenticodeSignMsis; + ShouldAuthenticodeSignOutputAssemblies = shouldAuthenticodeSignOutputAssemblies; + ShouldAuthenticodeSignPowerShellScripts = shouldAuthenticodeSignPowerShellScripts; + ShouldBuildMsi = shouldBuildMsi; + ShouldBuildNugetSourcePackage = shouldBuildNugetSourcePackage; + ShouldDownloadFullReleaseNotes = shouldDownloadFullReleaseNotes; + ShouldDownloadMilestoneReleaseNotes = shouldDownloadMilestoneReleaseNotes; + ShouldObfuscateOutputAssemblies = shouldObfuscateOutputAssemblies; + ShouldPublishGitHub = shouldPublishGitHub; + 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; + ShouldRunReportGenarator = 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; @@ -492,11 +545,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/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") From 6435abf4d3808db5a0d70b6e20ba03d1e229904c Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 10:16:20 +0100 Subject: [PATCH 04/11] (#61) Add new criteria to tasks To allow these tasks to be overridden in the recipe.cake file, in the same way that can be done for other tasks. This now means that all tasks can be overridden. --- Chocolatey.Cake.Recipe/Content/gitversion.cake | 17 +++++++++++++++++ Chocolatey.Cake.Recipe/Content/ilmerge.cake | 3 ++- Chocolatey.Cake.Recipe/Content/packages.cake | 2 ++ Chocolatey.Cake.Recipe/Content/parameters.cake | 4 ++-- Chocolatey.Cake.Recipe/Content/testing.cake | 8 ++++++++ 5 files changed, 31 insertions(+), 3 deletions(-) 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 d34a02f..f1259f3 100644 --- a/Chocolatey.Cake.Recipe/Content/packages.cake +++ b/Chocolatey.Cake.Recipe/Content/packages.cake @@ -141,6 +141,7 @@ BuildParameters.Tasks.DotNetPackTask = Task("DotNetPack") }); 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 7721ac1..40bf372 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -255,7 +255,7 @@ public static class BuildParameters bool shouldPublishGitHub = false, bool shouldPublishPreReleasePackages = true, bool shouldPublishReleasePackages = true, - bool shouldReportCodeCoverageResults = true, + bool shouldReportCodeCoverageMetrics = true, bool shouldReportUnitTestResults = true, bool shouldRunChocolatey = true, bool shouldRunDotNetPack = false, @@ -362,7 +362,7 @@ public static class BuildParameters ShouldRunInspectCode = shouldRunInspectCode; ShouldRunNuGet = shouldRunNuGet; ShouldRunNUnit = shouldRunNUnit; - ShouldRunReportGenarator = shouldRunReportGenerator; + ShouldRunReportGenerator = shouldRunReportGenerator; ShouldRunReportUnit = shouldRunReportUnit; ShouldRunTransifex = shouldRunTransifex ?? TransifexIsConfiguredForRepository(context); ShouldRunxUnit = shouldRunxUnit; diff --git a/Chocolatey.Cake.Recipe/Content/testing.cake b/Chocolatey.Cake.Recipe/Content/testing.cake index 9805a06..2526c75 100644 --- a/Chocolatey.Cake.Recipe/Content/testing.cake +++ b/Chocolatey.Cake.Recipe/Content/testing.cake @@ -12,6 +12,7 @@ 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); @@ -49,6 +50,7 @@ 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); @@ -90,6 +92,7 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest") .IsDependentOn("Install-OpenCover") + .WithCriteria(() => BuildParameters.ShouldRunDotNetTest, "Skipping because dotnet test is not enabled") .Does(() => { var msBuildSettings = new DotNetCoreMSBuildSettings() @@ -203,6 +206,7 @@ BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest") 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 +230,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 +249,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,6 +330,7 @@ private void ReportCoverageMetric( } BuildParameters.Tasks.GenerateLocalCoverageReportTask = Task("Generate-FriendlyCoverageReport") + .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)) @@ -362,6 +369,7 @@ 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.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.ReportGeneratorGlobalTool : ToolSettings.ReportGeneratorTool, () => { if (FileExists(BuildParameters.Paths.Files.TestCoverageOutputFilePath)) From f0ffcac55ef8bae38fe19fe8335db15095520b53 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 10:20:09 +0100 Subject: [PATCH 05/11] (#61) Renamed ShouldPublishGitHub To reflect what is actually happening, i.e. running GitReleaseManager. --- Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake | 2 +- Chocolatey.Cake.Recipe/Content/parameters.cake | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake b/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake index 65a1ab1..a6c675f 100644 --- a/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake +++ b/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake @@ -64,7 +64,7 @@ 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?") + .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.CanUseGitReleaseManager) { diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index 40bf372..9a76a13 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -67,7 +67,6 @@ public static class BuildParameters public static bool ShouldDownloadFullReleaseNotes { get; private set;} public static bool ShouldDownloadMilestoneReleaseNotes { get; private set;} public static bool ShouldObfuscateOutputAssemblies { get; private set; } - public static bool ShouldPublishGitHub { get; private set; } public static bool ShouldPublishPreReleasePackages { get; private set; } public static bool ShouldPublishReleasePackages { get; private set; } public static bool ShouldReportCodeCoverageMetrics { get; private set; } @@ -75,6 +74,7 @@ public static class BuildParameters 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; } @@ -184,7 +184,6 @@ public static class BuildParameters context.Information("ShouldDownloadFullReleaseNotes: {0}", BuildParameters.ShouldDownloadFullReleaseNotes); context.Information("ShouldDownloadMilestoneReleaseNotes: {0}", BuildParameters.ShouldDownloadMilestoneReleaseNotes); context.Information("ShouldObfuscateOutputAssemblies: {0}", BuildParameters.ShouldObfuscateOutputAssemblies); - context.Information("ShouldPublishGitHub: {0}", BuildParameters.ShouldPublishGitHub); context.Information("ShouldPublishPreReleasePackages: {0}", BuildParameters.ShouldPublishPreReleasePackages); context.Information("ShouldPublishReleasePackages: {0}", BuildParameters.ShouldPublishReleasePackages); context.Information("ShouldReportCodeCoverageMetrics: {0}", BuildParameters.ShouldReportCodeCoverageMetrics); @@ -192,6 +191,7 @@ public static class BuildParameters 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); @@ -252,7 +252,6 @@ public static class BuildParameters bool shouldDownloadFullReleaseNotes = false, bool shouldDownloadMilestoneReleaseNotes = false, bool shouldObfuscateOutputAssemblies = true, - bool shouldPublishGitHub = false, bool shouldPublishPreReleasePackages = true, bool shouldPublishReleasePackages = true, bool shouldReportCodeCoverageMetrics = true, @@ -260,6 +259,7 @@ public static class BuildParameters bool shouldRunChocolatey = true, bool shouldRunDotNetPack = false, bool shouldRunDotNetTest = true, + bool shouldRunGitReleaseManager = false, bool shouldRunGitVersion = true, bool shouldRunILMerge = true, bool shouldRunInspectCode = true, @@ -349,7 +349,7 @@ public static class BuildParameters ShouldDownloadFullReleaseNotes = shouldDownloadFullReleaseNotes; ShouldDownloadMilestoneReleaseNotes = shouldDownloadMilestoneReleaseNotes; ShouldObfuscateOutputAssemblies = shouldObfuscateOutputAssemblies; - ShouldPublishGitHub = shouldPublishGitHub; + ShouldRunGitReleaseManager = shouldRunGitReleaseManager; ShouldPublishPreReleasePackages = shouldPublishPreReleasePackages; ShouldPublishReleasePackages = shouldPublishReleasePackages; ShouldReportCodeCoverageMetrics = shouldReportCodeCoverageMetrics; From 20d2cca7bca29021519b573c0a84b824e3a0515c Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 10:22:05 +0100 Subject: [PATCH 06/11] (maint) Renamed CanUseGitReleaseManager property To be CanRunGitReleaseManager, which then makes it the same verbiage as ShouldRunGitReleaseManager. --- Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake | 8 ++++---- Chocolatey.Cake.Recipe/Content/parameters.cake | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake b/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake index a6c675f..b3f9abd 100644 --- a/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake +++ b/Chocolatey.Cake.Recipe/Content/gitreleasemanager.cake @@ -4,7 +4,7 @@ BuildParameters.Tasks.CreateReleaseNotesTask = Task("Create-Release-Notes") .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { - if (BuildParameters.CanUseGitReleaseManager) + if (BuildParameters.CanRunGitReleaseManager) { var settings = new GitReleaseManagerCreateSettings { @@ -34,7 +34,7 @@ BuildParameters.Tasks.ExportReleaseNotesTask = Task("Export-Release-Notes") .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.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { - if (BuildParameters.CanUseGitReleaseManager) + if (BuildParameters.CanRunGitReleaseManager) { if (BuildParameters.ShouldDownloadMilestoneReleaseNotes) { @@ -66,7 +66,7 @@ BuildParameters.Tasks.PublishGitHubReleaseTask = Task("Publish-GitHub-Release") .WithCriteria(() => BuildParameters.IsTagged, "Skipping because this is not a tagged build") .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.CanUseGitReleaseManager) + if (BuildParameters.CanRunGitReleaseManager) { // Concatenating FilePathCollections should make sure we get unique FilePaths foreach (var package in GetFiles(BuildParameters.Paths.Directories.Packages + "/*") + @@ -93,7 +93,7 @@ BuildParameters.Tasks.PublishGitHubReleaseTask = Task("Publish-GitHub-Release") BuildParameters.Tasks.CreateDefaultLabelsTask = Task("Create-Default-Labels") .Does(() => RequireTool(BuildParameters.IsDotNetBuild || BuildParameters.PreferDotNetGlobalToolUsage ? ToolSettings.GitReleaseManagerGlobalTool : ToolSettings.GitReleaseManagerTool, () => { - if (BuildParameters.CanUseGitReleaseManager) + if (BuildParameters.CanRunGitReleaseManager) { GitReleaseManagerLabel(BuildParameters.GitHub.Token, BuildParameters.RepositoryOwner, BuildParameters.RepositoryName); } diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index 9a76a13..ed8a7f3 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -116,7 +116,7 @@ public static class BuildParameters Tasks = new BuildTasks(); } - public static bool CanUseGitReleaseManager + public static bool CanRunGitReleaseManager { get { From d1ca4e6a8d218b9d33c68ecca4a1b2deed9ce860 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 10:24:21 +0100 Subject: [PATCH 07/11] (maint) Correct spelling of NuGet Nuget -> NuGet --- Chocolatey.Cake.Recipe/Content/packages.cake | 6 +++--- Chocolatey.Cake.Recipe/Content/parameters.cake | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/packages.cake b/Chocolatey.Cake.Recipe/Content/packages.cake index f1259f3..267bcf1 100644 --- a/Chocolatey.Cake.Recipe/Content/packages.cake +++ b/Chocolatey.Cake.Recipe/Content/packages.cake @@ -119,7 +119,7 @@ BuildParameters.Tasks.DotNetPackTask = Task("DotNetPack") .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.DotNetPackTask = Task("DotNetPack") 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) diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index ed8a7f3..bbad036 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -63,7 +63,7 @@ public static class BuildParameters 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 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; } @@ -90,7 +90,7 @@ public static class BuildParameters public static string StrongNameDependentAssembliesInputPath { 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; } @@ -161,7 +161,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); @@ -180,7 +180,7 @@ public static class BuildParameters 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("ShouldBuildNuGetSourcePackage: {0}", BuildParameters.ShouldBuildNuGetSourcePackage); context.Information("ShouldDownloadFullReleaseNotes: {0}", BuildParameters.ShouldDownloadFullReleaseNotes); context.Information("ShouldDownloadMilestoneReleaseNotes: {0}", BuildParameters.ShouldDownloadMilestoneReleaseNotes); context.Information("ShouldObfuscateOutputAssemblies: {0}", BuildParameters.ShouldObfuscateOutputAssemblies); @@ -248,7 +248,7 @@ public static class BuildParameters bool shouldAuthenticodeSignOutputAssemblies = true, bool shouldAuthenticodeSignPowerShellScripts = true, bool shouldBuildMsi = false, - bool shouldBuildNugetSourcePackage = false, + bool shouldBuildNuGetSourcePackage = false, bool shouldDownloadFullReleaseNotes = false, bool shouldDownloadMilestoneReleaseNotes = false, bool shouldObfuscateOutputAssemblies = true, @@ -345,7 +345,7 @@ public static class BuildParameters ShouldAuthenticodeSignOutputAssemblies = shouldAuthenticodeSignOutputAssemblies; ShouldAuthenticodeSignPowerShellScripts = shouldAuthenticodeSignPowerShellScripts; ShouldBuildMsi = shouldBuildMsi; - ShouldBuildNugetSourcePackage = shouldBuildNugetSourcePackage; + ShouldBuildNuGetSourcePackage = shouldBuildNuGetSourcePackage; ShouldDownloadFullReleaseNotes = shouldDownloadFullReleaseNotes; ShouldDownloadMilestoneReleaseNotes = shouldDownloadMilestoneReleaseNotes; ShouldObfuscateOutputAssemblies = shouldObfuscateOutputAssemblies; @@ -375,7 +375,7 @@ public static class BuildParameters 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; @@ -398,10 +398,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") From f1071406ba343f7a258a3d1f1484e30f7064e996 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 11:44:11 +0100 Subject: [PATCH 08/11] (#62) Don't run any unit tests when argument set There was already the option to run unit, integration, or all, but we should also provide the ability to not run any tests whatsoever. --- Chocolatey.Cake.Recipe/Content/testing.cake | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Chocolatey.Cake.Recipe/Content/testing.cake b/Chocolatey.Cake.Recipe/Content/testing.cake index 2526c75..f93cb1d 100644 --- a/Chocolatey.Cake.Recipe/Content/testing.cake +++ b/Chocolatey.Cake.Recipe/Content/testing.cake @@ -17,6 +17,12 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit") .Does(() => RequireTool(ToolSettings.NUnitTool, () => { EnsureDirectoryExists(BuildParameters.Paths.Directories.NUnitTestResults); + 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) { Information("Running OpenCover and NUnit..."); @@ -55,6 +61,12 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") .Does(() => RequireTool(ToolSettings.XUnitTool, () => { EnsureDirectoryExists(BuildParameters.Paths.Directories.xUnitTestResults); + 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) { Information("Running OpenCover and xUnit..."); @@ -95,6 +107,12 @@ BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest") .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) From 6d962c2604a18bc8c6f779c70d49560f88b36377 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 11:45:14 +0100 Subject: [PATCH 09/11] (maint) Formatting Push everything over a tab --- Chocolatey.Cake.Recipe/Content/testing.cake | 189 ++++++++++---------- 1 file changed, 94 insertions(+), 95 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/testing.cake b/Chocolatey.Cake.Recipe/Content/testing.cake index f93cb1d..46f3e45 100644 --- a/Chocolatey.Cake.Recipe/Content/testing.cake +++ b/Chocolatey.Cake.Recipe/Content/testing.cake @@ -106,119 +106,118 @@ 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; + } - 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) + { + // 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") From d181e7f3c8137a7f3f636b7d69311a2ff1457c85 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 11:46:44 +0100 Subject: [PATCH 10/11] (#62) ToLower() to argument Since we are comparing against it in a few places, and we should ensure that we are comparing apples to apples. --- Chocolatey.Cake.Recipe/Content/parameters.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index bbad036..2f354af 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -444,7 +444,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") { From 1ac87f790a25f8f67ea791b46b4c86dd24898a08 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Mon, 9 May 2022 11:51:46 +0100 Subject: [PATCH 11/11] (#61) Add override for OpenCover To allow preventing the execution of OpenCover, which can cause problems in some scenarios. --- Chocolatey.Cake.Recipe/Content/parameters.cake | 4 ++++ Chocolatey.Cake.Recipe/Content/testing.cake | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index 2f354af..2e58626 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -80,6 +80,7 @@ public static class BuildParameters public static bool ShouldRunInspectCode { get; private set; } public static bool ShouldRunNuGet { 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; } @@ -197,6 +198,7 @@ public static class BuildParameters 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); @@ -265,6 +267,7 @@ public static class BuildParameters bool shouldRunInspectCode = true, bool shouldRunNuGet = true, bool shouldRunNUnit = true, + bool shouldRunOpenCover = true, bool shouldRunReportGenerator = true, bool shouldRunReportUnit = true, bool? shouldRunTransifex = null, @@ -362,6 +365,7 @@ public static class BuildParameters ShouldRunInspectCode = shouldRunInspectCode; ShouldRunNuGet = shouldRunNuGet; ShouldRunNUnit = shouldRunNUnit; + ShouldRunOpenCover = shouldRunOpenCover; ShouldRunReportGenerator = shouldRunReportGenerator; ShouldRunReportUnit = shouldRunReportUnit; ShouldRunTransifex = shouldRunTransifex ?? TransifexIsConfiguredForRepository(context); diff --git a/Chocolatey.Cake.Recipe/Content/testing.cake b/Chocolatey.Cake.Recipe/Content/testing.cake index 46f3e45..59d72b0 100644 --- a/Chocolatey.Cake.Recipe/Content/testing.cake +++ b/Chocolatey.Cake.Recipe/Content/testing.cake @@ -23,7 +23,7 @@ BuildParameters.Tasks.TestNUnitTask = Task("Test-NUnit") return; } - if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows) + if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows && BuildParameters.ShouldRunOpenCover) { Information("Running OpenCover and NUnit..."); @@ -67,7 +67,7 @@ BuildParameters.Tasks.TestxUnitTask = Task("Test-xUnit") return; } - if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows) + if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows && BuildParameters.ShouldRunOpenCover) { Information("Running OpenCover and xUnit..."); @@ -200,7 +200,7 @@ BuildParameters.Tasks.DotNetTestTask = Task("DotNetTest") } else { - if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows) + if (BuildParameters.BuildAgentOperatingSystem == PlatformFamily.Windows && BuildParameters.ShouldRunOpenCover) { // We can not use msbuild properties together with opencover settings.ArgumentCustomization = null;