diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 465d77d..1084870 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -54,6 +54,7 @@ jobs: 3.1.x 5.0.x 6.0.x + 7.0.x - name: Build Addin uses: cake-build/cake-action@v2 with: diff --git a/Source/Cake.Codecov.Tests/Cake.Codecov.Tests.csproj b/Source/Cake.Codecov.Tests/Cake.Codecov.Tests.csproj index 5ca3aab..7b6bd93 100644 --- a/Source/Cake.Codecov.Tests/Cake.Codecov.Tests.csproj +++ b/Source/Cake.Codecov.Tests/Cake.Codecov.Tests.csproj @@ -1,12 +1,12 @@ - net6.0;net5.0;netcoreapp3.1 + net7.0;net6.0 8.0 false - + runtime; build; native; contentfiles; analyzers all diff --git a/Source/Cake.Codecov.Tests/CodecovRunnerTests.cs b/Source/Cake.Codecov.Tests/CodecovRunnerTests.cs index 8cd7729..44b9249 100644 --- a/Source/Cake.Codecov.Tests/CodecovRunnerTests.cs +++ b/Source/Cake.Codecov.Tests/CodecovRunnerTests.cs @@ -1,5 +1,4 @@ using System; -using System.Runtime.InteropServices; using Cake.Codecov.Internals; using Cake.Codecov.Tests.Attributes; using Cake.Core; diff --git a/Source/Cake.Codecov.Tests/CodecovSettingsTests.cs b/Source/Cake.Codecov.Tests/CodecovSettingsTests.cs index 555165a..66d4bd2 100644 --- a/Source/Cake.Codecov.Tests/CodecovSettingsTests.cs +++ b/Source/Cake.Codecov.Tests/CodecovSettingsTests.cs @@ -56,6 +56,20 @@ public void Should_Set_Build_Value() settings.Build.Should().Be(expected); } + [Fact] + public void Should_Set_Clean_Value() + { + // Given + var settings = new CodecovSettings + { + // When + CleanReports = true + }; + + // Then + settings.CleanReports.Should().BeTrue(); + } + [Fact] public void Should_Set_Commit_Value() { @@ -72,17 +86,17 @@ public void Should_Set_Commit_Value() } [Fact] - public void Should_Set_Clean_Value() + public void Should_Set_DryRun_Value() { // Given var settings = new CodecovSettings { // When - CleanReports = true + DryRun = true }; // Then - settings.CleanReports.Should().BeTrue(); + settings.DryRun.Should().BeTrue(); } [Fact] @@ -174,6 +188,20 @@ public void Should_Set_Name_Value() settings.Name.Should().Be(expected); } + [Fact] + public void Should_Set_NonZero_Value() + { + // Given + var settings = new CodecovSettings + { + // When + NonZero = true + }; + + // Then + settings.NonZero.Should().BeTrue(); + } + [Fact] public void Should_Set_ParentSha_Value() { diff --git a/Source/Cake.Codecov/Cake.Codecov.csproj b/Source/Cake.Codecov/Cake.Codecov.csproj index 23cea35..80880c1 100644 --- a/Source/Cake.Codecov/Cake.Codecov.csproj +++ b/Source/Cake.Codecov/Cake.Codecov.csproj @@ -8,7 +8,7 @@ Cake addin that extends Cake with the ability to use the official Codecov CLI. bin\$(Configuration)\$(TargetFramework)\Cake.Codecov.xml en-GB - net6.0;net5.0;netcoreapp3.1 + net7.0;net6.0 8.0 @@ -35,7 +35,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + diff --git a/appveyor.yml b/appveyor.yml index d2c2de3..4936033 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -11,9 +11,8 @@ skip_commits: - '.travis.yml' install: - - choco install dotnetcore-3.1-sdk -y - - choco install dotnet-5.0-sdk -y - - choco install dotnet-6.0-runtime dotnet-6.0-sdk -y + - choco install dotnetcore-3.1-sdk dotnet-5.0-sdk dotnet-6.0-sdk dotnet-7.0-sdk -y + - choco install dotnet-7.0-runtime -y build: off test: off diff --git a/setup.cake b/setup.cake index 7b25045..4523d1b 100644 --- a/setup.cake +++ b/setup.cake @@ -33,6 +33,78 @@ ToolSettings.SetToolPreprocessorDirectives( gitVersionGlobalTool: "#tool dotnet:?package=GitVersion.Tool&version=5.12.0", gitReleaseManagerGlobalTool: "#tool dotnet:?package=GitReleaseManager.Tool&version=0.17.0"); +// Since Cake.Recipe does not properly detect .NET only test projects, we need +// to override how the tests are running. +((CakeTask)BuildParameters.Tasks.DotNetCoreTestTask.Task).Actions.Clear(); +BuildParameters.Tasks.DotNetCoreTestTask.Does((context, msBuildSettings) => { + + var projects = GetFiles(BuildParameters.TestDirectoryPath + (BuildParameters.TestFilePattern ?? "/**/*Tests.csproj")); + // We create the coverlet settings here so we don't have to create the filters several times + var coverletSettings = new CoverletSettings + { + CollectCoverage = true, + // It is problematic to merge the reports into one, as such we use a custom directory for coverage results + CoverletOutputDirectory = BuildParameters.Paths.Directories.TestCoverage.Combine("coverlet"), + CoverletOutputFormat = CoverletOutputFormat.opencover, + ExcludeByFile = ToolSettings.TestCoverageExcludeByFile.Split(new [] {';' }, StringSplitOptions.None).ToList(), + ExcludeByAttribute = ToolSettings.TestCoverageExcludeByAttribute.Split(new [] {';' }, StringSplitOptions.None).ToList() + }; + + foreach (var filter in ToolSettings.TestCoverageFilter.Split(new [] {' ' }, StringSplitOptions.None)) + { + if (filter[0] == '+') + { + coverletSettings.WithInclusion(filter.TrimStart('+')); + } + else if (filter[0] == '-') + { + coverletSettings.WithFilter(filter.TrimStart('-')); + } + } + var settings = new DotNetCoreTestSettings + { + Configuration = BuildParameters.Configuration, + NoBuild = true + }; + + foreach (var project in projects) + { + Action testAction = tool => + { + tool.DotNetCoreTest(project.FullPath, settings); + }; + + var parsedProject = ParseProject(project, BuildParameters.Configuration); + + var coverletPackage = parsedProject.GetPackage("coverlet.msbuild"); + bool shouldAddSourceLinkArgument = false; // Set it to false by default due to OpenCover + if (coverletPackage != null) + { + // If the version is a pre-release, we will assume that it is a later + // version than what we need, and thus TryParse will return false. + // If TryParse is successful we need to compare the coverlet version + // to ensure it is higher or equal to the version that includes the fix + // for using the SourceLink argument. + // https://github.com/coverlet-coverage/coverlet/issues/882 + Version coverletVersion; + shouldAddSourceLinkArgument = !Version.TryParse(coverletPackage.Version, out coverletVersion) + || coverletVersion >= Version.Parse("2.9.1"); + } + + settings.ArgumentCustomization = args => { + args.AppendMSBuildSettings(msBuildSettings, context.Environment); + if (shouldAddSourceLinkArgument && parsedProject.HasPackage("Microsoft.SourceLink.GitHub")) + { + args.Append("/p:UseSourceLink=true"); + } + return args; + }; + + coverletSettings.CoverletOutputName = parsedProject.RootNameSpace.Replace('.', '-'); + DotNetCoreTest(project.FullPath, settings, coverletSettings); + } +}); + // Tasks we want to override ((CakeTask)BuildParameters.Tasks.UploadCodecovReportTask.Task).Actions.Clear(); BuildParameters.Tasks.UploadCodecovReportTask