Skip to content

Commit

Permalink
Optimize NUKE spell check (#2089)
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Jan 8, 2023
1 parent ad5febc commit c56b55b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 37 deletions.
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
45 changes: 41 additions & 4 deletions 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,32 +73,35 @@ 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;
if (IsPullRequest)
{
Serilog.Log.Information(
Information(
"Branch spec {branchspec} is a pull request. Adding build number {buildnumber}",
BranchSpec, BuildNumber);
SemVer = string.Join('.', GitVersion.SemVer.Split('.').Take(3).Union(new[] { BuildNumber }));
}
Serilog.Log.Information("SemVer = {semver}", SemVer);
Information("SemVer = {semver}", SemVer);
});

bool IsPullRequest => BranchSpec != null && BranchSpec.Contains("pull", StringComparison.InvariantCultureIgnoreCase);

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 @@ -183,11 +198,12 @@ class Build : NukeBuild
.SetAssemblyFilters("+FluentAssertions"));
string link = TestResultsDirectory / "reports" / "index.html";
Serilog.Log.Information($"Code coverage report: \x1b]8;;file://{link.Replace('\\', '/')}\x1b\\{link}\x1b]8;;\x1b\\");
Information($"Code coverage report: \x1b]8;;file://{link.Replace('\\', '/')}\x1b\\{link}\x1b]8;;\x1b\\");
});

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,31 @@ 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 =>
Repository.Diff
.Compare<TreeChanges>(TargetBranch, SourceBranch)
.Where(x => x.Exists)
.Select(x => x.Path)
.ToArray();

Repository Repository => new Repository(GitRepository.LocalDirectory);
Tree TargetBranch => Repository.Branches[PullRequestBase].Tip.Tree;
Tree SourceBranch => Repository.Branches[Repository.Head.FriendlyName].Tip.Tree;
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

0 comments on commit c56b55b

Please sign in to comment.