diff --git a/.nuke/build.schema.json b/.nuke/build.schema.json index 184c799a9..607f91310 100644 --- a/.nuke/build.schema.json +++ b/.nuke/build.schema.json @@ -8,7 +8,6 @@ "properties": { "Configuration": { "type": "string", - "description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)", "enum": [ "Debug", "Release" @@ -74,10 +73,17 @@ "enum": [ "Clean", "Compile", - "Restore" + "Information", + "Preparation", + "Restore", + "RunUnitTests" ] } }, + "Solution": { + "type": "string", + "description": "Path to a solution file that is automatically loaded" + }, "Target": { "type": "array", "description": "List of targets to be invoked. Default is '{default_target}'", @@ -86,10 +92,16 @@ "enum": [ "Clean", "Compile", - "Restore" + "Information", + "Preparation", + "Restore", + "RunUnitTests" ] } }, + "TestResultDirectory": { + "type": "string" + }, "Verbosity": { "type": "string", "description": "Logging verbosity during build execution. Default is 'Normal'", diff --git a/src/6-Build/.editorconfig b/src/6-Build/.editorconfig deleted file mode 100644 index 31e43dcd8..000000000 --- a/src/6-Build/.editorconfig +++ /dev/null @@ -1,11 +0,0 @@ -[*.cs] -dotnet_style_qualification_for_field = false:warning -dotnet_style_qualification_for_property = false:warning -dotnet_style_qualification_for_method = false:warning -dotnet_style_qualification_for_event = false:warning -dotnet_style_require_accessibility_modifiers = never:warning - -csharp_style_expression_bodied_methods = true:silent -csharp_style_expression_bodied_properties = true:warning -csharp_style_expression_bodied_indexers = true:warning -csharp_style_expression_bodied_accessors = true:warning diff --git a/src/6-Build/Build.cs b/src/6-Build/Build.cs index 902602073..e40848270 100644 --- a/src/6-Build/Build.cs +++ b/src/6-Build/Build.cs @@ -1,44 +1,94 @@ -using System; +using Serilog; using System.Linq; using Nuke.Common; -using Nuke.Common.CI; -using Nuke.Common.Execution; -using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Tooling; -using Nuke.Common.Utilities.Collections; +using Nuke.Common.Tools.Coverlet; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.GitVersion; +using Nuke.Common.Tools.NuGet; using static Nuke.Common.EnvironmentInfo; using static Nuke.Common.IO.FileSystemTasks; using static Nuke.Common.IO.PathConstruction; +using static Nuke.Common.Tools.DotNet.DotNetTasks; +using static Nuke.Common.Tools.NuGet.NuGetTasks; +using static Nuke.Common.Tools.NuGet.NuGetPackSettingsExtensions; +using Nuke.Common.IO; +using Nuke.Common.Utilities.Collections; class Build : NukeBuild { - /// Support plugins are available for: - /// - JetBrains ReSharper https://nuke.build/resharper - /// - JetBrains Rider https://nuke.build/rider - /// - Microsoft VisualStudio https://nuke.build/visualstudio - /// - Microsoft VSCode https://nuke.build/vscode - - public static int Main () => Execute(x => x.Compile); + public static int Main() => Execute(x => x.RunUnitTests); - [Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")] + [Parameter] readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release; + [Solution] + readonly Solution Solution; + + [Parameter] + AbsolutePath TestResultDirectory = RootDirectory + "/Artifacts/Test-Results/"; + + Target Information => _ => _ + .Before(Preparation) + .Executes(() => + { + Log.Information($"Solution path : {Solution}"); + Log.Information($"Solution directory : {Solution.Directory}"); + Log.Information($"Configuration : {Configuration}"); + Log.Information($"TestResultDirectory : {TestResultDirectory}"); + }); + + Target Preparation => _ => _ + .DependsOn(Information) + .Executes(() => + { + TestResultDirectory.CreateOrCleanDirectory(); + }); + Target Clean => _ => _ - .Before(Restore) + .DependsOn(Preparation) .Executes(() => { + DotNetClean(); }); Target Restore => _ => _ + .DependsOn(Clean) .Executes(() => { + DotNetRestore(a => a.SetProjectFile(Solution)); }); Target Compile => _ => _ .DependsOn(Restore) .Executes(() => { + DotNetBuild(a => + a.SetProjectFile(Solution) + .SetNoRestore(true) + .SetConfiguration(Configuration)); }); + Target RunUnitTests => _ => _ + .DependsOn(Compile) + .Executes(() => + { + var testProjects = Solution.AllProjects.Where(s => s.Name.EndsWith("Tests.Unit")); + + DotNetTest(a => a + .SetConfiguration(Configuration) + .SetNoBuild(true) + .SetNoRestore(true) + .ResetVerbosity() + .SetResultsDirectory(TestResultDirectory) + .EnableCollectCoverage() + .SetCoverletOutputFormat(CoverletOutputFormat.opencover) + .SetExcludeByFile("*.Generated.cs") + .EnableUseSourceLink() + .CombineWith(testProjects, (b, z) => b + .SetProjectFile(z) + .AddLoggers($"trx;LogFileName={z.Name}.trx") + .SetCoverletOutput(TestResultDirectory + $"{z.Name}.xml"))); + }); } diff --git a/src/6-Build/Build.csproj b/src/6-Build/Build.csproj index 8223182f4..71f0c06d8 100644 --- a/src/6-Build/Build.csproj +++ b/src/6-Build/Build.csproj @@ -1,18 +1,18 @@ - + - - Exe - net6.0 - - CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 - ..\.. - ..\.. - 1 - false - + + Exe + net6.0 + TaskoMask.Build + TaskoMask.Build + CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006 + 1 + false + - - - + + + +