Skip to content

Commit ca07e18

Browse files
vidai-msftCopilot
andauthored
Improve test coverage and add condition for getting GitHub PAT (#28226)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 92febbd commit ca07e18

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

.azure-pipelines/test-coverage.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ jobs:
105105
arguments: '-CalcBaseline:$${{ parameters.updateBaseline }}'
106106

107107
- template: util/get-github-pat-steps.yml
108+
parameters:
109+
execCondition: and(succeeded(), ${{ parameters.updateBaseline }})
108110

109111
- task: PowerShell@2
110112
displayName: Update Test Coverage Baseline

.azure-pipelines/util/get-github-pat-steps.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
parameters:
2+
- name: execCondition
3+
type: string
4+
default: succeeded()
5+
16
steps:
27
- task: AzurePowerShell@5
8+
displayName: Get GitHub PAT from Key Vault
9+
condition: ${{ parameters.execCondition }}
310
inputs:
411
pwsh: true
12+
azurePowerShellVersion: 'LatestVersion'
513
azureSubscription: '$(AzureSubscription)'
614
ScriptType: 'InlineScript'
715
Inline: |
816
$GithubToken = Get-AzKeyVaultSecret -VaultName $(GithubPATKeyVaultName) -Name $(GithubPATKeyVaultAccount) -AsPlainText
917
Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken"
10-
azurePowerShellVersion: 'LatestVersion'
11-
displayName: Get Github PAT from Key Vault

tools/TestFx/Coverage/AnalyzeTestCoverage.ps1

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ $cvgReportCsv = Join-Path -Path $cvgResultsDir -ChildPath "Report.csv"
6161
({} | Select-Object "Module", "TotalCommands", "TestedCommands", "CommandCoverage", "TotalParameterSets", "TestedParameterSets", "ParameterSetCoverage", "TotalParameters", "TestedParameters", "ParameterCoverage" | ConvertTo-Csv -NoTypeInformation)[0] | Out-File -LiteralPath $cvgReportCsv -Encoding utf8 -Force
6262

6363
$allModules = Get-ChildItem -Path $debugDir -Filter "Az.*" -Directory -Name
64+
$testedModules = $allModules
6465

6566
if ($CalcBaseline.IsPresent) {
66-
$testedModules = $allModules
6767
$cvgBaselineCsv = Join-Path -Path $cvgResultsDir -ChildPath "Baseline.csv"
6868
({} | Select-Object "Module", "CommandCoverage" | ConvertTo-Csv -NoTypeInformation)[0] | Out-File -LiteralPath $cvgBaselineCsv -Encoding utf8 -Force
6969
}
7070
else {
7171
$ciPlanFilePath = Join-Path -Path $artifactsDir -ChildPath "PipelineResult" | Join-Path -ChildPath "CIPlan.json"
72-
$ciPlan = Get-Content -Path $ciPlanFilePath -Raw | ConvertFrom-Json
73-
if ($ciPlan.test.Length -gt 0) {
74-
$testedModules = $allModules | Where-Object { $_.Substring(3) -in $ciPlan.test }
72+
if (Test-Path -Path $ciPlanFilePath -PathType Leaf) {
73+
$ciPlan = Get-Content -Path $ciPlanFilePath -Raw | ConvertFrom-Json
74+
if ($ciPlan.test.Length -gt 0) {
75+
$testedModules = $allModules | Where-Object { $_.Substring(3) -in $ciPlan.test }
76+
}
7577
}
7678
}
7779

@@ -195,8 +197,8 @@ foreach ($moduleName in $testedModules) {
195197

196198
if ($CalcBaseline.IsPresent) {
197199
$cvgBaseline = [PSCustomObject]@{
198-
Module = $simpleModuleName
199-
CommandCoverage = $cvgCommand
200+
Module = $simpleModuleName
201+
CommandCoverage = $cvgCommand
200202
}
201203
$cvgBaseline | Export-Csv -Path $cvgBaselineCsv -Encoding utf8 -NoTypeInformation -Append -Force
202204
}

0 commit comments

Comments
 (0)