diff --git a/Chocolatey.Cake.Recipe/Content/analyzing.cake b/Chocolatey.Cake.Recipe/Content/analyzing.cake index 654c5a5..fcdac68 100644 --- a/Chocolatey.Cake.Recipe/Content/analyzing.cake +++ b/Chocolatey.Cake.Recipe/Content/analyzing.cake @@ -91,7 +91,36 @@ BuildParameters.Tasks.CreateIssuesReportTask = Task("CreateIssuesReport") } }); +BuildParameters.Tasks.DotNetFormatCheckTask = Task("Run-DotNetFormatCheck") + .WithCriteria(() => BuildParameters.ShouldRunDotNetFormat, "Skipping because DotNetFormat has been disabled") + .WithCriteria(() => BuildParameters.ShouldRunAnalyze, "Skipping because running analysis tasks is not enabled") + .Does(() => RequireTool(ToolSettings.DotNetFormatGlobalTool, () => + { + var dotNetFormatTool = Context.Tools.Resolve("dotnet-format.exe"); + if (dotNetFormatTool == null) + { + dotNetFormatTool = Context.Tools.Resolve("dotnet-format"); + } + + StartProcess(dotNetFormatTool, new ProcessSettings{ Arguments = string.Format("{0} --report {1} --check --no-restore", MakeAbsolute(BuildParameters.SolutionFilePath), MakeAbsolute(BuildParameters.Paths.Files.DotNetFormatOutputFilePath)) }); + }) +); + +BuildParameters.Tasks.DotNetFormatTask = Task("Run-DotNetFormat") + .Does(() => RequireTool(ToolSettings.DotNetFormatGlobalTool, () => + { + var dotNetFormatTool = Context.Tools.Resolve("dotnet-format.exe"); + if (dotNetFormatTool == null) + { + dotNetFormatTool = Context.Tools.Resolve("dotnet-format"); + } + + StartProcess(dotNetFormatTool, new ProcessSettings{ Arguments = string.Format("{0} --report {1} --no-restore", MakeAbsolute(BuildParameters.SolutionFilePath), MakeAbsolute(BuildParameters.Paths.Files.DotNetFormatOutputFilePath)) }); + }) +); + BuildParameters.Tasks.AnalyzeTask = Task("Analyze") .IsDependentOn("InspectCode") + .IsDependentOn("Run-DotNetFormatCheck") .IsDependentOn("CreateIssuesReport") .WithCriteria(() => BuildParameters.ShouldRunAnalyze, "Skipping because running analysis tasks is not enabled"); diff --git a/Chocolatey.Cake.Recipe/Content/parameters.cake b/Chocolatey.Cake.Recipe/Content/parameters.cake index d41d0de..d3439d2 100644 --- a/Chocolatey.Cake.Recipe/Content/parameters.cake +++ b/Chocolatey.Cake.Recipe/Content/parameters.cake @@ -165,6 +165,7 @@ public static class BuildParameters public static bool ShouldRunChocolatey { get; private set; } public static bool ShouldRunDependencyCheck { get; private set; } public static bool ShouldRunDocker { get; private set; } + public static bool ShouldRunDotNetFormat { get; private set; } public static bool ShouldRunDotNetPack { get; private set; } public static bool ShouldRunDotNetTest { get; private set; } public static bool ShouldRunGitReleaseManager { get; private set; } @@ -296,6 +297,7 @@ public static class BuildParameters context.Information("ShouldRunChocolatey: {0}", BuildParameters.ShouldRunChocolatey); context.Information("ShouldRunDependencyCheck: {0}", BuildParameters.ShouldRunDependencyCheck); context.Information("ShouldRunDocker: {0}", BuildParameters.ShouldRunDocker); + context.Information("ShouldRunDotNetFormat: {0}", BuildParameters.ShouldRunDotNetFormat); context.Information("ShouldRunDotNetPack: {0}", BuildParameters.ShouldRunDotNetPack); context.Information("ShouldRunDotNetTest: {0}", BuildParameters.ShouldRunDotNetTest); context.Information("ShouldRunGitReleaseManager: {0}", BuildParameters.ShouldRunGitReleaseManager); @@ -401,6 +403,7 @@ public static class BuildParameters bool shouldRunAnalyze = true, bool shouldRunChocolatey = true, bool shouldRunDocker = true, + bool shouldRunDotNetFormat = true, bool shouldRunDotNetPack = false, bool shouldRunDotNetTest = true, bool shouldRunGitReleaseManager = false, @@ -665,6 +668,13 @@ public static class BuildParameters ShouldRunDocker = context.Argument("shouldRunDocker"); } + ShouldRunDotNetFormat = shouldRunDotNetFormat; + + if (context.HasArgument("shouldRunDotNetFormat")) + { + ShouldRunDotNetFormat = context.Argument("shouldRunDotNetFormat"); + } + ShouldRunDotNetPack = shouldRunDotNetPack; if (context.HasArgument("shouldRunDotNetPack")) diff --git a/Chocolatey.Cake.Recipe/Content/paths.cake b/Chocolatey.Cake.Recipe/Content/paths.cake index 73e5841..33940ab 100644 --- a/Chocolatey.Cake.Recipe/Content/paths.cake +++ b/Chocolatey.Cake.Recipe/Content/paths.cake @@ -50,6 +50,7 @@ public class BuildPaths var dependencyCheckReportsDirectory = buildDirectoryPath + "/DependencyCheckReports"; // Files + var dotNetFormatOutputFilePath = ((DirectoryPath)testResultsDirectory).CombineWithFilePath("dotnet-format.json"); var testCoverageOutputFilePath = ((DirectoryPath)testCoverageDirectory).CombineWithFilePath("OpenCover.xml"); var solutionInfoFilePath = ((DirectoryPath)BuildParameters.SourceDirectoryPath).CombineWithFilePath("SolutionVersion.cs"); var buildLogFilePath = ((DirectoryPath)buildDirectoryPath).CombineWithFilePath("MsBuild.log"); @@ -86,6 +87,7 @@ public class BuildPaths var buildFiles = new BuildFiles( repoFilesPaths, + dotNetFormatOutputFilePath, testCoverageOutputFilePath, solutionInfoFilePath, buildLogFilePath, @@ -105,6 +107,7 @@ public class BuildFiles { public ICollection RepoFilesPaths { get; private set; } + public FilePath DotNetFormatOutputFilePath { get; private set; } public FilePath TestCoverageOutputFilePath { get; private set; } public FilePath SolutionInfoFilePath { get; private set; } @@ -117,6 +120,7 @@ public class BuildFiles public BuildFiles( FilePath[] repoFilesPaths, + FilePath dotNetFormatOutputFilePath, FilePath testCoverageOutputFilePath, FilePath solutionInfoFilePath, FilePath buildLogFilePath, @@ -125,6 +129,7 @@ public class BuildFiles ) { RepoFilesPaths = Filter(repoFilesPaths); + DotNetFormatOutputFilePath = dotNetFormatOutputFilePath; TestCoverageOutputFilePath = testCoverageOutputFilePath; SolutionInfoFilePath = solutionInfoFilePath; BuildLogFilePath = buildLogFilePath; diff --git a/Chocolatey.Cake.Recipe/Content/tasks.cake b/Chocolatey.Cake.Recipe/Content/tasks.cake index d01c085..5c618cb 100644 --- a/Chocolatey.Cake.Recipe/Content/tasks.cake +++ b/Chocolatey.Cake.Recipe/Content/tasks.cake @@ -36,6 +36,8 @@ public class BuildTasks // Analysing Tasks public CakeTaskBuilder InspectCodeTask { get; set; } public CakeTaskBuilder CreateIssuesReportTask { get; set; } + public CakeTaskBuilder DotNetFormatCheckTask { get; set; } + public CakeTaskBuilder DotNetFormatTask { get; set; } public CakeTaskBuilder AnalyzeTask { get; set; } // Dependency-Check Tasks diff --git a/Chocolatey.Cake.Recipe/Content/toolsettings.cake b/Chocolatey.Cake.Recipe/Content/toolsettings.cake index ecfd2cf..26c6018 100644 --- a/Chocolatey.Cake.Recipe/Content/toolsettings.cake +++ b/Chocolatey.Cake.Recipe/Content/toolsettings.cake @@ -27,6 +27,7 @@ public static class ToolSettings public static FilePath EazfuscatorToolLocation { get; private set; } public static string AmazonLambdaGlobalTool { get; private set; } public static string DependencyCheckTool { get; private set; } + public static string DotNetFormatGlobalTool { get; private set; } public static string GitVersionGlobalTool { get; private set; } public static string GitVersionTool { get; private set; } public static string GitReleaseManagerGlobalTool { get; private set; } @@ -53,6 +54,7 @@ public static class ToolSettings public static void SetToolPreprocessorDirectives( string amazonLambdaGlobalTool = "#tool dotnet:?package=amazon.lambda.tools&version=5.4.5", string dependencyCheckTool = "#tool nuget:?package=DependencyCheck.Runner.Tool&version=3.2.1&include=./**/dependency-check.sh&include=./**/dependency-check.bat", + string dotNetFormatGlobalTool = "#tool dotnet:?package=dotnet-format&version=5.1.250801", string gitVersionGlobalTool = "#tool dotnet:?package=GitVersion.Tool&version=5.10.1", string gitVersionTool = "#tool nuget:?package=GitVersion.CommandLine&version=5.10.1", string gitReleaseManagerGlobalTool = "#tool dotnet:?package=GitReleaseManager.Tool&version=0.13.0", @@ -74,6 +76,7 @@ public static class ToolSettings { AmazonLambdaGlobalTool = amazonLambdaGlobalTool; DependencyCheckTool = dependencyCheckTool; + DotNetFormatGlobalTool = dotNetFormatGlobalTool; GitVersionGlobalTool = gitVersionGlobalTool; GitVersionTool = gitVersionTool; GitReleaseManagerGlobalTool = gitReleaseManagerGlobalTool;