Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
Switch to using dotnet-coverage
Browse files Browse the repository at this point in the history
Now that the merge bug has been fixed, this should provide a better report than `dotnet-reportgenerator-globaltool` because methods with `#if` blocks will now still be merged in the report instead of being listed multiple times.
  • Loading branch information
AArnott committed Sep 13, 2022
1 parent 5d14d2c commit 34f4c9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 10 additions & 5 deletions azure-pipelines/Merge-CodeCoverage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ Param(
[string[]]$Path,
[ValidateSet('Badges', 'Clover', 'Cobertura', 'CsvSummary', 'Html', 'Html_Dark', 'Html_Light', 'HtmlChart', 'HtmlInline', 'HtmlInline_AzurePipelines', 'HtmlInline_AzurePipelines_Dark', 'HtmlInline_AzurePipelines_Light', 'HtmlSummary', 'JsonSummary', 'Latex', 'LatexSummary', 'lcov', 'MarkdownSummary', 'MHtml', 'PngChart', 'SonarQube', 'TeamCitySummary', 'TextSummary', 'Xml', 'XmlSummary')]
[string]$Format='Cobertura',
[string]$OutputDir=("$PSScriptRoot/../coveragereport")
[string]$OutputFile=("$PSScriptRoot/../coveragereport/merged.cobertura.xml")
)

$RepoRoot = [string](Resolve-Path $PSScriptRoot/..)

if (!(Test-Path $RepoRoot/obj/reportgenerator*)) {
dotnet tool install --tool-path $RepoRoot/obj dotnet-reportgenerator-globaltool --version 5.1.9 --configfile $PSScriptRoot/justnugetorg.nuget.config
if (!(Test-Path $RepoRoot/obj/dotnet-coverage*)) {
dotnet tool install --tool-path $RepoRoot/obj dotnet-coverage --version 17.4.3 --configfile $PSScriptRoot/justnugetorg.nuget.config
}

Write-Verbose "Searching $Path for *.cobertura.xml files"
Expand All @@ -39,8 +39,13 @@ if ($reports) {
$xml.Save($_)
}

$Inputs = [string]::join(';', ($reports |% { Resolve-Path -relative $_.FullName }))
& "$RepoRoot/obj/reportgenerator" -reports:"$Inputs" -targetdir:$OutputDir -reporttypes:$Format
$Inputs = $reports |% { Resolve-Path -relative $_.FullName }

if (Split-Path $OutputFile) {
New-Item -Type Directory -Path (Split-Path $OutputFile) | Out-Null
}

& "$RepoRoot/obj/dotnet-coverage" merge $Inputs -o $OutputFile -f cobertura
} else {
Write-Error "No reports found to merge."
}
4 changes: 2 additions & 2 deletions azure-pipelines/publish-codecoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ steps:
displayName: 🔻 Download macOS code coverage results
continueOnError: true
condition: and(succeeded(), ${{ parameters.includeMacOS }})
- powershell: azure-pipelines/Merge-CodeCoverage.ps1 -Path '$(Pipeline.Workspace)' -OutputDir coveragereport -Format Cobertura -Verbose
- powershell: azure-pipelines/Merge-CodeCoverage.ps1 -Path '$(Pipeline.Workspace)' -OutputFile coveragereport/merged.cobertura.xml -Format Cobertura -Verbose
displayName: ⚙ Merge coverage
- task: PublishCodeCoverageResults@1
displayName: 📢 Publish code coverage results to Azure DevOps
inputs:
codeCoverageTool: cobertura
summaryFileLocation: coveragereport/Cobertura.xml
summaryFileLocation: coveragereport/merged.cobertura.xml
failIfCoverageEmpty: true

0 comments on commit 34f4c9f

Please sign in to comment.