diff --git a/Build/Build.cs b/Build/Build.cs index a5f76d2205..596e2273e9 100644 --- a/Build/Build.cs +++ b/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; @@ -28,7 +30,7 @@ class Build : NukeBuild - Microsoft VSCode https://nuke.build/vscode */ - public static int Main() => Execute(x => x.Push); + public static int Main() => Execute(x => x.SpellCheck, x => x.Push); [Parameter("A branch specification such as develop or refs/pull/1775/merge")] readonly string BranchSpec; @@ -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; @@ -101,6 +106,7 @@ class Build : NukeBuild Target Compile => _ => _ .DependsOn(Restore) + .OnlyWhenDynamic(() => SourceChangesDetected()) .Executes(() => { DotNetBuild(s => s @@ -115,6 +121,7 @@ class Build : NukeBuild Target ApiChecks => _ => _ .DependsOn(Compile) + .OnlyWhenDynamic(() => SourceChangesDetected()) .Executes(() => { DotNetTest(s => s @@ -126,6 +133,7 @@ class Build : NukeBuild Target UnitTests => _ => _ .DependsOn(Compile) + .OnlyWhenDynamic(() => SourceChangesDetected()) .Executes(() => { Project[] projects = new[] @@ -172,6 +180,7 @@ class Build : NukeBuild Target CodeCoverage => _ => _ .DependsOn(TestFrameworks) .DependsOn(UnitTests) + .OnlyWhenDynamic(() => SourceChangesDetected()) .Executes(() => { ReportGenerator(s => s @@ -188,6 +197,7 @@ class Build : NukeBuild Target TestFrameworks => _ => _ .DependsOn(Compile) + .OnlyWhenDynamic(() => SourceChangesDetected()) .Executes(() => { var testCombinations = @@ -227,6 +237,7 @@ class Build : NukeBuild .DependsOn(UnitTests) .DependsOn(CodeCoverage) .DependsOn(CalculateNugetVersion) + .OnlyWhenDynamic(() => SourceChangesDetected()) .Executes(() => { DotNetPack(s => s @@ -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 Changes + { + get + { + using var repo = new Repository(GitRepository.LocalDirectory); + + return repo.Diff.Compare(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); } diff --git a/Build/_build.csproj b/Build/_build.csproj index b73d4f73d0..e60e653e3a 100644 --- a/Build/_build.csproj +++ b/Build/_build.csproj @@ -22,6 +22,7 @@ + diff --git a/package.json b/package.json index 4c21a44ce7..6d8b3d61b5 100644 --- a/package.json +++ b/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"