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 all 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
97 changes: 54 additions & 43 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 All @@ -65,12 +64,13 @@ class Build : NukeBuild
#endif
Tool Node;

string YarnCli => $"{ToolPathResolver.GetPackageExecutable("Yarn.MSBuild", "yarn.js", "1.22.19")} --silent";

AbsolutePath ArtifactsDirectory => RootDirectory / "Artifacts";

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 +97,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 All @@ -117,7 +117,7 @@ class Build : NukeBuild
{
DotNetBuild(s => s
.SetProjectFile(Solution)
.SetConfiguration("CI")
IT-VBFK marked this conversation as resolved.
Show resolved Hide resolved
.SetConfiguration(Configuration.CI)
.EnableNoLogo()
.EnableNoRestore()
.SetAssemblyVersion(GitVersion.AssemblySemVer)
Expand All @@ -131,41 +131,44 @@ class Build : NukeBuild
.Executes(() =>
{
DotNetTest(s => s
.SetConfiguration("Release")
.SetConfiguration(Configuration.Release)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
.EnableNoBuild()
.CombineWith(
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")
.SetConfiguration(Configuration.Debug)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
.EnableNoBuild()
.SetDataCollector("XPlat Code Coverage")
Expand All @@ -174,7 +177,7 @@ class Build : NukeBuild
"DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.DoesNotReturnAttribute",
"DoesNotReturnAttribute")
.CombineWith(
projects,
Projects,
(_, project) => _
.SetProjectFile(project)
.CombineWith(
Expand All @@ -185,8 +188,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 +202,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 All @@ -222,7 +231,7 @@ class Build : NukeBuild
select new { project, framework };

DotNetTest(s => s
.SetConfiguration("Debug")
.SetConfiguration(Configuration.Debug)
.SetProcessEnvironmentVariable("DOTNET_CLI_UI_LANGUAGE", "en-US")
.EnableNoBuild()
.SetDataCollector("XPlat Code Coverage")
Expand Down Expand Up @@ -252,7 +261,7 @@ class Build : NukeBuild
DotNetPack(s => s
.SetProject(Solution.Core.FluentAssertions)
.SetOutputDirectory(ArtifactsDirectory)
.SetConfiguration("Release")
.SetConfiguration(Configuration.Release)
.EnableNoLogo()
.EnableNoRestore()
.EnableContinuousIntegrationBuild() // Necessary for deterministic builds
Expand All @@ -262,14 +271,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,10 +289,11 @@ 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));
});

Expand Down
15 changes: 15 additions & 0 deletions Build/Configuration.cs
@@ -0,0 +1,15 @@
using System.ComponentModel;
using Nuke.Common.Tooling;

[TypeConverter(typeof(TypeConverter<Configuration>))]
public class Configuration : Enumeration
{
public static Configuration Debug = new Configuration { Value = nameof(Debug) };
public static Configuration Release = new Configuration { Value = nameof(Release) };
public static Configuration CI = new Configuration { Value = nameof(CI) };

public static implicit operator string(Configuration configuration)
{
return configuration.Value;
}
}
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