Skip to content

Commit

Permalink
Fix merging of coverage using MS CC (#4194)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evangelink authored Nov 28, 2024
1 parent d5876b6 commit a99c3c5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-coverage": {
"version": "17.12.6",
"commands": [
"dotnet-coverage"
],
"rollForward": false
}
}
}
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
<PackageVersion Include="NuGet.Packaging" Version="6.12.1" />
<PackageVersion Include="Polly" Version="8.4.2" />
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageVersion Include="ReportGenerator" Version="4.3.6" />
<PackageVersion Include="StreamJsonRpc" Version="2.20.20" />
<PackageVersion Include="StrongNamer" Version="0.2.5" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
Expand Down
33 changes: 22 additions & 11 deletions eng/CodeCoverage.proj
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,56 @@

<ItemGroup>
<PackageReference Include="Codecov" Version="$(CodecovVersion)" GeneratePathProperty="true" />
<PackageReference Include="ReportGenerator" Version="$(ReportGeneratorVersion)" GeneratePathProperty="true" />
</ItemGroup>

<Target Name="GatherCoverageInputs">
<PropertyGroup>
<_CodecovPath>$(PkgCodecov)\tools\Codecov.exe</_CodecovPath>
<_ReportGeneratorPath>$(PkgReportGenerator)\tools\net47\ReportGenerator.exe</_ReportGeneratorPath>
<_LocalDotNetPath>$(DotNetRoot)\dotnet.exe</_LocalDotNetPath>
<MergedFullCoverageDirectory>$(ArtifactsCoverageDir)full\</MergedFullCoverageDirectory>
<MergedUnitCoverageDirectory>$(ArtifactsCoverageDir)unit\</MergedUnitCoverageDirectory>
<MergedIntegrationCoverageDirectory>$(ArtifactsCoverageDir)integration\</MergedIntegrationCoverageDirectory>
<CoberturaFileName>Cobertura.xml</CoberturaFileName>
</PropertyGroup>

<ItemGroup>
<_CoverageReports Include="$(ArtifactsTestResultsDir)\*.coverage" />
<_CoverageReports Include="@(_CoverageReports->'&quot;%(Identity)&quot;', ' ')" />
<_UnitCoverageReports Include="@(_CoverageReports)" Condition="$([System.String]::Copy('%(Identity)').Contains('.UnitTests_'))" />
<_UnitCoverageReports Include="@(_UnitCoverageReports->'&quot;%(Identity)&quot;', ' ')" />
<_IntegrationCoverageReports Include="@(_CoverageReports)" Condition="$([System.String]::Copy('%(Identity)').Contains('.IntegrationTests_'))" />
<_IntegrationCoverageReports Include="@(_IntegrationCoverageReports->'&quot;%(Identity)&quot;', ' ')" />
</ItemGroup>
</Target>

<Target Name="MergeCoverage" DependsOnTargets="GatherCoverageInputs">
<!-- coverage tool doesn't create output directories if they don't exist -->
<MakeDir Directories="$(MergedFullCoverageDirectory)" Condition="!Exists('$(MergedFullCoverageDirectory)')" />
<MakeDir Directories="$(MergedUnitCoverageDirectory)" Condition="!Exists('$(MergedUnitCoverageDirectory)')" />
<MakeDir Directories="$(MergedIntegrationCoverageDirectory)" Condition="!Exists('$(MergedIntegrationCoverageDirectory)')" />

<!-- Merge multiple coverlet reports into a single Cobertura report before uploading to codecov.io, in order to
reduce upload size and load on the codecov.io processing servers. -->
<Message Importance="high" Text="&quot;$(_ReportGeneratorPath)&quot; &quot;-reports:@(_CoverageReports)&quot; -targetdir:$(ArtifactsCoverageDir)full -reporttypes:Cobertura -filefilters:-*.g.cs" />
<Exec Condition="'@(_CoverageReports)' != ''" Command="&quot;$(_ReportGeneratorPath)&quot; &quot;-reports:@(_CoverageReports)&quot; -targetdir:$(ArtifactsCoverageDir)/full -reporttypes:Cobertura -filefilters:-*.g.cs" />
<Message Importance="high" Text="&quot;$(_LocalDotNetPath)&quot; coverage merge @(_CoverageReports) --output &quot;$(MergedFullCoverageDirectory)$(CoberturaFileName)&quot; --output-format Cobertura" />
<Exec Condition="'@(_CoverageReports)' != ''" Command="&quot;$(_LocalDotNetPath)&quot; coverage merge @(_CoverageReports) --output &quot;$(MergedFullCoverageDirectory)$(CoberturaFileName)&quot; --output-format Cobertura" ConsoleToMsBuild="true" />

<!-- Merge multiple coverlet reports into a single Cobertura report before uploading to codecov.io, in order to
reduce upload size and load on the codecov.io processing servers. -->
<Message Importance="high" Text="&quot;$(_ReportGeneratorPath)&quot; &quot;-reports:@(_UnitCoverageReports)&quot; -targetdir:$(ArtifactsCoverageDir)unit -reporttypes:Cobertura -filefilters:-*.g.cs" />
<Exec Condition="'@(_UnitCoverageReports)' != ''" Command="&quot;$(_ReportGeneratorPath)&quot; &quot;-reports:@(_UnitCoverageReports)&quot; -targetdir:$(ArtifactsCoverageDir)/unit -reporttypes:Cobertura -filefilters:-*.g.cs" />
<Message Importance="high" Text="&quot;$(_LocalDotNetPath)&quot; coverage merge @(_UnitCoverageReports) --output &quot;$(MergedUnitCoverageDirectory)$(CoberturaFileName)&quot; --output-format Cobertura" />
<Exec Condition="'@(_UnitCoverageReports)' != ''" Command="&quot;$(_LocalDotNetPath)&quot; coverage merge @(_UnitCoverageReports) --output &quot;$(MergedUnitCoverageDirectory)$(CoberturaFileName)&quot; --output-format Cobertura" ConsoleToMsBuild="true" />

<!-- Merge multiple coverlet reports into a single Cobertura report before uploading to codecov.io, in order to
reduce upload size and load on the codecov.io processing servers. -->
<Message Importance="high" Text="&quot;$(_ReportGeneratorPath)&quot; &quot;-reports:@(_IntegrationCoverageReports)&quot; -targetdir:$(ArtifactsCoverageDir)integration -reporttypes:Cobertura -filefilters:-*.g.cs" />
<Exec Condition="'@(_IntegrationCoverageReports)' != ''" Command="&quot;$(_ReportGeneratorPath)&quot; &quot;-reports:@(_IntegrationCoverageReports)&quot; -targetdir:$(ArtifactsCoverageDir)/integration -reporttypes:Cobertura -filefilters:-*.g.cs" />
<Message Importance="high" Text="&quot;$(_LocalDotNetPath)&quot; coverage merge @(_IntegrationCoverageReports) --output &quot;$(MergedIntegrationCoverageDirectory)$(CoberturaFileName)&quot; --output-format Cobertura" />
<Exec Condition="'@(_IntegrationCoverageReports)' != ''" Command="&quot;$(_LocalDotNetPath)&quot; coverage merge @(_IntegrationCoverageReports) --output &quot;$(MergedIntegrationCoverageDirectory)$(CoberturaFileName)&quot; --output-format Cobertura" ConsoleToMsBuild="true" />
</Target>

<Target Name="Codecov" DependsOnTargets="MergeCoverage">

<ItemGroup>
<_CodecovFullArgs Include="-f;$(ArtifactsCoverageDir)full\Cobertura.xml" />
<_CodecovUnitArgs Include="-f;$(ArtifactsCoverageDir)unit\Cobertura.xml" />
<_CodecovIntegrationArgs Include="-f;$(ArtifactsCoverageDir)integration\Cobertura.xml" />
<_CodecovFullArgs Include="-f;$(MergedFullCoverageDirectory)$(CoberturaFileName)" />
<_CodecovUnitArgs Include="-f;$(MergedUnitCoverageDirectory)$(CoberturaFileName)" />
<_CodecovIntegrationArgs Include="-f;$(MergedIntegrationCoverageDirectory)$(CoberturaFileName)" />

<!-- Report an error if the upload fails -->
<_CodecovArgs Include="--required" />
Expand Down

0 comments on commit a99c3c5

Please sign in to comment.