diff --git a/.build/Build.cs b/.build/Build.cs index 220aeae6..a8925193 100644 --- a/.build/Build.cs +++ b/.build/Build.cs @@ -2,6 +2,7 @@ using Nuke.Common.CI; using Nuke.Common.Execution; using Nuke.Common.Git; +using Nuke.Common.IO; using Nuke.Common.ProjectModel; using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.GitVersion; @@ -76,4 +77,6 @@ internal partial class Pipeline : NukeBuild, [Parameter("Configuration to build")] public Configuration Configuration { get; } = IsLocalBuild ? Configuration.Debug : Configuration.Release; + + AbsolutePath IComprehendTests.RunSettings => RootDirectory / "src" / "Nuke" / "default.runsettings"; } diff --git a/src/Nuke/DotNetCore/ICanTestWithDotNetCore.cs b/src/Nuke/DotNetCore/ICanTestWithDotNetCore.cs index b1de89ef..562ed361 100644 --- a/src/Nuke/DotNetCore/ICanTestWithDotNetCore.cs +++ b/src/Nuke/DotNetCore/ICanTestWithDotNetCore.cs @@ -41,7 +41,6 @@ public interface ICanTestWithDotNetCore : IHaveBuildTarget, ) ) .CreateOrCleanDirectory(TestResultsDirectory) - .CleanCoverageDirectory(CoverageDirectory) .EnsureRunSettingsExists(RunSettings) .Net9MsBuildFix() .Executes( diff --git a/src/Nuke/DotNetCore/ICanTestWithDotNetCoreBuild.cs b/src/Nuke/DotNetCore/ICanTestWithDotNetCoreBuild.cs index 7d145e08..85756a96 100644 --- a/src/Nuke/DotNetCore/ICanTestWithDotNetCoreBuild.cs +++ b/src/Nuke/DotNetCore/ICanTestWithDotNetCoreBuild.cs @@ -43,7 +43,6 @@ public interface ICanTestWithDotNetCoreBuild : IHaveBuildTarget, ) ) .CreateOrCleanDirectory(TestResultsDirectory) - .CleanCoverageDirectory(CoverageDirectory) .EnsureRunSettingsExists(RunSettings) .Net9MsBuildFix() .Executes( @@ -53,9 +52,9 @@ public interface ICanTestWithDotNetCoreBuild : IHaveBuildTarget, .SetProjectFile(Solution) .SetDefaultLoggers(LogsDirectory / "test.log") .SetGitVersionEnvironment(GitVersion) - .EnableNoRestore() - .SetLoggers("trx") .SetConfiguration(TestBuildConfiguration) + .SetLoggers("trx") + .EnableNoRestore() .EnableNoBuild() .SetResultsDirectory(TestResultsDirectory) .SetSettingsFile(RunSettings) diff --git a/src/Nuke/IGenerateCodeCoverageBadges.cs b/src/Nuke/IGenerateCodeCoverageBadges.cs index 214f03a5..509a2864 100644 --- a/src/Nuke/IGenerateCodeCoverageBadges.cs +++ b/src/Nuke/IGenerateCodeCoverageBadges.cs @@ -23,6 +23,7 @@ public interface IGenerateCodeCoverageBadges : ITriggerCodeCoverageReports, IGen .TriggeredBy(CollectCodeCoverage) .Unlisted() .AssuredAfterFailure() + .ProceedAfterFailure() .OnlyWhenDynamic(() => InputReports.Any()) .Executes( () => ReportGeneratorTasks.ReportGenerator( diff --git a/src/Nuke/IGenerateCodeCoverageReport.cs b/src/Nuke/IGenerateCodeCoverageReport.cs index fdab20e8..95e2cd0e 100644 --- a/src/Nuke/IGenerateCodeCoverageReport.cs +++ b/src/Nuke/IGenerateCodeCoverageReport.cs @@ -23,6 +23,7 @@ public interface IGenerateCodeCoverageReport : ITriggerCodeCoverageReports, IGen .TriggeredBy(CollectCodeCoverage) .Unlisted() .AssuredAfterFailure() + .ProceedAfterFailure() .OnlyWhenDynamic(() => InputReports.Any()) .Executes( () => ReportGeneratorTasks.ReportGenerator( diff --git a/src/Nuke/IGenerateCodeCoverageSummary.cs b/src/Nuke/IGenerateCodeCoverageSummary.cs index 480bdc91..ab6865d4 100644 --- a/src/Nuke/IGenerateCodeCoverageSummary.cs +++ b/src/Nuke/IGenerateCodeCoverageSummary.cs @@ -23,6 +23,7 @@ public interface IGenerateCodeCoverageSummary : ITriggerCodeCoverageReports, IGe .TriggeredBy(CollectCodeCoverage) .Unlisted() .AssuredAfterFailure() + .ProceedAfterFailure() .OnlyWhenDynamic(() => InputReports.Any()) .Executes( () => ReportGeneratorTasks.ReportGenerator( diff --git a/src/Nuke/IHaveCodeCoverage.cs b/src/Nuke/IHaveCodeCoverage.cs index fb60e562..9c0de3e3 100644 --- a/src/Nuke/IHaveCodeCoverage.cs +++ b/src/Nuke/IHaveCodeCoverage.cs @@ -15,7 +15,8 @@ public interface IHaveCodeCoverage : IHaveArtifacts /// The directory where coverage artifacts are to be dropped /// [Parameter("The directory where coverage artifacts are to be dropped", Name = "Coverage")] - public AbsolutePath CoverageDirectory => EnvironmentInfo.GetVariable("Coverage") + public AbsolutePath CoverageDirectory => + EnvironmentInfo.GetVariable("Coverage") ?? TryGetValue(() => CoverageDirectory) ?? NukeBuild.RootDirectory / "coverage"; } diff --git a/src/Nuke/ITriggerCodeCoverageReports.cs b/src/Nuke/ITriggerCodeCoverageReports.cs index 0dc274ea..53c1d098 100644 --- a/src/Nuke/ITriggerCodeCoverageReports.cs +++ b/src/Nuke/ITriggerCodeCoverageReports.cs @@ -1,4 +1,6 @@ using Nuke.Common.IO; +using Nuke.Common.Tooling; +using Nuke.Common.Tools.DotNet; using Nuke.Common.Tools.ReportGenerator; // ReSharper disable SuspiciousTypeConversion.Global @@ -34,14 +36,21 @@ public interface ITriggerCodeCoverageReports : IHaveCodeCoverage, IHaveTestTarge .Executes( () => { - // Ensure anything that has been dropped in the test results from a collector is - // into the coverage directory - foreach (var file in TestResultsDirectory.GlobFiles("**/*.cobertura.xml")) -// .Where(x => Guid.TryParse(Path.GetFileName(x.Parent), out _)) - { - var relativePath = TestResultsDirectory.GetRelativePathTo(file); - file.Copy(CoverageDirectory.CreateOrCleanDirectory() / relativePath, ExistsPolicy.FileOverwriteIfNewer); - } + var coverageFiles = TestResultsDirectory.GlobFiles("**/*.cobertura*.xml"); + var coverageTool = DotNetTool.GetTool("dotnet-coverage"); + var args = new Arguments(); + args + .Add("merge") + .Add("{value}", coverageFiles, ' '); + + coverageTool( + new Arguments() + .Concatenate(args) + .Add("--format {value}", "cobertura") + .Add("--output {value}", CoverageDirectory.CreateOrCleanDirectory() / "solution.cobertura.xml") + .RenderForExecution(), + RootDirectory + ); } ); @@ -54,6 +63,7 @@ public interface ITriggerCodeCoverageReports : IHaveCodeCoverage, IHaveTestTarge .TriggeredBy(CollectCodeCoverage) .Unlisted() .AssuredAfterFailure() + .ProceedAfterFailure() .OnlyWhenDynamic(() => InputReports.Any()) .Executes( () => @@ -64,15 +74,6 @@ public interface ITriggerCodeCoverageReports : IHaveCodeCoverage, IHaveTestTarge .SetTargetDirectory(CoverageDirectory) .SetReportTypes(ReportTypes.Cobertura) ); - - ( CoverageDirectory / "Cobertura.xml" ).Copy( - CoverageDirectory / "solution.cobertura", - ExistsPolicy.FileOverwriteIfNewer - ); - ( CoverageDirectory / "Cobertura.xml" ).Copy( - CoverageDirectory / "solution.xml", - ExistsPolicy.FileOverwriteIfNewer - ); } ); diff --git a/src/Nuke/TestMethodExtensions.cs b/src/Nuke/TestMethodExtensions.cs index f6948ff8..dff0aae3 100644 --- a/src/Nuke/TestMethodExtensions.cs +++ b/src/Nuke/TestMethodExtensions.cs @@ -9,25 +9,6 @@ namespace Rocket.Surgery.Nuke; /// public static class TestMethodExtensions { - /// - /// Clean up any code coverage files from . - /// - /// - /// - /// - public static ITargetDefinition CleanCoverageDirectory(this ITargetDefinition target, AbsolutePath coverageDirectory) - { - return target.Executes( - () => - { - coverageDirectory - .GlobFiles("*.cobertura.xml", "*.opencover.xml", "*.json", "*.info") - .Where(x => Guid.TryParse(Path.GetFileName(x).Split('.')[0], out _)) - .ForEach(AbsolutePathExtensions.DeleteFile); - } - ); - } - // ReSharper disable once CommentTypo /// /// A method that ensures the given runsettings file exists or creates a default one diff --git a/src/Nuke/ToolSettingsExtensions.cs b/src/Nuke/ToolSettingsExtensions.cs index 3a486a2d..f4610b44 100644 --- a/src/Nuke/ToolSettingsExtensions.cs +++ b/src/Nuke/ToolSettingsExtensions.cs @@ -51,10 +51,17 @@ Func func /// /// public static T SetDefaultLoggers(this T settings, AbsolutePath path, MSBuildVerbosity? verbosity = null) - where T : ToolSettings => - settings - .SetBinaryLogger((AbsolutePath)Path.ChangeExtension(path, "binlog")) - .SetFileLogger((AbsolutePath)Path.ChangeExtension(path, "log"), verbosity); + where T : ToolSettings + { + if (NukeBuild.IsLocalBuild) + { + var existingArgs = settings.ProcessArgumentConfigurator; + settings = settings.SetProcessArgumentConfigurator(args => existingArgs(args).Add("/tl")); + } + return settings + .SetBinaryLogger((AbsolutePath)Path.ChangeExtension(path, "binlog")) + .SetFileLogger((AbsolutePath)Path.ChangeExtension(path, "log"), verbosity); + } /// /// Configures binary logging for MSBuild diff --git a/src/Nuke/Xamarin/ICanTestXamarin.cs b/src/Nuke/Xamarin/ICanTestXamarin.cs index f0c85cd2..116a4f7f 100644 --- a/src/Nuke/Xamarin/ICanTestXamarin.cs +++ b/src/Nuke/Xamarin/ICanTestXamarin.cs @@ -24,7 +24,6 @@ public interface ICanTestXamarin : IHaveTestTarget, .DependsOn(Build) .OnlyWhenStatic(() => TestsDirectory.DirectoryExists()) .CreateOrCleanDirectory(TestResultsDirectory) - .CleanCoverageDirectory(CoverageDirectory) .Net9MsBuildFix() .Executes( () => DotNetTasks.DotNetTest( diff --git a/src/Nuke/default.runsettings b/src/Nuke/default.runsettings index f11ab3ed..5b8f8b84 100644 --- a/src/Nuke/default.runsettings +++ b/src/Nuke/default.runsettings @@ -2,41 +2,10 @@ + uri="datacollector://Microsoft/CodeCoverage/2.0" + assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> - - Cobertura - - - - ^System\.Diagnostics\.DebuggerHiddenAttribute$ - ^System\.Diagnostics\.DebuggerNonUserCodeAttribute$ - ^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$ - ^System\.Runtime\.CompilerServices\.CompilerGeneratedAttribute$ - ^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$ - - - - - ^Bogus\..* - ^Autofac\..* - ^FakeItEasy\..* - ^Moq\..* - ^NSubstitute\..* - ^Verify\..* - ^XUnit\..* - ^TUnit\..* - ^Microsoft\..* - ^System\..* - ^JetBrains\..* - ^DryIoc\..* - ^Nuke\..* - ^FluentAssertions\..* - ^Serilog\..* - - - + Cobertura