* Update packages.yml * Added sonar cloud properties * Update packages.yml * Update packages.yml * Update packages.yml * Update packages.yml * Updated nuke Build to produce test coverage output * Updated project key * Fix organization key * Versioning fix * Removed sonar properties * Added jdk17 * Changed build configuration for nuke * Added opencover paths * Added the coverlet collector NuGet package * Added exclusions * Updated workflow * Modified exclusions * Updated packages.yml to contain sonar cloud integration * Removed test github action * Updated for test coverage * Updated MergeWith property for the tests * Add verbose to check for code coverage issue * Updated reportPaths * Added --collect parameter * Updates * Updated packages workflow * Updated exclusions * Added sonar exclusions * Updated exclusions --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
85 lines
3.4 KiB
C#
85 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Nuke.Common;
|
|
using Nuke.Common.CI;
|
|
using Nuke.Common.CI.GitHubActions;
|
|
using Nuke.Common.Git;
|
|
using Nuke.Common.IO;
|
|
using Nuke.Common.ProjectModel;
|
|
using Nuke.Common.Tooling;
|
|
using Nuke.Common.Tools.Coverlet;
|
|
using Nuke.Common.Tools.DotNet;
|
|
using Nuke.Common.Tools.SonarScanner;
|
|
using Nuke.Common.Utilities.Collections;
|
|
using Nuke.Components;
|
|
using Serilog;
|
|
|
|
[ShutdownDotNetAfterServerBuild]
|
|
partial class Build : NukeBuild, ITest, IPack
|
|
{
|
|
public static int Main() => Execute<Build>(x => ((ICompile)x).Compile);
|
|
|
|
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
|
|
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
|
|
|
|
[GitRepository] readonly GitRepository GitRepository;
|
|
|
|
AbsolutePath SourceDirectory => RootDirectory / "src";
|
|
|
|
public AbsolutePath PackagesDirectory => RootDirectory / "packages";
|
|
public AbsolutePath TestResultDirectory => RootDirectory / "testresults";
|
|
|
|
string TagVersion => GitRepository.Tags.SingleOrDefault(x => "v".StartsWith(x))?[1..];
|
|
bool IsTaggedBuild => !string.IsNullOrWhiteSpace(TagVersion);
|
|
|
|
string VersionSuffix;
|
|
|
|
[Parameter] string Version;
|
|
|
|
[Parameter] bool AnalyseCode;
|
|
|
|
protected override void OnBuildInitialized()
|
|
{
|
|
VersionSuffix = !IsTaggedBuild
|
|
? $"preview-{DateTime.UtcNow:yyyyMMdd-HHmm}"
|
|
: "";
|
|
|
|
if (IsLocalBuild)
|
|
{
|
|
VersionSuffix = $"dev-{DateTime.UtcNow:yyyyMMdd-HHmm}";
|
|
}
|
|
|
|
Log.Information("BUILD SETUP:\nConfiguration: {Configuration}\nVersion Suffix: {VersionSuffix}\nVersion: {Version}\nTagged Build: {IsTaggedBuild}\nAnalyse Code: {AnalyseCode}",
|
|
Configuration, VersionSuffix, Version, IsTaggedBuild, AnalyseCode);
|
|
}
|
|
|
|
Target Clean => _ => _
|
|
.Before<IRestore>(x => x.Restore)
|
|
.Executes(() =>
|
|
{
|
|
SourceDirectory.GlobDirectories("**/bin", "**/obj").ForEach(x => x.DeleteDirectory());
|
|
((IHazArtifacts)this).ArtifactsDirectory.CreateOrCleanDirectory();
|
|
|
|
TestResultDirectory.CreateOrCleanDirectory();
|
|
});
|
|
|
|
|
|
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);
|
|
|
|
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"))
|
|
.When(AnalyseCode, settings => settings.SetCoverletOutputFormat(CoverletOutputFormat.opencover))
|
|
.When(AnalyseCode, settings => settings.EnableCollectCoverage())
|
|
.When(AnalyseCode, settings => settings.SetResultsDirectory(TestResultDirectory))
|
|
.When(AnalyseCode, settings => settings.SetCoverletOutput($"{TestResultDirectory}/opencoverCoverage.xml"))
|
|
.When(AnalyseCode, settings => settings.SetProcessArgumentConfigurator(args =>
|
|
args.Add("--collect:\"XPlat Code Coverage;Format=opencover\"")));
|
|
} |