continuity/build/Build.cs

98 lines
3.2 KiB
C#
Raw Normal View History

2023-10-08 10:47:30 +00:00
using System;
using System.Linq;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.GitHubActions;
2023-10-08 10:47:30 +00:00
using Nuke.Common.Execution;
using Nuke.Common.Git;
2023-10-08 10:47:30 +00:00
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.CodeMetrics;
using Nuke.Common.Tools.Docker;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.SonarScanner;
2023-10-08 10:47:30 +00:00
using Nuke.Common.Utilities.Collections;
using Serilog;
2023-10-08 10:47:30 +00:00
using static Nuke.Common.EnvironmentInfo;
using static Nuke.Common.IO.FileSystemTasks;
using static Nuke.Common.IO.PathConstruction;
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.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;
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)
.Executes(() =>
{
DotNetTasks.DotNetClean();
2023-10-08 10:47:30 +00:00
});
Target Restore => _ => _
.Executes(() =>
{
DotNetTasks.DotNetRestore();
2023-10-08 10:47:30 +00:00
});
Target Compile => _ => _
.DependsOn(Clean)
2023-10-08 10:47:30 +00:00
.DependsOn(Restore)
.Executes(() =>
{
DockerTasks.DockerStackRm(settings => settings.SetStacks("continuity"));
DotNetTasks.DotNetBuild(settings => settings.SetNoRestore(true));
2023-10-08 10:47:30 +00:00
});
Target Pack => _ => _
.DependsOn(Compile)
.Executes(() =>
{
DockerTasks.DockerBuild(settings => settings
.SetPath(AbsolutePath.Create(RootDirectory))
.SetFile("Server/Dockerfile")
.SetTag("continuity-server:latest")
.SetCompress(true)
.SetProgress(ProgressType.auto));
if (!IsLocalBuild)
{
DockerTasks.DockerPush(settings => settings.SetName("continuity-server:latest"));
}
});
Target Deploy => _ => _.DependsOn(Pack).Executes(() =>
{
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
}