Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHubSync update #564

Merged
merged 1 commit into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions deployment/cake/lib-generic.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand Down Expand Up @@ -660,7 +675,7 @@ private static string CreateInlinedProjectXml(BuildContext buildContext, string

//-------------------------------------------------------------

private static List<string> GetProjectRuntimesIdentifiers(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List<string> runtimeIdentifiersToInvestigate)
private static List<string> GetProjectRuntimesIdentifiers(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList<string> runtimeIdentifiersToInvestigate)
{
var projectFileContents = System.IO.File.ReadAllText(solutionOrProjectFileName.FullPath)?.ToLower();

Expand All @@ -670,7 +685,7 @@ private static List<string> 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;
Expand Down
14 changes: 8 additions & 6 deletions deployment/cake/lib-nuget.cake
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,13 @@ private static void RestoreNuGetPackages(BuildContext buildContext, Cake.Core.IO

var sources = SplitSeparatedList(buildContext.General.NuGet.PackageSources, ';');

var runtimeIdentifiers = new List<string>(new []
var runtimeIdentifiers = new []
{
"win-x86",
"win-x64",
"win-arm64",
"browser-wasm"
});
};

var supportedRuntimeIdentifiers = GetProjectRuntimesIdentifiers(buildContext, solutionOrProjectFileName, runtimeIdentifiers);

Expand All @@ -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<string> sources, List<string> runtimeIdentifiers)
private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList<string> sources, IReadOnlyList<string> runtimeIdentifiers)
{
if (!buildContext.General.NuGet.RestoreUsingNuGet)
{
Expand All @@ -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);
Expand All @@ -104,7 +106,7 @@ private static void RestoreNuGetPackagesUsingNuGet(BuildContext buildContext, Ca

//-------------------------------------------------------------

private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, List<string> sources, List<string> runtimeIdentifiers)
private static void RestoreNuGetPackagesUsingDotnetRestore(BuildContext buildContext, Cake.Core.IO.FilePath solutionOrProjectFileName, IReadOnlyList<string> sources, IReadOnlyList<string> runtimeIdentifiers)
{
if (!buildContext.General.NuGet.RestoreUsingDotNetRestore)
{
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions deployment/cake/tasks.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion deployment/cake/tests-nunit.cake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.18.1"
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.18.2"

//-------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions deployment/cake/tests-variables.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
};

Expand Down
115 changes: 62 additions & 53 deletions deployment/cake/tests.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -273,28 +280,30 @@ private static bool IsXUnitTestProject(BuildContext buildContext, string project

//-------------------------------------------------------------

private static string GetTestTargetFramework(BuildContext buildContext, string projectName)
private static IReadOnlyList<string> GetTestTargetFrameworks(BuildContext buildContext, string projectName)
{
// Step 1: if defined, use defined value
var testTargetFramework = buildContext.Tests.TargetFramework;
if (!string.IsNullOrWhiteSpace(testTargetFramework))
{
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;
}
Loading