Skip to content

Commit

Permalink
feat: implement nuild script
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-shirbandi committed Oct 6, 2023
1 parent 75f1bfe commit 9f42792
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 42 deletions.
18 changes: 15 additions & 3 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"properties": {
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
"enum": [
"Debug",
"Release"
Expand Down Expand Up @@ -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}'",
Expand All @@ -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'",
Expand Down
11 changes: 0 additions & 11 deletions src/6-Build/.editorconfig

This file was deleted.

78 changes: 64 additions & 14 deletions src/6-Build/Build.cs
Original file line number Diff line number Diff line change
@@ -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<Build>(x => x.Compile);
public static int Main() => Execute<Build>(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")));
});
}
28 changes: 14 additions & 14 deletions src/6-Build/Build.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace></RootNamespace>
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
<NukeRootDirectory>..\..</NukeRootDirectory>
<NukeScriptDirectory>..\..</NukeScriptDirectory>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>TaskoMask.Build</AssemblyName>
<RootNamespace>TaskoMask.Build</RootNamespace>
<NoWarn>CS0649;CS0169;CA1050;CA1822;CA2211;IDE1006</NoWarn>
<NukeTelemetryVersion>1</NukeTelemetryVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nuke.Common" Version="7.0.6" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nuke.Common" Version="7.0.6" />
<PackageReference Include="Serilog" Version="3.0.1" />
</ItemGroup>

</Project>

0 comments on commit 9f42792

Please sign in to comment.