From 6dd8e200d116c45a7653efbf37260716477c47f4 Mon Sep 17 00:00:00 2001 From: Geert van Horrik Date: Sat, 21 Sep 2024 18:21:41 +0200 Subject: [PATCH] GitHubSync update --- deployment/cake/lib-generic.cake | 39 ++++++--- deployment/cake/lib-nuget.cake | 14 ++-- deployment/cake/tasks.cake | 4 +- deployment/cake/tests-nunit.cake | 2 +- deployment/cake/tests-variables.cake | 2 + deployment/cake/tests.cake | 115 +++++++++++++++------------ 6 files changed, 102 insertions(+), 74 deletions(-) diff --git a/deployment/cake/lib-generic.cake b/deployment/cake/lib-generic.cake index 7ab6571..c45cb4a 100644 --- a/deployment/cake/lib-generic.cake +++ b/deployment/cake/lib-generic.cake @@ -517,16 +517,7 @@ private static bool IsDotNetCoreProject(BuildContext buildContext, string projec var lowerCase = line.ToLower(); if (lowerCase.Contains("targetframework")) { - if (lowerCase.Contains("netcore")) - { - isDotNetCore = true; - break; - } - - if (lowerCase.Contains("net5") || - lowerCase.Contains("net6") || - lowerCase.Contains("net7") || - lowerCase.Contains("net8")) + if (IsDotNetCoreTargetFramework(buildContext, lowerCase)) { isDotNetCore = true; break; @@ -542,6 +533,30 @@ private static bool IsDotNetCoreProject(BuildContext buildContext, string projec //------------------------------------------------------------- +private static bool IsDotNetCoreTargetFramework(BuildContext buildContext, string targetFramework) +{ + var lowerCase = targetFramework.ToLower(); + + if (lowerCase.Contains("netcore")) + { + return true; + } + + if (lowerCase.Contains("net5") || + lowerCase.Contains("net6") || + lowerCase.Contains("net7") || + lowerCase.Contains("net8") || + lowerCase.Contains("net9") || + lowerCase.Contains("net10")) + { + return true; + } + + return false; +} + +//------------------------------------------------------------- + private static bool ShouldProcessProject(BuildContext buildContext, string projectName, bool checkDeployment = true) { @@ -660,7 +675,7 @@ private static string CreateInlinedProjectXml(BuildContext buildContext, string //------------------------------------------------------------- -private static List GetProjectRuntimesIdentifiers(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List runtimeIdentifiersToInvestigate) +private static List GetProjectRuntimesIdentifiers(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList runtimeIdentifiersToInvestigate) { var projectFileContents = System.IO.File.ReadAllText(solutionOrProjectFileName.FullPath)?.ToLower(); @@ -670,7 +685,7 @@ private static List GetProjectRuntimesIdentifiers(BuildContext buildCont { if (!string.IsNullOrWhiteSpace(runtimeIdentifier)) { - if (!projectFileContents.Contains(runtimeIdentifier.ToLower())) + if (!projectFileContents.Contains(runtimeIdentifier, StringComparison.OrdinalIgnoreCase)) { buildContext.CakeContext.Information("Project '{0}' does not support runtime identifier '{1}', removing from supported runtime identifiers list", solutionOrProjectFileName, runtimeIdentifier); continue; diff --git a/deployment/cake/lib-nuget.cake b/deployment/cake/lib-nuget.cake index 4f5a0bc..81ebe7a 100644 --- a/deployment/cake/lib-nuget.cake +++ b/deployment/cake/lib-nuget.cake @@ -54,11 +54,13 @@ private static void RestoreNuGetPackages(BuildContext buildContext, Cake.Core.IO var sources = SplitSeparatedList(buildContext.General.NuGet.PackageSources, ';'); - var runtimeIdentifiers = new List(new [] + var runtimeIdentifiers = new [] { + "win-x86", "win-x64", + "win-arm64", "browser-wasm" - }); + }; var supportedRuntimeIdentifiers = GetProjectRuntimesIdentifiers(buildContext, solutionOrProjectFileName, runtimeIdentifiers); @@ -68,7 +70,7 @@ private static void RestoreNuGetPackages(BuildContext buildContext, Cake.Core.IO //------------------------------------------------------------- -private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List sources, List runtimeIdentifiers) +private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList sources, IReadOnlyList runtimeIdentifiers) { if (!buildContext.General.NuGet.RestoreUsingNuGet) { @@ -91,7 +93,7 @@ private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Ca if (sources.Count > 0) { - nuGetRestoreSettings.Source = sources; + nuGetRestoreSettings.Source = sources.ToList(); } buildContext.CakeContext.NuGetRestore(solutionOrProjectFileName, nuGetRestoreSettings); @@ -104,7 +106,7 @@ private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Ca //------------------------------------------------------------- -private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List sources, List runtimeIdentifiers) +private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList sources, IReadOnlyList runtimeIdentifiers) { if (!buildContext.General.NuGet.RestoreUsingDotNetRestore) { @@ -141,7 +143,7 @@ private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildCon if (sources.Count > 0) { - restoreSettings.Sources = sources; + restoreSettings.Sources = sources.ToList(); } using (buildContext.CakeContext.UseDiagnosticVerbosity()) diff --git a/deployment/cake/tasks.cake b/deployment/cake/tasks.cake index 6ff0088..a7df9fb 100644 --- a/deployment/cake/tasks.cake +++ b/deployment/cake/tasks.cake @@ -36,7 +36,7 @@ // It probably means the tool is not correctly installed. // `dotnet tool install --global dotnet-sonarscanner --ignore-failed-sources` //#tool "nuget:?package=MSBuild.SonarQube.Runner.Tool&version=4.8.0" -#tool "nuget:?package=dotnet-sonarscanner&version=7.1.1" +#tool "nuget:?package=dotnet-sonarscanner&version=8.0.3" //------------------------------------------------------------- // BACKWARDS COMPATIBILITY CODE - START @@ -382,9 +382,9 @@ Task("Build") Verbose = false, Silent = true, - // Support waiting for the quality gate ArgumentCustomization = args => args .Append("/d:sonar.qualitygate.wait=true") + .Append("/d:sonar.scanner.scanAll=false") }; if (!string.IsNullOrWhiteSpace(buildContext.General.SonarQube.Organization)) diff --git a/deployment/cake/tests-nunit.cake b/deployment/cake/tests-nunit.cake index fe05b22..c7bdbd7 100644 --- a/deployment/cake/tests-nunit.cake +++ b/deployment/cake/tests-nunit.cake @@ -1,4 +1,4 @@ -#tool "nuget:?package=NUnit.ConsoleRunner&version=3.18.1" +#tool "nuget:?package=NUnit.ConsoleRunner&version=3.18.2" //------------------------------------------------------------- diff --git a/deployment/cake/tests-variables.cake b/deployment/cake/tests-variables.cake index fc9f69d..82e06ac 100644 --- a/deployment/cake/tests-variables.cake +++ b/deployment/cake/tests-variables.cake @@ -11,6 +11,7 @@ public class TestsContext : BuildContextWithItemsBase public string Framework { get; set; } public string TargetFramework { get; set; } + public string OperatingSystem { get; set; } public string ProcessBit { get; set; } protected override void ValidateContext() @@ -47,6 +48,7 @@ private TestsContext InitializeTestsContext(BuildContext buildContext, IBuildCon Framework = buildContext.BuildServer.GetVariable("TestFramework", "nunit", showValue: true), TargetFramework = buildContext.BuildServer.GetVariable("TestTargetFramework", "", showValue: true), + OperatingSystem = buildContext.BuildServer.GetVariable("TestOperatingSystem", "win", showValue: true), ProcessBit = buildContext.BuildServer.GetVariable("TestProcessBit", "X64", showValue: true) }; diff --git a/deployment/cake/tests.cake b/deployment/cake/tests.cake index a63a5a3..f2cb9dc 100644 --- a/deployment/cake/tests.cake +++ b/deployment/cake/tests.cake @@ -137,63 +137,70 @@ private static void RunUnitTests(BuildContext buildContext, string projectName) var ranTests = false; var failed = false; - var testTargetFramework = GetTestTargetFramework(buildContext, projectName); + var testTargetFrameworks = GetTestTargetFrameworks(buildContext, projectName); try { - if (IsDotNetCoreProject(buildContext, projectName)) + foreach (var testTargetFramework in testTargetFrameworks) { - buildContext.CakeContext.Information($"Project '{projectName}' is a .NET core project, using 'dotnet test' to run the unit tests"); - - var projectFileName = GetProjectFileName(buildContext, projectName); - - var dotNetTestSettings = new DotNetTestSettings - { - Configuration = buildContext.General.Solution.ConfigurationName, - // Loggers = new [] - // { - // "nunit;LogFilePath=test-result.xml" - // }, - NoBuild = true, - NoLogo = true, - NoRestore = true, - OutputDirectory = System.IO.Path.Combine(GetProjectOutputDirectory(buildContext, projectName), testTargetFramework), - ResultsDirectory = testResultsDirectory - }; - - if (IsNUnitTestProject(buildContext, projectName)) - { - dotNetTestSettings.ArgumentCustomization = args => args - .Append($"-- NUnit.TestOutputXml={testResultsDirectory}"); - } + LogSeparator(buildContext.CakeContext, "Running tests for target framework {0}", testTargetFramework); - if (IsXUnitTestProject(buildContext, projectName)) + if (IsDotNetCoreTargetFramework(buildContext, testTargetFramework)) { - var outputFileName = System.IO.Path.Combine(testResultsDirectory, $"{projectName}.xml"); + buildContext.CakeContext.Information($"Project '{projectName}' is a .NET core project, using 'dotnet test' to run the unit tests"); + + var projectFileName = GetProjectFileName(buildContext, projectName); + + var dotNetTestSettings = new DotNetTestSettings + { + Configuration = buildContext.General.Solution.ConfigurationName, + // Loggers = new [] + // { + // "nunit;LogFilePath=test-result.xml" + // }, + NoBuild = true, + NoLogo = true, + NoRestore = true, + OutputDirectory = System.IO.Path.Combine(GetProjectOutputDirectory(buildContext, projectName), testTargetFramework), + ResultsDirectory = testResultsDirectory + }; + + if (IsNUnitTestProject(buildContext, projectName)) + { + dotNetTestSettings.ArgumentCustomization = args => args + .Append($"-- NUnit.TestOutputXml={testResultsDirectory}"); + } + + if (IsXUnitTestProject(buildContext, projectName)) + { + var outputFileName = System.IO.Path.Combine(testResultsDirectory, $"{projectName}.xml"); + + dotNetTestSettings.ArgumentCustomization = args => args + .Append($"-l:trx;LogFileName={outputFileName}"); + } + + var processBit = buildContext.Tests.ProcessBit.ToLower(); + if (!string.IsNullOrWhiteSpace(processBit)) + { + dotNetTestSettings.Runtime = $"{buildContext.Tests.OperatingSystem}-{processBit}"; + } + + buildContext.CakeContext.Information($"Runtime: '{dotNetTestSettings.Runtime}'"); + + buildContext.CakeContext.DotNetTest(projectFileName, dotNetTestSettings); - dotNetTestSettings.ArgumentCustomization = args => args - .Append($"-l:trx;LogFileName={outputFileName}"); + ranTests = true; } - - var processBit = buildContext.Tests.ProcessBit.ToLower(); - if (!string.IsNullOrWhiteSpace(processBit)) + else { - dotNetTestSettings.Runtime = $"win-{processBit}"; - } - - buildContext.CakeContext.DotNetTest(projectFileName, dotNetTestSettings); - - ranTests = true; - } - else - { - buildContext.CakeContext.Information($"Project '{projectName}' is a .NET project, using '{buildContext.Tests.Framework} runner' to run the unit tests"); + buildContext.CakeContext.Information($"Project '{projectName}' is a .NET project, using '{buildContext.Tests.Framework} runner' to run the unit tests"); - if (IsNUnitTestProject(buildContext, projectName)) - { - RunTestsUsingNUnit(buildContext, projectName, testTargetFramework, testResultsDirectory); + if (IsNUnitTestProject(buildContext, projectName)) + { + RunTestsUsingNUnit(buildContext, projectName, testTargetFramework, testResultsDirectory); - ranTests = true; + ranTests = true; + } } } } @@ -273,7 +280,7 @@ private static bool IsXUnitTestProject(BuildContext buildContext, string project //------------------------------------------------------------- -private static string GetTestTargetFramework(BuildContext buildContext, string projectName) +private static IReadOnlyList GetTestTargetFrameworks(BuildContext buildContext, string projectName) { // Step 1: if defined, use defined value var testTargetFramework = buildContext.Tests.TargetFramework; @@ -281,20 +288,22 @@ private static string GetTestTargetFramework(BuildContext buildContext, string p { buildContext.CakeContext.Information("Using test target framework '{0}', specified via the configuration", testTargetFramework); - return testTargetFramework; + return new [] + { + testTargetFramework + }; } - buildContext.CakeContext.Information("Test target framework not specified, auto detecting test target framework"); + buildContext.CakeContext.Information("Test target framework not specified, auto detecting test target frameworks"); var targetFrameworks = GetTargetFrameworks(buildContext, projectName); - testTargetFramework = targetFrameworks.FirstOrDefault(); - buildContext.CakeContext.Information("Auto detected test target framework '{0}'", testTargetFramework); + buildContext.CakeContext.Information("Auto detected test target frameworks '{0}'", string.Join(", ", targetFrameworks)); - if (string.IsNullOrWhiteSpace(testTargetFramework)) + if (targetFrameworks.Length == 0) { throw new Exception(string.Format("Test target framework could not automatically be detected for project '{0]'", projectName)); } - return testTargetFramework; + return targetFrameworks; } \ No newline at end of file