From e98598742fc85ba2f528c9b11abc0c811e5e0280 Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Tue, 14 Jun 2022 22:44:08 -0700 Subject: [PATCH 1/9] OS flags --- azure-pipelines/publish-CodeCov.ps1 | 74 +++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index a115b52..4be9d2a 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -7,6 +7,8 @@ Path to root of code coverage files .PARAMETER Name Optional name to upload with codecoverge +.PARAMETER CalcNSFlags + Optional switch to calculate Flags from namespace of test. .PARAMETER Flags Optional flags to upload with codecoverge #> @@ -15,6 +17,7 @@ Param ( [string]$CodeCovToken, [string]$PathToCodeCoverage, [string]$Name="", + [switch]$CalcNSFlags = true, [string]$Flags="" ) @@ -37,5 +40,76 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { Write-Host "Uploading: $relativeFilePath" -ForegroundColor Yellow + if ($CalcNSFlags) + { + $TestTypeFlag = "UnknownTest" + + if ($relativeFilePath -ilike ".Unit") + { + $TestTypeFlag = "Unit" + } + elseif ($relativeFilePath -ilike ".Integration") + { + $TestTypeFlag = "Integration" + } + elseif ($relativeFilePath -ilike ".Local") + { + $TestTypeFlag = "Local" + } + elseif ($relativeFilePath -ilike ".Device") + { + $TestTypeFlag = "Device" + } + + $OSTypeFlag = "UnknownOS" + + if ($relativeFilePath -ilike ".Windows") + { + $OSTypeFlag = "Windows" + } + elseif ($relativeFilePath -ilike ".WinUI") + { + $OSTypeFlag = "WinUI" + } + elseif ($relativeFilePath -ilike ".WPF") + { + $OSTypeFlag = "WPF" + } + elseif ($relativeFilePath -ilike ".MacOS") + { + $OSTypeFlag = "MacOS" + } + elseif ($relativeFilePath -ilike ".MacCatalyst") + { + $OSTypeFlag = "MacCatalyst" + } + elseif ($relativeFilePath -ilike ".OSX") + { + $OSTypeFlag = "MacOS" + } + elseif ($relativeFilePath -ilike ".Android") + { + $OSTypeFlag = "Android" + } + elseif ($relativeFilePath -ilike ".IOS") + { + $OSTypeFlag = "IOS" + } + elseif ($relativeFilePath -ilike ".Linux") + { + $OSTypeFlag = "Linux" + } + elseif ($relativeFilePath -ilike ".NetCore") + { + $OSTypeFlag = "NetCore" + } + elseif ($relativeFilePath -ilike ".Core") + { + $OSTypeFlag = "Core" + } + + $Flags = ($Flags, $TestTypeFlag, $OSTypeFlag -join ',') + } + & (& "$PSScriptRoot/Get-CodeCovTool.ps1") -t "$CodeCovToken" -f "$relativeFilePath" -R "$RepoRoot" -F "$Flags" -n "$Name" } From e70cd42b029b5364d100d90a415e9a6654ae5d03 Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Tue, 14 Jun 2022 22:48:15 -0700 Subject: [PATCH 2/9] Update publish-CodeCov.ps1 --- azure-pipelines/publish-CodeCov.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index 4be9d2a..b8d5348 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -17,7 +17,7 @@ Param ( [string]$CodeCovToken, [string]$PathToCodeCoverage, [string]$Name="", - [switch]$CalcNSFlags = true, + [switch]$CalcNSFlags, [string]$Flags="" ) @@ -40,6 +40,8 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { Write-Host "Uploading: $relativeFilePath" -ForegroundColor Yellow + $CalcNSFlags = true + if ($CalcNSFlags) { $TestTypeFlag = "UnknownTest" From cf53d300ba01feb1fa71b4f2b5fa9d72fc0b8d49 Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Tue, 14 Jun 2022 22:54:32 -0700 Subject: [PATCH 3/9] Output flags --- azure-pipelines/publish-CodeCov.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index b8d5348..356a8e5 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -113,5 +113,7 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { $Flags = ($Flags, $TestTypeFlag, $OSTypeFlag -join ',') } + Write-Host "Flags: $Flags" -ForegroundColor Yellow + & (& "$PSScriptRoot/Get-CodeCovTool.ps1") -t "$CodeCovToken" -f "$relativeFilePath" -R "$RepoRoot" -F "$Flags" -n "$Name" } From fcacd89fe00d30161cb9fd50052dfc3ffc8f47cc Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Tue, 14 Jun 2022 22:58:21 -0700 Subject: [PATCH 4/9] Update publish-CodeCov.ps1 --- azure-pipelines/publish-CodeCov.ps1 | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index 356a8e5..6ad4c38 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -40,9 +40,7 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { Write-Host "Uploading: $relativeFilePath" -ForegroundColor Yellow - $CalcNSFlags = true - - if ($CalcNSFlags) + if (true) { $TestTypeFlag = "UnknownTest" From 9528f3f988a669256cc7ead3ccda9481bf7fc09e Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Tue, 14 Jun 2022 23:07:58 -0700 Subject: [PATCH 5/9] Fix NS calculation --- azure-pipelines/publish-CodeCov.ps1 | 46 ++++++++++++++++++----------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index 6ad4c38..5b3f302 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -42,73 +42,83 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { if (true) { - $TestTypeFlag = "UnknownTest" + $TestTypeFlag = "" if ($relativeFilePath -ilike ".Unit") { - $TestTypeFlag = "Unit" + $TestTypeFlag = ",Unit" } elseif ($relativeFilePath -ilike ".Integration") { - $TestTypeFlag = "Integration" + $TestTypeFlag = ",Integration" } elseif ($relativeFilePath -ilike ".Local") { - $TestTypeFlag = "Local" + $TestTypeFlag = ",Local" } elseif ($relativeFilePath -ilike ".Device") { - $TestTypeFlag = "Device" + $TestTypeFlag = ",Device" } + else + { + $TestTypeFlag = ",UnknownTest" + } + - $OSTypeFlag = "UnknownOS" + $OSTypeFlag = "" if ($relativeFilePath -ilike ".Windows") { - $OSTypeFlag = "Windows" + $OSTypeFlag = ",Windows" } elseif ($relativeFilePath -ilike ".WinUI") { - $OSTypeFlag = "WinUI" + $OSTypeFlag = ",WinUI" } elseif ($relativeFilePath -ilike ".WPF") { - $OSTypeFlag = "WPF" + $OSTypeFlag = ",WPF" } elseif ($relativeFilePath -ilike ".MacOS") { - $OSTypeFlag = "MacOS" + $OSTypeFlag = ",MacOS" } elseif ($relativeFilePath -ilike ".MacCatalyst") { - $OSTypeFlag = "MacCatalyst" + $OSTypeFlag = ",MacCatalyst" } elseif ($relativeFilePath -ilike ".OSX") { - $OSTypeFlag = "MacOS" + $OSTypeFlag = ",MacOS" } elseif ($relativeFilePath -ilike ".Android") { - $OSTypeFlag = "Android" + $OSTypeFlag = ",Android" } elseif ($relativeFilePath -ilike ".IOS") { - $OSTypeFlag = "IOS" + $OSTypeFlag = ",IOS" } elseif ($relativeFilePath -ilike ".Linux") { - $OSTypeFlag = "Linux" + $OSTypeFlag = ",Linux" } elseif ($relativeFilePath -ilike ".NetCore") { - $OSTypeFlag = "NetCore" + $OSTypeFlag = ",NetCore" } elseif ($relativeFilePath -ilike ".Core") { - $OSTypeFlag = "Core" + $OSTypeFlag = ",Core" + } + else + { + $TestTypeFlag = ",UnknownOS" } - $Flags = ($Flags, $TestTypeFlag, $OSTypeFlag -join ',') + $Flags += $TestTypeFlag + $Flags += $OSTypeFlag } Write-Host "Flags: $Flags" -ForegroundColor Yellow From 04e942716b3318238314921463bcf36ffc91347e Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Tue, 14 Jun 2022 23:13:29 -0700 Subject: [PATCH 6/9] -CalcNSFlags flag --- .github/workflows/build.yml | 2 +- azure-pipelines/dotnet.yml | 2 +- azure-pipelines/publish-CodeCov.ps1 | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7bf8638..329cebc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -109,7 +109,7 @@ jobs: path: ${{ runner.temp }}/_artifacts/deployables if: always() - name: Publish code coverage results to codecov.io - run: ./azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "${{ env.codecov_token }}" -PathToCodeCoverage "${{ runner.temp }}/_artifacts/coverageResults" -Name "${{ runner.os }} Coverage Results" -Flags "${{ runner.os }},${{ env.BUILDCONFIGURATION }}" + run: ./azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "${{ env.codecov_token }}" -PathToCodeCoverage "${{ runner.temp }}/_artifacts/coverageResults" -Name "${{ runner.os }} Coverage Results" -Flags "${{ runner.os }},${{ env.BUILDCONFIGURATION }}" -CalcNSFlags shell: pwsh timeout-minutes: 3 continue-on-error: true diff --git a/azure-pipelines/dotnet.yml b/azure-pipelines/dotnet.yml index 38c09e6..1b30282 100644 --- a/azure-pipelines/dotnet.yml +++ b/azure-pipelines/dotnet.yml @@ -19,7 +19,7 @@ steps: - powershell: | $ArtifactStagingFolder = & "azure-pipelines/Get-ArtifactsStagingDirectory.ps1" $CoverageResultsFolder = Join-Path $ArtifactStagingFolder "coverageResults-$(Agent.JobName)" - azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "$(codecov_token)" -PathToCodeCoverage "$CoverageResultsFolder" -Name "$(Agent.JobName) Coverage Results" -Flags "$(Agent.JobName),$(BuildConfiguration)" + azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "$(codecov_token)" -PathToCodeCoverage "$CoverageResultsFolder" -Name "$(Agent.JobName) Coverage Results" -Flags "$(Agent.JobName),$(BuildConfiguration)" -CalcNSFlags displayName: 📢 Publish code coverage results to codecov.io condition: ne(variables['codecov_token'], '') timeoutInMinutes: 3 diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index 5b3f302..35d8f1e 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -40,7 +40,7 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { Write-Host "Uploading: $relativeFilePath" -ForegroundColor Yellow - if (true) + if ($CalcNSFlags) { $TestTypeFlag = "" @@ -64,7 +64,6 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { { $TestTypeFlag = ",UnknownTest" } - $OSTypeFlag = "" From d2480e582741ecfcd11b3e6e43cfeb9467264de4 Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Tue, 14 Jun 2022 23:19:25 -0700 Subject: [PATCH 7/9] Fixed up tags --- .github/workflows/build.yml | 2 +- azure-pipelines/dotnet.yml | 2 +- azure-pipelines/publish-CodeCov.ps1 | 8 -------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 329cebc..015a685 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -109,7 +109,7 @@ jobs: path: ${{ runner.temp }}/_artifacts/deployables if: always() - name: Publish code coverage results to codecov.io - run: ./azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "${{ env.codecov_token }}" -PathToCodeCoverage "${{ runner.temp }}/_artifacts/coverageResults" -Name "${{ runner.os }} Coverage Results" -Flags "${{ runner.os }},${{ env.BUILDCONFIGURATION }}" -CalcNSFlags + run: ./azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "${{ env.codecov_token }}" -PathToCodeCoverage "${{ runner.temp }}/_artifacts/coverageResults" -Name "${{ runner.os }} Coverage Results" -Flags "${{ runner.os }}Host,${{ env.BUILDCONFIGURATION }}" -CalcNSFlags shell: pwsh timeout-minutes: 3 continue-on-error: true diff --git a/azure-pipelines/dotnet.yml b/azure-pipelines/dotnet.yml index 1b30282..abdea3c 100644 --- a/azure-pipelines/dotnet.yml +++ b/azure-pipelines/dotnet.yml @@ -19,7 +19,7 @@ steps: - powershell: | $ArtifactStagingFolder = & "azure-pipelines/Get-ArtifactsStagingDirectory.ps1" $CoverageResultsFolder = Join-Path $ArtifactStagingFolder "coverageResults-$(Agent.JobName)" - azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "$(codecov_token)" -PathToCodeCoverage "$CoverageResultsFolder" -Name "$(Agent.JobName) Coverage Results" -Flags "$(Agent.JobName),$(BuildConfiguration)" -CalcNSFlags + azure-pipelines/publish-CodeCov.ps1 -CodeCovToken "$(codecov_token)" -PathToCodeCoverage "$CoverageResultsFolder" -Name "$(Agent.JobName) Coverage Results" -Flags "$(Agent.JobName)Host,$(BuildConfiguration)" -CalcNSFlags displayName: 📢 Publish code coverage results to codecov.io condition: ne(variables['codecov_token'], '') timeoutInMinutes: 3 diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index 35d8f1e..2036ecf 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -60,10 +60,6 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { { $TestTypeFlag = ",Device" } - else - { - $TestTypeFlag = ",UnknownTest" - } $OSTypeFlag = "" @@ -111,10 +107,6 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { { $OSTypeFlag = ",Core" } - else - { - $TestTypeFlag = ",UnknownOS" - } $Flags += $TestTypeFlag $Flags += $OSTypeFlag From af462228b371635c0be2a305d5ed937ce1ccf57e Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Thu, 16 Jun 2022 06:58:42 -0700 Subject: [PATCH 8/9] CodeCoverage updates. 3.01 DotNet --- azure-pipelines/publish-CodeCov.ps1 | 44 +++++++++++++---------------- global.json | 2 +- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/azure-pipelines/publish-CodeCov.ps1 b/azure-pipelines/publish-CodeCov.ps1 index 2036ecf..1f71276 100644 --- a/azure-pipelines/publish-CodeCov.ps1 +++ b/azure-pipelines/publish-CodeCov.ps1 @@ -39,80 +39,76 @@ Get-ChildItem -Recurse -Path $CodeCoveragePathWildcard | % { } Write-Host "Uploading: $relativeFilePath" -ForegroundColor Yellow + $TestTypeFlag = "" + $OSTypeFlag = "" + $FTargetFrameworkFlag = "" if ($CalcNSFlags) { - $TestTypeFlag = "" - - if ($relativeFilePath -ilike ".Unit") + if ($relativeFilePath -ilike "*.Unit*") { $TestTypeFlag = ",Unit" } - elseif ($relativeFilePath -ilike ".Integration") + elseif ($relativeFilePath -ilike "*.Integration*") { $TestTypeFlag = ",Integration" } - elseif ($relativeFilePath -ilike ".Local") + elseif ($relativeFilePath -ilike "*.Local*") { $TestTypeFlag = ",Local" } - elseif ($relativeFilePath -ilike ".Device") + elseif ($relativeFilePath -ilike "*.Device*") { $TestTypeFlag = ",Device" } - $OSTypeFlag = "" - - if ($relativeFilePath -ilike ".Windows") + if ($relativeFilePath -ilike "*.Windows*") { $OSTypeFlag = ",Windows" } - elseif ($relativeFilePath -ilike ".WinUI") + elseif ($relativeFilePath -ilike "*.WinUI*") { $OSTypeFlag = ",WinUI" } - elseif ($relativeFilePath -ilike ".WPF") + elseif ($relativeFilePath -ilike "*.WPF*") { $OSTypeFlag = ",WPF" } - elseif ($relativeFilePath -ilike ".MacOS") + elseif ($relativeFilePath -ilike "*.MacOS*") { $OSTypeFlag = ",MacOS" } - elseif ($relativeFilePath -ilike ".MacCatalyst") + elseif ($relativeFilePath -ilike "*.MacCatalyst*") { $OSTypeFlag = ",MacCatalyst" } - elseif ($relativeFilePath -ilike ".OSX") + elseif ($relativeFilePath -ilike "*.OSX*") { $OSTypeFlag = ",MacOS" } - elseif ($relativeFilePath -ilike ".Android") + elseif ($relativeFilePath -ilike "*.Android*") { $OSTypeFlag = ",Android" } - elseif ($relativeFilePath -ilike ".IOS") + elseif ($relativeFilePath -ilike "*.IOS*") { $OSTypeFlag = ",IOS" } - elseif ($relativeFilePath -ilike ".Linux") + elseif ($relativeFilePath -ilike "*.Linux*") { $OSTypeFlag = ",Linux" } - elseif ($relativeFilePath -ilike ".NetCore") + elseif ($relativeFilePath -ilike "*.NetCore*") { $OSTypeFlag = ",NetCore" } - elseif ($relativeFilePath -ilike ".Core") + elseif ($relativeFilePath -ilike "*.Core*") { $OSTypeFlag = ",Core" } - - $Flags += $TestTypeFlag - $Flags += $OSTypeFlag } - Write-Host "Flags: $Flags" -ForegroundColor Yellow + Write-Host "Flags: $Flags$TargetFrameworkFlag$TestTypeFlag$OSTypeFlag" -ForegroundColor Yellow - & (& "$PSScriptRoot/Get-CodeCovTool.ps1") -t "$CodeCovToken" -f "$relativeFilePath" -R "$RepoRoot" -F "$Flags" -n "$Name" + & (& "$PSScriptRoot/Get-CodeCovTool.ps1") -t "$CodeCovToken" -f "$relativeFilePath" -R "$RepoRoot" -F "$Flags$TargetFrameworkFlag$TestTypeFlag$OSTypeFlag" -n "$Name" } diff --git a/global.json b/global.json index f4e12c1..6024922 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0.300", + "version": "6.0.301", "allowPrerelease": true, "rollForward": "patch" } From 3a494ca7177c95e9ef92cc652e0b35da5ee85d2e Mon Sep 17 00:00:00 2001 From: Steve Bush Date: Fri, 17 Jun 2022 07:26:59 -0700 Subject: [PATCH 9/9] Updates from Library.Template --- .gitignore | 1 + azure-pipelines/Merge-CodeCoverage.ps1 | 42 ++++++++++++++++++++++++ azure-pipelines/publish-codecoverage.yml | 14 +------- 3 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 azure-pipelines/Merge-CodeCoverage.ps1 diff --git a/.gitignore b/.gitignore index 65f9477..3bb4991 100644 --- a/.gitignore +++ b/.gitignore @@ -140,6 +140,7 @@ _TeamCity* # Visual Studio code coverage results *.coverage *.coveragexml +/coveragereport/ # NCrunch _NCrunch_* diff --git a/azure-pipelines/Merge-CodeCoverage.ps1 b/azure-pipelines/Merge-CodeCoverage.ps1 new file mode 100644 index 0000000..6672b94 --- /dev/null +++ b/azure-pipelines/Merge-CodeCoverage.ps1 @@ -0,0 +1,42 @@ +#!/usr/bin/env pwsh + +<# +.SYNOPSIS + Merges code coverage reports. +.PARAMETER Path + The path(s) to search for Cobertura code coverage reports. +.PARAMETER Format + The format for the merged result. The default is Cobertura +.PARAMETER OutputDir + The directory the merged result will be written to. The default is `coveragereport` in the root of this repo. +#> +[CmdletBinding()] +Param( + [Parameter(Mandatory=$true)] + [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") +) + +$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 +} + +Write-Verbose "Searching $Path for *.cobertura.xml files" +$reports = Get-ChildItem -Recurse $Path -Filter *.cobertura.xml + +if ($reports) { + $reports |% { $_.FullName } |% { + # In addition to replacing {reporoot}, we also normalize on one kind of slash so that the report aggregates data for a file whether data was collected on Windows or not. + $content = Get-Content -Path $_ |% { [Regex]::Replace($_, '{reporoot}([^"]+)', { $RepoRoot + $args[0].groups[1].value.replace([IO.Path]::AltDirectorySeparatorChar, [IO.Path]::DirectorySeparatorChar) }) } + Set-Content -Path $_ -Value $content -Encoding UTF8 + } + + $Inputs = [string]::join(';', ($reports |% { Resolve-Path -relative $_.FullName })) + & "$RepoRoot/obj/reportgenerator" -reports:"$Inputs" -targetdir:$OutputDir -reporttypes:$Format +} else { + Write-Error "No reports found to merge." +} diff --git a/azure-pipelines/publish-codecoverage.yml b/azure-pipelines/publish-codecoverage.yml index 23e88a6..6e7ef21 100644 --- a/azure-pipelines/publish-codecoverage.yml +++ b/azure-pipelines/publish-codecoverage.yml @@ -15,19 +15,7 @@ steps: displayName: 🔻 Download macOS code coverage results continueOnError: true condition: ${{ parameters.includeMacOS }} -- powershell: | - dotnet tool install --tool-path obj dotnet-reportgenerator-globaltool --version 5.1.9 --configfile azure-pipelines/justnugetorg.nuget.config - Copy-Item -Recurse $(Pipeline.Workspace)/coverageResults-Windows/obj/* $(System.DefaultWorkingDirectory)/obj - Write-Host 'Substituting {reporoot} with $(System.DefaultWorkingDirectory)' - $reports = Get-ChildItem -Recurse '$(Pipeline.Workspace)/*.cobertura.xml' - $reports |% { - # In addition to replacing {reporoot}, we also normalize on one kind of slash so that the report aggregates data for a file whether data was collected on Windows or not. - $content = Get-Content -Path $_ |% { [Regex]::Replace($_, '{reporoot}([^"]+)', { '$(System.DefaultWorkingDirectory)' + $args[0].groups[1].value.replace([IO.Path]::AltDirectorySeparatorChar, [IO.Path]::DirectorySeparatorChar) }) } - Set-Content -Path $_ -Value $content -Encoding UTF8 - } - - $Inputs = [string]::join(';', ($reports |% { Resolve-Path -relative $_ })) - obj/reportgenerator -reports:"$Inputs" -targetdir:coveragereport -reporttypes:Cobertura +- powershell: azure-pipelines/Merge-CodeCoverage.ps1 -Path '$(Pipeline.Workspace)' -OutputDir coveragereport -Format Cobertura -Verbose displayName: ⚙ Merge coverage - task: PublishCodeCoverageResults@1 displayName: 📢 Publish code coverage results to Azure DevOps