2024-01-21 09:53:07 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Nuke.Common;
|
|
|
|
|
using Nuke.Common.CI;
|
2024-02-04 09:15:08 +00:00
|
|
|
using Nuke.Common.CI.GitHubActions;
|
2024-01-21 09:53:07 +00:00
|
|
|
using Nuke.Common.Git;
|
|
|
|
|
using Nuke.Common.IO;
|
|
|
|
|
using Nuke.Common.ProjectModel;
|
|
|
|
|
using Nuke.Common.Tooling;
|
2024-04-26 13:46:34 +00:00
|
|
|
using Nuke.Common.Tools.Coverlet;
|
2024-01-21 09:53:07 +00:00
|
|
|
using Nuke.Common.Tools.DotNet;
|
|
|
|
|
using Nuke.Common.Utilities.Collections;
|
|
|
|
|
using Nuke.Components;
|
|
|
|
|
using Serilog;
|
|
|
|
|
|
|
|
|
|
[ShutdownDotNetAfterServerBuild]
|
|
|
|
|
partial class Build : NukeBuild, ITest, IPack
|
|
|
|
|
{
|
2024-04-26 13:46:34 +00:00
|
|
|
public static int Main() => Execute<Build>(x => ((ICompile)x).Compile);
|
2024-01-21 09:53:07 +00:00
|
|
|
|
2024-04-26 13:46:34 +00:00
|
|
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
|
|
|
|
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
|
2024-01-21 09:53:07 +00:00
|
|
|
|
|
|
|
|
[GitRepository] readonly GitRepository GitRepository;
|
|
|
|
|
|
|
|
|
|
AbsolutePath SourceDirectory => RootDirectory / "src";
|
|
|
|
|
|
|
|
|
|
public AbsolutePath PackagesDirectory => RootDirectory / "packages";
|
2024-04-26 13:46:34 +00:00
|
|
|
public AbsolutePath TestResultDirectory => RootDirectory / "testresults";
|
2024-01-21 09:53:07 +00:00
|
|
|
|
|
|
|
|
string TagVersion => GitRepository.Tags.SingleOrDefault(x => "v".StartsWith(x))?[1..];
|
|
|
|
|
bool IsTaggedBuild => !string.IsNullOrWhiteSpace(TagVersion);
|
|
|
|
|
|
|
|
|
|
string VersionSuffix;
|
|
|
|
|
|
2024-04-26 13:46:34 +00:00
|
|
|
[Parameter] string Version;
|
|
|
|
|
|
|
|
|
|
[Parameter] bool AnalyseCode;
|
2024-01-21 09:53:07 +00:00
|
|
|
|
|
|
|
|
protected override void OnBuildInitialized()
|
|
|
|
|
{
|
|
|
|
|
VersionSuffix = !IsTaggedBuild
|
|
|
|
|
? $"preview-{DateTime.UtcNow:yyyyMMdd-HHmm}"
|
|
|
|
|
: "";
|
|
|
|
|
|
|
|
|
|
if (IsLocalBuild)
|
|
|
|
|
{
|
|
|
|
|
VersionSuffix = $"dev-{DateTime.UtcNow:yyyyMMdd-HHmm}";
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-26 13:46:34 +00:00
|
|
|
Log.Information("BUILD SETUP:\nConfiguration: {Configuration}\nVersion Suffix: {VersionSuffix}\nVersion: {Version}\nTagged Build: {IsTaggedBuild}\nAnalyse Code: {AnalyseCode}",
|
|
|
|
|
Configuration, VersionSuffix, Version, IsTaggedBuild, AnalyseCode);
|
2024-01-21 09:53:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Target Clean => _ => _
|
|
|
|
|
.Before<IRestore>(x => x.Restore)
|
|
|
|
|
.Executes(() =>
|
|
|
|
|
{
|
|
|
|
|
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(x => x.DeleteDirectory());
|
2024-04-26 13:46:34 +00:00
|
|
|
((IHazArtifacts)this).ArtifactsDirectory.CreateOrCleanDirectory();
|
2024-07-24 12:30:39 +00:00
|
|
|
|
2024-04-26 13:46:34 +00:00
|
|
|
TestResultDirectory.CreateOrCleanDirectory();
|
2024-01-21 09:53:07 +00:00
|
|
|
});
|
2024-07-24 12:30:39 +00:00
|
|
|
|
|
|
|
|
public Configure<DotNetRestoreSettings> RestoreSettings => _ => _
|
|
|
|
|
.SetVerbosity(DotNetVerbosity.quiet);
|
2024-01-21 09:53:07 +00:00
|
|
|
|
|
|
|
|
public Configure<DotNetBuildSettings> CompileSettings => _ => _
|
|
|
|
|
// ensure we don't generate too much output in CI run
|
|
|
|
|
// 0 Turns off emission of all warning messages
|
|
|
|
|
// 1 Displays severe warning messages
|
|
|
|
|
.SetWarningLevel(IsServerBuild ? 0 : 1);
|
|
|
|
|
|
2024-04-26 13:46:34 +00:00
|
|
|
public IEnumerable<Project> TestProjects =>
|
|
|
|
|
((IHazSolution)this).Solution.AllProjects.Where(x => x.Name.EndsWith("Tests"));
|
|
|
|
|
|
|
|
|
|
public Configure<DotNetTestSettings, Project> TestProjectSettings => (testSettings, project) => testSettings
|
|
|
|
|
.When(GitHubActions.Instance is not null, settings => settings.AddLoggers("GitHubActions;report-warnings=false"))
|
2024-07-24 12:30:39 +00:00
|
|
|
.When(AnalyseCode, settings => settings
|
|
|
|
|
.SetCoverletOutputFormat(CoverletOutputFormat.opencover)
|
|
|
|
|
.EnableCollectCoverage()
|
|
|
|
|
.SetResultsDirectory(TestResultDirectory)
|
|
|
|
|
.SetCoverletOutput($"{TestResultDirectory}/opencoverCoverage.xml")
|
|
|
|
|
.SetProcessArgumentConfigurator(args =>
|
|
|
|
|
args.Add("--collect:\"XPlat Code Coverage;Format=opencover\"")
|
|
|
|
|
)
|
|
|
|
|
);
|
2024-01-21 09:53:07 +00:00
|
|
|
}
|