79 lines
2.2 KiB
C#
79 lines
2.2 KiB
C#
using Nuke.Common;
|
|
using Nuke.Common.Execution;
|
|
using Nuke.Common.IO;
|
|
using Nuke.Common.ProjectModel;
|
|
using Nuke.Common.Tools.DotNet;
|
|
using Nuke.Common.Utilities.Collections;
|
|
using System;
|
|
using static Nuke.Common.IO.FileSystemTasks;
|
|
using static Nuke.Common.IO.PathConstruction;
|
|
using static Nuke.Common.Tools.DotNet.DotNetTasks;
|
|
|
|
[UnsetVisualStudioEnvironmentVariables]
|
|
class Build : NukeBuild {
|
|
|
|
public static int Main() => Execute<Build>(x => x.Publish);
|
|
|
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
|
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
|
|
[Parameter]
|
|
readonly string NugetApiKey;
|
|
[Parameter]
|
|
readonly string NugetEndpoint;
|
|
|
|
[Solution] readonly Solution Solution;
|
|
AbsolutePath SourceDirectory => RootDirectory / "src";
|
|
AbsolutePath OutputDirectory => RootDirectory / "output";
|
|
|
|
Target Clean => _ => _
|
|
.Executes(() => {
|
|
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(DeleteDirectory);
|
|
EnsureCleanDirectory(OutputDirectory);
|
|
});
|
|
|
|
Target Restore => _ => _
|
|
.DependsOn(Clean)
|
|
.Executes(() => {
|
|
DotNetRestore(s => s
|
|
.SetProjectFile(Solution));
|
|
});
|
|
|
|
Target Compile => _ => _
|
|
.DependsOn(Restore)
|
|
.Executes(() => {
|
|
DotNetBuild(s => s
|
|
.SetProjectFile(Solution)
|
|
.SetConfiguration(Configuration)
|
|
.EnableNoRestore());
|
|
});
|
|
|
|
Target Test => _ => _
|
|
.DependsOn(Compile)
|
|
.Executes(() => {
|
|
DotNetTest(s => s
|
|
.SetProjectFile(Solution)
|
|
.EnableNoRestore());
|
|
});
|
|
|
|
Target Package => _ => _
|
|
.DependsOn(Test)
|
|
.Executes(() => {
|
|
DotNetPack(s => s
|
|
.SetProject(Solution.Projects.SingleOrError(project => project.Name == "Robware.Lib.ApiClient", "ERROR FINDING API CLIENT PROJECT"))
|
|
.SetIncludeSymbols(true)
|
|
.SetSymbolPackageFormat(DotNetSymbolPackageFormat.snupkg)
|
|
.SetOutputDirectory(OutputDirectory));
|
|
});
|
|
|
|
Target Publish => _ => _
|
|
.DependsOn(Package)
|
|
.Executes(() => {
|
|
if (!string.IsNullOrEmpty(NugetApiKey) && !string.IsNullOrEmpty(NugetEndpoint))
|
|
DotNetNuGetPush(s => s
|
|
.SetApiKey(NugetApiKey)
|
|
.SetSource(NugetEndpoint)
|
|
.SetTargetPath(OutputDirectory/"*"));
|
|
else
|
|
Console.WriteLine("Endpoint and API key not specified, skipping");
|
|
});
|
|
}
|