Skip to content

Commit

Permalink
Optimize NUKE build pipeline's spell check
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Jan 7, 2023
1 parent ad5febc commit fcf9dd1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
38 changes: 37 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 Down Expand Up @@ -101,6 +106,7 @@ class Build : NukeBuild

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

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

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

Target TestFrameworks => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
var testCombinations =
Expand Down Expand Up @@ -227,6 +237,7 @@ class Build : NukeBuild
.DependsOn(UnitTests)
.DependsOn(CodeCoverage)
.DependsOn(CalculateNugetVersion)
.OnlyWhenDynamic(() => SourceChangesDetected())
.Executes(() =>
{
DotNetPack(s => s
Expand Down Expand Up @@ -258,11 +269,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()
{
return Changes.Any(x => x.StartsWith("docs"));
}

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

IEnumerable<string> Changes
{
get
{
using var repo = new Repository(GitRepository.LocalDirectory);

return repo.Diff.Compare<TreeChanges>(repo.Branches["develop"].Tip.Tree,
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

0 comments on commit fcf9dd1

Please sign in to comment.