|
| 1 | +& (Join-Path -Path $PSScriptRoot -ChildPath "AnalyzeTestCoverage.ps1") |
| 2 | + |
| 3 | +$cvgRootDir = (Get-AzConfig -TestCoverageLocation).Value |
| 4 | +$cvgResultsDir = Join-Path -Path $cvgRootDir -ChildPath "TestCoverageAnalysis" | Join-Path -ChildPath "Results" |
| 5 | +$rptCsv = Join-Path -Path $cvgResultsDir -ChildPath "Report.csv" |
| 6 | +if (!(Test-Path -Path $rptCsv -PathType Leaf)) { |
| 7 | + Write-Warning "No test coverage analysis result was found!" |
| 8 | + return |
| 9 | +} |
| 10 | + |
| 11 | +$blCsv = Join-Path -Path $PSScriptRoot -ChildPath "Baseline.csv" |
| 12 | +if (!(Test-Path -Path $blCsv -PathType Leaf)) { |
| 13 | + Write-Warning "No test coverage baseline was found!" |
| 14 | + return |
| 15 | +} |
| 16 | + |
| 17 | +$repoRootDir = $PSScriptRoot | Split-Path | Split-Path | Split-Path |
| 18 | +$cipJson = Join-Path -Path $repoRootDir -ChildPath "artifacts" | Join-Path -ChildPath "PipelineResult" | Join-Path -ChildPath "CIPlan.json" |
| 19 | +if (!(Test-Path -Path $cipJson -PathType Leaf)) { |
| 20 | + Write-Warning "No CI plan was found!" |
| 21 | + return |
| 22 | +} |
| 23 | + |
| 24 | +$cipJson = Get-Content -Path $cipJson -Raw | ConvertFrom-Json |
| 25 | +$testedModules = $cipJson.test | Where-Object { $_ -ne "Accounts" } |
| 26 | + |
| 27 | +$toolsDir = $PSScriptRoot | Split-Path | Split-Path |
| 28 | +$funcTestStatus = Join-Path -Path $toolsDir -ChildPath "ExecuteCIStep.ps1" |
| 29 | +. $funcTestStatus |
| 30 | + |
| 31 | +$rptData = Import-Csv -Path $rptCsv |
| 32 | +$blData = Import-Csv -Path $blCsv |
| 33 | + |
| 34 | +$cvgMessageHeader50 = "|Type|Title|Current Coverage|Description|`n|---|---|---|---|`n" |
| 35 | +$cvgMessageHeader80 = "|Type|Title|Current Coverage|Last Coverage|Description|`n|---|---|---|---|---|`n" |
| 36 | + |
| 37 | +$rptData | Where-Object Module -in $testedModules | ForEach-Object { |
| 38 | + $module = $_.Module |
| 39 | + Write-Host "##[section]Validating test coverage for module $module..." |
| 40 | + |
| 41 | + $cmdCvg = $_.CommandCoverage |
| 42 | + $cmdCvgD = [decimal]$cmdCvg.TrimEnd("%") / 100 |
| 43 | + |
| 44 | + Write-Host "Test coverage for module $module is $cmdCvg." |
| 45 | + if ($cmdCvgD -lt 0.5) { |
| 46 | + Write-Warning "Test coverage for module $module is less than 50% !" |
| 47 | + $cvgMessageBody50 = "|⚠️|Test Coverage Less Than 50%|$cmdCvg|Test coverage for the module cannot be lower than 50%.|`n" |
| 48 | + Set-ModuleTestStatusInPipelineResult -ModuleName "Az.$module" -Status Warning -Content ($cvgMessageHeader50 + $cvgMessageBody50) |
| 49 | + } |
| 50 | + elseif ($cmdCvgD -lt 0.8) { |
| 51 | + $blCvgRow = $blData | Where-Object Module -eq $module |
| 52 | + $blCvg = $blCvgRow.CommandCoverage |
| 53 | + $blCvgD = [decimal]$blCvg.TrimEnd("%") / 100 |
| 54 | + Write-Host "Last release test coverage for module $module is $blCvg." |
| 55 | + if ($cmdCvgD -lt $blCvgD) { |
| 56 | + Write-Warning "Test coverage for module $module is less than 80% and lower than the last release !" |
| 57 | + $cvgMessageBody80 = "|⚠️|Test Coverage Less Than 80%|$cmdCvg|$blCvg|Test coverage cannot be lower than the number of the last release.|`n" |
| 58 | + Set-ModuleTestStatusInPipelineResult -ModuleName "Az.$module" -Status Warning -Content ($cvgMessageHeader80 + $cvgMessageBody80) |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + Write-Host |
| 63 | +} |
0 commit comments