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 8 commits
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
11 changes: 4 additions & 7 deletions .github/workflows/build.yml
@@ -1,12 +1,6 @@
name: build

on:
pull_request:
paths-ignore:
- docs/**
push:
paths-ignore:
- docs/**
on: [push, pull_request]

jobs:
build:
Expand Down Expand Up @@ -35,6 +29,7 @@ jobs:
env:
BranchSpec: ${{ github.ref }}
BuildNumber: ${{ github.run_number }}
PullRequestBase: ${{ github.event.pull_request.base.ref }}
ApiKey: ${{ secrets.NUGETAPIKEY }}

- name: coveralls
Expand Down Expand Up @@ -71,3 +66,5 @@ jobs:

- name: Run NUKE
run: ./build.sh UnitTests
env:
BaseRef: ${{ github.event.pull_request.base.ref }}
25 changes: 0 additions & 25 deletions .github/workflows/spellcheck.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .nuke/build.schema.json
Expand Up @@ -66,6 +66,10 @@
"type": "string"
}
},
"PullRequestBase": {
"type": "string",
"description": "The target branch for the pull request"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
Expand Down
46 changes: 45 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,14 +30,17 @@ 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;

[Parameter("An incrementing build number as provided by the build engine")]
readonly string BuildNumber;

[Parameter("The target branch for the pull request")]
readonly string PullRequestBase;

[Parameter("The key to push to Nuget")]
readonly string ApiKey;

Expand All @@ -45,6 +50,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 +73,15 @@ class Build : NukeBuild
string YarnCli => ToolPathResolver.GetPackageExecutable("Yarn.MSBuild", "yarn.js", "1.22.19");

Target Clean => _ => _
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
EnsureCleanDirectory(ArtifactsDirectory);
EnsureCleanDirectory(TestResultsDirectory);
});

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

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

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

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

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

Target TestFrameworks => _ => _
.DependsOn(Compile)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
var testCombinations =
Expand Down Expand Up @@ -227,6 +243,7 @@ class Build : NukeBuild
.DependsOn(UnitTests)
.DependsOn(CodeCoverage)
.DependsOn(CalculateNugetVersion)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
DotNetPack(s => s
Expand Down Expand Up @@ -258,11 +275,38 @@ class Build : NukeBuild
});

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

bool HasDocumentationChanges =>
Changes.Any(x => x.StartsWith("docs"));

bool HasSourceChanges =>
Changes.Any(x => !x.StartsWith("docs"));

string[] Changes
{
get
{
using var repo = new Repository(GitRepository.LocalDirectory);

Tree targetBranch = repo.Branches[PullRequestBase].Tip.Tree;
Tree sourceBranch = repo.Branches[repo.Head.FriendlyName].Tip.Tree;

return repo.Diff
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
.Compare<TreeChanges>(targetBranch, sourceBranch)
.Where(x => x.Exists)
.Select(x => x.Path)
.ToArray();
}
}

bool RunAllTargets => PullRequestBase == default;

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