Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize NUKE spell check #2089

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 40 additions & 1 deletion Build/Build.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LibGit2Sharp;
using Nuke.Common;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
Expand All @@ -28,7 +30,7 @@ class Build : NukeBuild
- Microsoft VSCode https://nuke.build/vscode
*/

public static int Main() => Execute<Build>(x => x.Push);
public static int Main() => Execute<Build>(x => x.SpellCheck, x => x.Push);

[Parameter("A branch specification such as develop or refs/pull/1775/merge")]
readonly string BranchSpec;
Expand All @@ -45,6 +47,9 @@ class Build : NukeBuild
[GitVersion(Framework = "net6.0")]
readonly GitVersion GitVersion;

[GitRepository]
readonly GitRepository GitRepository;

[PackageExecutable("nspec", "NSpecRunner.exe", Version = "3.1.0")]
Tool NSpec3;

Expand All @@ -65,13 +70,15 @@ class Build : NukeBuild
string YarnCli => ToolPathResolver.GetPackageExecutable("Yarn.MSBuild", "yarn.js", "1.22.19");

Target Clean => _ => _
.OnlyWhenDynamic(() => SourceChangesDetected())
dennisdoomen marked this conversation as resolved.
Show resolved Hide resolved
.Executes(() =>
{
EnsureCleanDirectory(ArtifactsDirectory);
EnsureCleanDirectory(TestResultsDirectory);
});

Target CalculateNugetVersion => _ => _
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
SemVer = GitVersion.SemVer;
Expand All @@ -91,6 +98,7 @@ class Build : NukeBuild

Target Restore => _ => _
.DependsOn(Clean)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
DotNetRestore(s => s
Expand All @@ -101,6 +109,7 @@ class Build : NukeBuild

Target Compile => _ => _
.DependsOn(Restore)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
DotNetBuild(s => s
Expand All @@ -115,6 +124,7 @@ class Build : NukeBuild

Target ApiChecks => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
DotNetTest(s => s
Expand All @@ -126,6 +136,7 @@ class Build : NukeBuild

Target UnitTests => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
Project[] projects = new[]
Expand Down Expand Up @@ -172,6 +183,7 @@ class Build : NukeBuild
Target CodeCoverage => _ => _
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
ReportGenerator(s => s
Expand All @@ -188,6 +200,7 @@ class Build : NukeBuild

Target TestFrameworks => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
var testCombinations =
Expand Down Expand Up @@ -227,6 +240,7 @@ class Build : NukeBuild
.DependsOn(UnitTests)
.DependsOn(CodeCoverage)
.DependsOn(CalculateNugetVersion)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
DotNetPack(s => s
Expand Down Expand Up @@ -258,11 +272,36 @@ class Build : NukeBuild
});

Target SpellCheck => _ => _
.OnlyWhenDynamic(() => DocumentationChangesDetected())
.Executes(() =>
{
Node($"{YarnCli} install --silent", workingDirectory: RootDirectory);
Node($"{YarnCli} --silent run cspell --no-summary", workingDirectory: RootDirectory,
customLogger: (_, msg) => Error(msg));
});

bool DocumentationChangesDetected()
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
{
return Changes.Any(x => x.StartsWith("docs"));
}

bool SourceChangesDetected()
{
return Changes.Any(x => !x.StartsWith("docs"));
}

IEnumerable<string> Changes
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
{
get
{
using var repo = new Repository(GitRepository.LocalDirectory);

return repo.Diff.Compare<TreeChanges>(repo.Branches["develop"].Tip.Tree,
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
repo.Branches[repo.Head.FriendlyName].Tip.Tree)
.Where(x => x.Exists)
.Select(x => x.Path);
}
}

bool IsTag => BranchSpec != null && BranchSpec.Contains("refs/tags", StringComparison.InvariantCultureIgnoreCase);
}
1 change: 1 addition & 0 deletions Build/_build.csproj
Expand Up @@ -22,6 +22,7 @@
<PackageDownload Include="ReportGenerator" Version="[5.1.13]" />
<PackageDownload Include="xunit.runner.console" Version="[2.4.2]" />
<PackageDownload Include="Node.js.redist" Version="[16.17.1]" />
<PackageReference Include="LibGit2Sharp" Version="0.27.0-preview-0182" />
<PackageReference Include="Nuke.Common" Version="6.3.0" />
<PackageDownload Include="Yarn.MSBuild" Version="[1.22.19]" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"version": "1.0.0",
"scripts": {
"cspell": "cspell --config ./cSpell.json ./**/*.md --no-progress"
"cspell": "cspell --config ./cSpell.json ./docs/**/*.md --no-progress"
},
"dependencies": {
"cspell": "^6.18.1"
Expand Down