Skip to content

Commit

Permalink
Merge pull request #121 from gep13/issue-120
Browse files Browse the repository at this point in the history
(#120) Add ability to run dotnet-format
  • Loading branch information
Windos authored Aug 21, 2023
2 parents 7a38a0c + d76fd41 commit f7e01f1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Chocolatey.Cake.Recipe/Content/analyzing.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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");
10 changes: 10 additions & 0 deletions Chocolatey.Cake.Recipe/Content/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -665,6 +668,13 @@ public static class BuildParameters
ShouldRunDocker = context.Argument<bool>("shouldRunDocker");
}

ShouldRunDotNetFormat = shouldRunDotNetFormat;

if (context.HasArgument("shouldRunDotNetFormat"))
{
ShouldRunDotNetFormat = context.Argument<bool>("shouldRunDotNetFormat");
}

ShouldRunDotNetPack = shouldRunDotNetPack;

if (context.HasArgument("shouldRunDotNetPack"))
Expand Down
5 changes: 5 additions & 0 deletions Chocolatey.Cake.Recipe/Content/paths.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -86,6 +87,7 @@ public class BuildPaths

var buildFiles = new BuildFiles(
repoFilesPaths,
dotNetFormatOutputFilePath,
testCoverageOutputFilePath,
solutionInfoFilePath,
buildLogFilePath,
Expand All @@ -105,6 +107,7 @@ public class BuildFiles
{
public ICollection<FilePath> RepoFilesPaths { get; private set; }

public FilePath DotNetFormatOutputFilePath { get; private set; }
public FilePath TestCoverageOutputFilePath { get; private set; }

public FilePath SolutionInfoFilePath { get; private set; }
Expand All @@ -117,6 +120,7 @@ public class BuildFiles

public BuildFiles(
FilePath[] repoFilesPaths,
FilePath dotNetFormatOutputFilePath,
FilePath testCoverageOutputFilePath,
FilePath solutionInfoFilePath,
FilePath buildLogFilePath,
Expand All @@ -125,6 +129,7 @@ public class BuildFiles
)
{
RepoFilesPaths = Filter(repoFilesPaths);
DotNetFormatOutputFilePath = dotNetFormatOutputFilePath;
TestCoverageOutputFilePath = testCoverageOutputFilePath;
SolutionInfoFilePath = solutionInfoFilePath;
BuildLogFilePath = buildLogFilePath;
Expand Down
2 changes: 2 additions & 0 deletions Chocolatey.Cake.Recipe/Content/tasks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Chocolatey.Cake.Recipe/Content/toolsettings.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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",
Expand All @@ -74,6 +76,7 @@ public static class ToolSettings
{
AmazonLambdaGlobalTool = amazonLambdaGlobalTool;
DependencyCheckTool = dependencyCheckTool;
DotNetFormatGlobalTool = dotNetFormatGlobalTool;
GitVersionGlobalTool = gitVersionGlobalTool;
GitVersionTool = gitVersionTool;
GitReleaseManagerGlobalTool = gitReleaseManagerGlobalTool;
Expand Down

0 comments on commit f7e01f1

Please sign in to comment.