Skip to content

Commit

Permalink
Merge pull request #313 from AdmiringWorm/update-cake
Browse files Browse the repository at this point in the history
+semver: major
  • Loading branch information
AdmiringWorm authored May 6, 2024
2 parents 0a17242 + 158dbab commit 3393625
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Source/Cake.Codecov.Tests/Cake.Codecov.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AppVeyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Cake.Testing" Version="2.3.0" />
<PackageReference Include="Cake.Testing" Version="3.2.0" />
<PackageReference Include="coverlet.msbuild" Version="6.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
1 change: 0 additions & 1 deletion Source/Cake.Codecov.Tests/CodecovRunnerTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Runtime.InteropServices;
using Cake.Codecov.Internals;
using Cake.Codecov.Tests.Attributes;
using Cake.Core;
Expand Down
34 changes: 31 additions & 3 deletions Source/Cake.Codecov.Tests/CodecovSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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]
Expand Down Expand Up @@ -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()
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Cake.Codecov/Cake.Codecov.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Description>Cake addin that extends Cake with the ability to use the official Codecov CLI.</Description>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Cake.Codecov.xml</DocumentationFile>
<NeutralLanguage>en-GB</NeutralLanguage>
<TargetFrameworks>net6.0;net5.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net7.0;net6.0</TargetFrameworks>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
<!-- Package information -->
Expand All @@ -35,7 +35,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Cake.Core" Version="2.0.0" PrivateAssets="All" />
<PackageReference Include="Cake.Core" Version="3.0.0" PrivateAssets="All" />
<PackageReference Include="CakeContrib.Guidelines" Version="1.4.0" PrivateAssets="All" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" PrivateAssets="All" />
<PackageReference Include="Roslynator.Analyzers" Version="4.12.2">
Expand Down
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 72 additions & 0 deletions setup.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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<DotNetCoreMSBuildSettings>((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<ICakeContext> 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
Expand Down

0 comments on commit 3393625

Please sign in to comment.