Skip to content

Commit

Permalink
Add dotnet format check
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletKuro committed May 30, 2024
1 parent 472cb67 commit 94f6877
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@
"Pack",
"Push",
"PushGithubNuget",
"Restore"
"Restore",
"VerifyFormat"
]
}
},
Expand All @@ -107,7 +108,8 @@
"Pack",
"Push",
"PushGithubNuget",
"Restore"
"Restore",
"VerifyFormat"
]
}
},
Expand Down
24 changes: 21 additions & 3 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Build : NukeBuild
/// - Microsoft VisualStudio https://nuke.build/visualstudio
/// - Microsoft VSCode https://nuke.build/vscode

public static int Main () => Execute<Build>(x => x.Compile);
public static int Main() => Execute<Build>(x => x.Compile);

[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
readonly Configuration Configuration = Configuration.Release;
Expand All @@ -48,6 +48,8 @@ class Build : NukeBuild
[Parameter][Secret] readonly string NugetKey;
[Parameter][Secret] readonly string GithubToken;

bool RunFormatAnalyzers => false;

bool IsTag => GitHubActions.Instance?.Ref?.StartsWith("refs/tags/") ?? false;

[Solution] readonly Solution Solution;
Expand All @@ -74,8 +76,23 @@ class Build : NukeBuild
.SetProjectFile(Solution));
});

Target VerifyFormat => _ => _
.After(Restore)
.Description("Verify code formatting for the solution.")
.Executes(() =>
{
DotNet($"format whitespace {Solution.Path} --verify-no-changes ");
DotNet($"format style {Solution.Path} --verify-no-changes ");
if (RunFormatAnalyzers)
{
DotNet($"format analyzers {Solution.Path} --verify-no-changes ");
}
});

Target Compile => _ => _
.DependsOn(Restore)
.DependsOn(Restore, VerifyFormat)
.Executes(() =>
{
DotNetBuild(s => s
Expand All @@ -89,7 +106,8 @@ class Build : NukeBuild
.Produces(PackagesDirectory / "*.nupkg")
.Produces(PackagesDirectory / "*.snupkg")
.Requires(() => Configuration.Equals(Configuration.Release))
.Executes(() => {
.Executes(() =>
{
DotNetPack(_ => _
.Apply(PackSettings));
Expand Down

0 comments on commit 94f6877

Please sign in to comment.