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

Clean up Build.cs #2093

Merged
merged 16 commits into from Jan 14, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
7 changes: 1 addition & 6 deletions .github/workflows/build.yml
Expand Up @@ -27,10 +27,7 @@ jobs:
- name: Run NUKE
run: ./build.ps1
env:
BranchSpec: ${{ github.ref }}
BuildNumber: ${{ github.run_number }}
PullRequestBase: ${{ github.event.pull_request.base.ref }}
ApiKey: ${{ secrets.NUGETAPIKEY }}
NuGetApiKey: ${{ secrets.NUGETAPIKEY }}

- name: coveralls
uses: coverallsapp/github-action@1.1.3
Expand Down Expand Up @@ -66,5 +63,3 @@ jobs:

- name: Run NUKE
run: ./build.sh UnitTests
env:
BaseRef: ${{ github.event.pull_request.base.ref }}
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 11 additions & 18 deletions .nuke/build.schema.json
Expand Up @@ -6,18 +6,6 @@
"build": {
"type": "object",
"properties": {
"ApiKey": {
"type": "string",
"description": "The key to push to Nuget"
},
"BranchSpec": {
"type": "string",
"description": "A branch specification such as develop or refs/pull/1775/merge"
},
"BuildNumber": {
"type": "string",
"description": "An incrementing build number as provided by the build engine"
},
"Continue": {
"type": "boolean",
"description": "Indicates to continue a previously failed build attempt"
Expand Down Expand Up @@ -51,6 +39,11 @@
"type": "boolean",
"description": "Disables displaying the NUKE logo"
},
"NuGetApiKey": {
"type": "string",
"description": "The key to push to Nuget",
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
},
"Partition": {
"type": "string",
"description": "Partition to use on CI"
Expand All @@ -66,10 +59,6 @@
"type": "string"
}
},
"PullRequestBase": {
"type": "string",
"description": "The target branch for the pull request"
},
"Root": {
"type": "string",
"description": "Root directory during build execution"
Expand All @@ -90,7 +79,9 @@
"Restore",
"SpellCheck",
"TestFrameworks",
"UnitTests"
"UnitTests",
"UnitTestsNetCore",
"UnitTestsNetFramework"
]
}
},
Expand All @@ -114,7 +105,9 @@
"Restore",
"SpellCheck",
"TestFrameworks",
"UnitTests"
"UnitTests",
"UnitTestsNetCore",
"UnitTestsNetFramework"
]
}
},
Expand Down
87 changes: 49 additions & 38 deletions Build/Build.cs
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using LibGit2Sharp;
using Nuke.Common;
using Nuke.Common.CI.GitHubActions;
using Nuke.Common.Execution;
using Nuke.Common.Git;
using Nuke.Common.IO;
Expand Down Expand Up @@ -32,17 +33,15 @@ class Build : NukeBuild

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;
GitHubActions GitHubActions => GitHubActions.Instance;
jnyrup marked this conversation as resolved.
Show resolved Hide resolved

[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;
string BranchSpec => GitHubActions?.Ref;
string BuildNumber => GitHubActions?.RunNumber.ToString();
string PullRequestBase => GitHubActions?.BaseRef;

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

[Solution(GenerateProjects = true)]
readonly Solution Solution;
Expand Down Expand Up @@ -70,7 +69,6 @@ class Build : NukeBuild
AbsolutePath TestResultsDirectory => RootDirectory / "TestResults";

string SemVer;
string YarnCli => ToolPathResolver.GetPackageExecutable("Yarn.MSBuild", "yarn.js", "1.22.19");

Target Clean => _ => _
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
Expand All @@ -97,7 +95,7 @@ class Build : NukeBuild
Information("SemVer = {semver}", SemVer);
});

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

Target Restore => _ => _
.DependsOn(Clean)
Expand Down Expand Up @@ -138,32 +136,35 @@ class Build : NukeBuild
cc => cc.SetProjectFile(Solution.Specs.Approval_Tests)));
});

Target UnitTests => _ => _
Project[] Projects => new[]
{
Solution.Specs.FluentAssertions_Specs,
Solution.Specs.FluentAssertions_Equivalency_Specs
};

Target UnitTestsNetFramework => _ => _
jnyrup marked this conversation as resolved.
Show resolved Hide resolved
.Unlisted()
.DependsOn(Compile)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.OnlyWhenDynamic(() => EnvironmentInfo.IsWin && (RunAllTargets || HasSourceChanges))
.Executes(() =>
{
Project[] projects = new[]
{
Solution.Specs.FluentAssertions_Specs,
Solution.Specs.FluentAssertions_Equivalency_Specs
};

if (EnvironmentInfo.IsWin)
{
Xunit2(s =>
{
IEnumerable<string> testAssemblies = projects
.SelectMany(project => GlobFiles(project.Directory, "bin/Debug/net47/*.Specs.dll"));

Assert.NotEmpty(testAssemblies.ToList());

return s
.SetFramework("net47")
.AddTargetAssemblies(testAssemblies);
});
}
IEnumerable<string> testAssemblies = Projects
.SelectMany(project => GlobFiles(project.Directory, "bin/Debug/net47/*.Specs.dll"));

Assert.NotEmpty(testAssemblies.ToList());

Xunit2(s => s
.SetFramework("net47")
.AddTargetAssemblies(testAssemblies)
);
});

Target UnitTestsNetCore => _ => _
.Unlisted()
.DependsOn(Compile)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
{
DotNetTest(s => s
.SetConfiguration("Debug")
jnyrup marked this conversation as resolved.
Show resolved Hide resolved
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
Expand All @@ -174,7 +175,7 @@ class Build : NukeBuild
"DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.DoesNotReturnAttribute",
"DoesNotReturnAttribute")
.CombineWith(
projects,
Projects,
(_, project) => _
.SetProjectFile(project)
.CombineWith(
Expand All @@ -185,8 +186,12 @@ class Build : NukeBuild
);
});

Target UnitTests => _ => _
.DependsOn(UnitTestsNetFramework)
.DependsOn(UnitTestsNetCore);

Target CodeCoverage => _ => _
.DependsOn(TestFrameworks)
.DependsOn(TestFrameworks)
.DependsOn(UnitTests)
.OnlyWhenDynamic(() => RunAllTargets || HasSourceChanges)
.Executes(() =>
Expand All @@ -195,7 +200,9 @@ class Build : NukeBuild
.SetProcessToolPath(ToolPathResolver.GetPackageExecutable("ReportGenerator", "ReportGenerator.dll", framework: "net6.0"))
.SetTargetDirectory(TestResultsDirectory / "reports")
.AddReports(TestResultsDirectory / "**/coverage.cobertura.xml")
.AddReportTypes("HtmlInline_AzurePipelines_Dark", "lcov")
.AddReportTypes(
ReportTypes.lcov,
ReportTypes.HtmlInline_AzurePipelines_Dark)
.AddFileFilters("-*.g.cs")
.SetAssemblyFilters("+FluentAssertions"));

Expand Down Expand Up @@ -262,14 +269,15 @@ class Build : NukeBuild
Target Push => _ => _
.DependsOn(Pack)
.OnlyWhenDynamic(() => IsTag)
.ProceedAfterFailure()
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
.Executes(() =>
{
IReadOnlyCollection<string> packages = GlobFiles(ArtifactsDirectory, "*.nupkg");

Assert.NotEmpty(packages.ToList());

DotNetNuGetPush(s => s
.SetApiKey(ApiKey)
.SetApiKey(NuGetApiKey)
.EnableSkipDuplicate()
.SetSource("https://api.nuget.org/v3/index.json")
.EnableNoSymbols()
Expand All @@ -279,13 +287,16 @@ class Build : NukeBuild

Target SpellCheck => _ => _
.OnlyWhenDynamic(() => RunAllTargets || HasDocumentationChanges)
.ProceedAfterFailure()
.Executes(() =>
{
Node($"{YarnCli} install --silent", workingDirectory: RootDirectory);
Node($"{YarnCli} --silent run cspell --no-summary", workingDirectory: RootDirectory,
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
Node($"{YarnCli} install", workingDirectory: RootDirectory);
Node($"{YarnCli} run cspell", workingDirectory: RootDirectory,
customLogger: (_, msg) => Error(msg));
});

string YarnCli => $"{ToolPathResolver.GetPackageExecutable("Yarn.MSBuild", "yarn.js", "1.22.19")} --silent";
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,7 +1,7 @@
{
"version": "1.0.0",
"version": "1.0.1",
"scripts": {
"cspell": "cspell --config ./cSpell.json ./docs/**/*.md --no-progress"
"cspell": "cspell --config ./cSpell.json ./docs/**/*.md --no-progress --no-summary"
},
"dependencies": {
"cspell": "^6.18.1"
Expand Down