2023-10-08 10:47:30 +00:00
|
|
|
using Nuke.Common;
|
2023-10-09 13:29:53 +00:00
|
|
|
using Nuke.Common.Git;
|
2023-10-08 10:47:30 +00:00
|
|
|
using Nuke.Common.IO;
|
2023-10-09 13:29:53 +00:00
|
|
|
using Nuke.Common.Tools.Docker;
|
|
|
|
using Nuke.Common.Tools.DotNet;
|
|
|
|
using Nuke.Common.Tools.SonarScanner;
|
|
|
|
using Serilog;
|
2023-10-08 10:47:30 +00:00
|
|
|
|
2023-10-27 18:19:37 +00:00
|
|
|
sealed class Build : NukeBuild
|
2023-10-08 10:47:30 +00:00
|
|
|
{
|
|
|
|
/// 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
|
2023-10-09 13:29:53 +00:00
|
|
|
public static int Main() => Execute<Build>(x => x.Information, x => x.Deploy);
|
2023-10-08 10:47:30 +00:00
|
|
|
|
|
|
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
|
|
|
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
|
|
|
|
|
2023-10-27 18:19:37 +00:00
|
|
|
[Parameter] readonly bool SupportsDocker = true;
|
|
|
|
|
2023-10-27 17:47:17 +00:00
|
|
|
[Parameter] readonly string SonarToken;
|
|
|
|
[Parameter] readonly string SonarHostUrl;
|
|
|
|
|
2023-10-09 13:29:53 +00:00
|
|
|
GitRepository GitRepository => GitRepository.FromLocalDirectory(RootDirectory);
|
|
|
|
|
|
|
|
Target Information => _ => _
|
|
|
|
.Before(Clean)
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
|
|
|
Log.Information("Branch Name: {BranchName}", GitRepository.Branch);
|
|
|
|
Log.Information("Commit: {Commit}", GitRepository.Commit);
|
|
|
|
});
|
|
|
|
|
2023-10-08 10:47:30 +00:00
|
|
|
Target Clean => _ => _
|
|
|
|
.Before(Restore)
|
2023-10-12 07:15:34 +00:00
|
|
|
.Executes(() => DotNetTasks.DotNetClean());
|
2023-10-08 10:47:30 +00:00
|
|
|
|
|
|
|
Target Restore => _ => _
|
2023-10-12 07:15:34 +00:00
|
|
|
.Executes(() => DotNetTasks.DotNetRestore());
|
2023-10-08 10:47:30 +00:00
|
|
|
|
|
|
|
Target Compile => _ => _
|
2023-10-09 13:29:53 +00:00
|
|
|
.DependsOn(Clean)
|
2023-10-08 10:47:30 +00:00
|
|
|
.DependsOn(Restore)
|
|
|
|
.Executes(() =>
|
|
|
|
{
|
2023-10-27 18:32:46 +00:00
|
|
|
if (IsLocalBuild && SupportsDocker)
|
2023-10-27 18:23:06 +00:00
|
|
|
{
|
2023-10-27 18:23:06 +00:00
|
|
|
DockerTasks.DockerStackRm(settings => settings.SetStacks("continuity"));
|
2023-10-27 18:23:06 +00:00
|
|
|
}
|
|
|
|
|
2023-10-09 13:29:53 +00:00
|
|
|
DotNetTasks.DotNetBuild(settings => settings.SetNoRestore(true));
|
2023-10-08 10:47:30 +00:00
|
|
|
});
|
|
|
|
|
2023-10-09 13:29:53 +00:00
|
|
|
Target Pack => _ => _
|
2023-10-27 17:47:17 +00:00
|
|
|
.DependsOn(SonarScan)
|
2023-10-09 13:29:53 +00:00
|
|
|
.Executes(() =>
|
|
|
|
{
|
2023-10-27 18:23:06 +00:00
|
|
|
if (!SupportsDocker)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-09 13:29:53 +00:00
|
|
|
DockerTasks.DockerBuild(settings => settings
|
|
|
|
.SetPath(AbsolutePath.Create(RootDirectory))
|
|
|
|
.SetFile("Server/Dockerfile")
|
|
|
|
.SetTag("continuity-server:latest")
|
|
|
|
.SetCompress(true)
|
|
|
|
.SetProgress(ProgressType.auto));
|
|
|
|
if (!IsLocalBuild)
|
|
|
|
{
|
2023-10-27 17:47:17 +00:00
|
|
|
//DockerTasks.DockerPush(settings => settings.SetName("continuity-server:latest"));
|
2023-10-09 13:29:53 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-10-27 17:47:17 +00:00
|
|
|
Target SonarScan => _ => _.DependsOn(Compile).Executes(() =>
|
|
|
|
{
|
|
|
|
if (IsLocalBuild)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-27 17:58:27 +00:00
|
|
|
|
2023-10-27 17:47:17 +00:00
|
|
|
var sonarScannerSettings = new SonarScannerBeginSettings()
|
2023-10-27 19:01:16 +00:00
|
|
|
.SetProjectKey("wonderking_continuity_AYeecUUTs-PH__JrTRky")
|
2023-10-27 18:49:06 +00:00
|
|
|
.SetLogin(SonarToken)
|
2023-10-27 17:47:17 +00:00
|
|
|
.SetServer(SonarHostUrl);
|
2023-10-28 13:23:00 +00:00
|
|
|
var sonarScannerEndSettings = new SonarScannerEndSettings().SetLogin(SonarToken);
|
2023-10-28 13:20:25 +00:00
|
|
|
SonarScannerTasks.SonarScannerBegin(sonarScannerSettings);
|
2023-10-27 18:42:53 +00:00
|
|
|
DotNetTasks.DotNetBuild(settings => settings.SetNoRestore(true));
|
2023-10-27 19:19:48 +00:00
|
|
|
SonarScannerTasks.SonarScannerEnd(sonarScannerEndSettings);
|
2023-10-27 17:58:27 +00:00
|
|
|
});
|
2023-10-27 17:47:17 +00:00
|
|
|
|
2023-10-09 13:29:53 +00:00
|
|
|
Target Deploy => _ => _.DependsOn(Pack).Executes(() =>
|
|
|
|
{
|
2023-10-27 18:23:06 +00:00
|
|
|
if (!SupportsDocker)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-10-09 13:29:53 +00:00
|
|
|
DockerTasks.DockerPull(settings => settings.SetName("postgres:16.0-alpine"));
|
|
|
|
if (IsLocalBuild)
|
|
|
|
{
|
|
|
|
var dockerComposeFile = AbsolutePath.Create(RootDirectory / "Server" / "docker-compose.yml");
|
|
|
|
DockerTasks.DockerStackDeploy(settings => settings
|
|
|
|
.AddComposeFile(dockerComposeFile)
|
|
|
|
.SetStack("continuity")
|
|
|
|
.SetPrune(true)
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.Error("Deploy is only available on local builds.");
|
|
|
|
});
|
2023-10-08 10:47:30 +00:00
|
|
|
}
|