105 lines
No EOL
3.7 KiB
C#
105 lines
No EOL
3.7 KiB
C#
using Nuke.Common;
|
|
using Nuke.Common.CI.GitHubActions;
|
|
using Nuke.Common.Execution;
|
|
using Nuke.Common.Git;
|
|
using Nuke.Common.IO;
|
|
using Nuke.Common.ProjectModel;
|
|
using Nuke.Common.Tools.DotNet;
|
|
using Nuke.Common.Tools.GitVersion;
|
|
using Nuke.Common.Tools.BenchmarkDotNet;
|
|
using Nuke.Common.Utilities.Collections;
|
|
using static Nuke.Common.IO.FileSystemTasks;
|
|
using static Nuke.Common.Tools.BenchmarkDotNet.BenchmarkDotNetTasks;
|
|
using static Nuke.Common.Tools.DotNet.DotNetTasks;
|
|
|
|
[GitHubActions(
|
|
"dotnet",
|
|
GitHubActionsImage.UbuntuLatest,
|
|
AutoGenerate = false,
|
|
On = new []{GitHubActionsTrigger.Push, GitHubActionsTrigger.PullRequest}
|
|
)
|
|
]
|
|
[UnsetVisualStudioEnvironmentVariables]
|
|
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.Pack);
|
|
|
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
|
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
|
|
|
|
[Solution] readonly Solution Solution;
|
|
[GitRepository]
|
|
readonly GitRepository GitRepository;
|
|
[GitVersion(Framework = "net6.0", NoFetch = true)]
|
|
readonly GitVersion GitVersion;
|
|
|
|
AbsolutePath SourceDirectory => RootDirectory / "src";
|
|
AbsolutePath TestsDirectory => RootDirectory / "test";
|
|
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
|
|
|
|
Target Clean => _ => _
|
|
.Before(Restore)
|
|
.Executes(() =>
|
|
{
|
|
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
|
|
TestsDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
|
|
EnsureCleanDirectory(ArtifactsDirectory);
|
|
});
|
|
|
|
Target Restore => _ => _
|
|
.Executes(() =>
|
|
DotNetRestore(s => s
|
|
.SetProjectFile(Solution))
|
|
);
|
|
|
|
Target Compile => _ => _
|
|
.DependsOn(Restore)
|
|
.DependsOn(Clean)
|
|
.Executes(() => DotNetBuild(s => s
|
|
.SetProjectFile(Solution)
|
|
.SetConfiguration(Configuration)
|
|
.SetAssemblyVersion(GitVersion.AssemblySemVer)
|
|
.SetFileVersion(GitVersion.AssemblySemFileVer)
|
|
.SetInformationalVersion(GitVersion.InformationalVersion)
|
|
.EnableNoRestore()));
|
|
|
|
Target Test => _ => _
|
|
.DependsOn(Compile)
|
|
.Executes(() => DotNetTest(s => s
|
|
.SetProjectFile(Solution)
|
|
.SetConfiguration(Configuration)
|
|
.EnableNoRestore()
|
|
.EnableNoBuild()));
|
|
|
|
Target Pack => _ => _
|
|
.DependsOn(Test)
|
|
.OnlyWhenStatic(() => GitRepository.IsOnMasterBranch())
|
|
.Executes(() => SourceDirectory
|
|
.GlobFiles("**/*.csproj")
|
|
.ForEach(csproj => DotNetPack(s => s
|
|
.SetProject(csproj)
|
|
.SetConfiguration(Configuration)
|
|
.SetOutputDirectory(ArtifactsDirectory)
|
|
.SetVersion(GitVersion.FullSemVer)
|
|
.EnableIncludeSource()
|
|
.EnableIncludeSymbols()
|
|
.EnableNoRestore()
|
|
.EnableNoBuild()
|
|
)));
|
|
|
|
Target Benchmark => _ => _
|
|
.DependsOn(Compile)
|
|
.Executes(() => TestsDirectory
|
|
.GlobFiles($"**/bin/{Configuration.ToString()}/**/*Benchmark*.dll")
|
|
.ForEach(benchmarkFile => BenchmarkDotNet(
|
|
s => s
|
|
.SetRuntimes("net7.0")
|
|
.SetFilter("*")
|
|
.SetAssemblyFile(benchmarkFile)))
|
|
);
|
|
} |