Skip to content

Commit

Permalink
Reworked Test and Coverage Builds (ChilliCream#4578)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib authored Dec 21, 2021
1 parent 4d792b1 commit 1413abe
Show file tree
Hide file tree
Showing 56 changed files with 575 additions and 121 deletions.
26 changes: 26 additions & 0 deletions .build/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/Build.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
2 changes: 2 additions & 0 deletions .build/Build.GitHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ partial class Build
{
[Parameter] readonly string GitHubToken;

[Parameter] readonly string CodeCovToken;

/// <summary>
/// ChilliCream/hotchocolate
/// </summary>
Expand Down
27 changes: 18 additions & 9 deletions .build/Build.Sonar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ partial class Build

SonarScannerBegin(SonarBeginPrSettings);
DotNetBuild(SonarBuildAll);
DotNetTest(
c => CoverNoBuildSettingsOnlyNet60(c, CoverProjects),
degreeOfParallelism: DegreeOfParallelism,
completeOnFailure: true);
try
{
DotNetTest(
c => CoverNoBuildSettingsOnlyNet60(c, CoverProjects),
degreeOfParallelism: DegreeOfParallelism,
completeOnFailure: true);
}
catch { }
SonarScannerEnd(SonarEndSettings);
});

Expand All @@ -56,10 +60,14 @@ partial class Build

SonarScannerBegin(SonarBeginFullSettings);
DotNetBuild(SonarBuildAll);
DotNetTest(
c => CoverNoBuildSettingsOnlyNet60(c, CoverProjects),
degreeOfParallelism: DegreeOfParallelism,
completeOnFailure: true);
try
{
DotNetTest(
c => CoverNoBuildSettingsOnlyNet60(c, CoverProjects),
degreeOfParallelism: DegreeOfParallelism,
completeOnFailure: true);
}
catch { }
SonarScannerEnd(SonarEndSettings);
});

Expand Down Expand Up @@ -109,7 +117,8 @@ DotNetBuildSettings SonarBuildAll(DotNetBuildSettings settings) =>
.SetProjectFile(SonarSolutionFile)
.SetNoRestore(true)
.SetConfiguration(Debug)
.SetProcessWorkingDirectory(RootDirectory);
.SetProcessWorkingDirectory(RootDirectory)
.SetFramework(Net60);

bool IsRelevantForSonar(string fileName)
=> !ExcludedCover.Contains(GetFileNameWithoutExtension(fileName));
Expand Down
50 changes: 39 additions & 11 deletions .build/Build.Tests.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Nuke.Common;
using Nuke.Common.CI;
using Nuke.Common.CI.AzurePipelines;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.Codecov;
using Nuke.Common.Tools.Coverlet;
using Nuke.Common.Tools.DotNet;
using Nuke.Common.Tools.ReportGenerator;
using Nuke.Common.Utilities.Collections;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Nuke.Common.Tools.ReportGenerator.ReportGeneratorTasks;
using static Nuke.Common.Tools.Codecov.CodecovTasks;
using static Helpers;
using System;
using System.Diagnostics;

partial class Build
{
Expand Down Expand Up @@ -67,11 +72,7 @@ partial class Build
}
finally
{
TestResultDirectory.GlobFiles("*.trx").ForEach(x =>
DevOpsPipeLine?.PublishTestResults(
type: AzurePipelinesTestResultsType.VSTest,
title: $"{Path.GetFileNameWithoutExtension(x)} ({DevOpsPipeLine.StageDisplayName})",
files: new string[] { x }));
UploadTestsAndMismatches();
}
});

Expand All @@ -97,11 +98,7 @@ partial class Build
}
finally
{
TestResultDirectory.GlobFiles("*.trx").ForEach(x =>
DevOpsPipeLine?.PublishTestResults(
type: AzurePipelinesTestResultsType.VSTest,
title: $"{Path.GetFileNameWithoutExtension(x)} ({DevOpsPipeLine.StageDisplayName})",
files: new string[] { x }));
UploadTestsAndMismatches();
}
});

Expand All @@ -116,7 +113,7 @@ partial class Build
.SetTargetDirectory(CoverageReportDirectory)
.SetAssemblyFilters("-*Tests"));

if (DevOpsPipeLine is { })
if (DevOpsPipeLine is not null)
{
CoverageReportDirectory.GlobFiles("*.xml").ForEach(x =>
DevOpsPipeLine.PublishCodeCoverage(
Expand Down Expand Up @@ -165,4 +162,35 @@ DotNetTestSettings TestBaseSettings(DotNetTestSettings settings) =>
.SetNoBuild(true)
.ResetVerbosity()
.SetResultsDirectory(TestResultDirectory);

void UploadTestsAndMismatches()
{
if (DevOpsPipeLine is not null)
{
TestResultDirectory.GlobFiles("*.trx")
.ForEach(x =>
DevOpsPipeLine.PublishTestResults(
type: AzurePipelinesTestResultsType.VSTest,
title: $"{Path.GetFileNameWithoutExtension(x)} ({DevOpsPipeLine.StageDisplayName})",
files: new string[] { x }));

string uploadDir = Path.Combine(RootDirectory, "mismatch");

if (!Directory.Exists(uploadDir))
{
Directory.CreateDirectory(uploadDir);
}

foreach (string mismatchDir in Directory.GetDirectories(
RootDirectory, "__mismatch__", SearchOption.AllDirectories))
{
foreach (string snapshot in Directory.GetFiles(mismatchDir, "*.*"))
{
File.Copy(snapshot, Path.Combine(uploadDir, Path.GetFileName(snapshot)));
}
}

DevOpsPipeLine.UploadArtifacts("foo", "__mismatch__", uploadDir);
}
}
}
4 changes: 2 additions & 2 deletions .build/Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

<ItemGroup>
<PackageDownload Include="GitVersion.Tool" Version="[5.8.1]" />
<PackageDownload Include="NuGet.CommandLine" Version="[5.11.0]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[5.3.2]" />
<PackageDownload Include="NuGet.CommandLine" Version="[6.0.0]" />
<PackageDownload Include="dotnet-sonarscanner" Version="[5.4.0]" />
<PackageDownload Include="OpenCover" Version="[4.7.1221]" />
<PackageDownload Include="ReportGenerator" Version="[5.0.0]" />
<PackageDownload Include="xunit.runner.console" Version="[2.4.1]" />
Expand Down
19 changes: 0 additions & 19 deletions .github/workflows/check-public-api.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"Breaking": {
"type": "boolean"
},
"CodeCovToken": {
"type": "string"
},
"Configuration": {
"type": "string",
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)"
Expand Down Expand Up @@ -107,6 +110,7 @@
"Pack",
"PackLocal",
"Publish",
"ReportCodecov",
"ReportCoverage",
"Reset",
"Restore",
Expand Down Expand Up @@ -139,6 +143,7 @@
"Pack",
"PackLocal",
"Publish",
"ReportCodecov",
"ReportCoverage",
"Reset",
"Restore",
Expand Down
Loading

0 comments on commit 1413abe

Please sign in to comment.