diff --git a/.azure-pipelines/test-coverage.yml b/.azure-pipelines/test-coverage.yml index 1fe4103876de..08c5db4cb86c 100644 --- a/.azure-pipelines/test-coverage.yml +++ b/.azure-pipelines/test-coverage.yml @@ -105,6 +105,8 @@ jobs: arguments: '-CalcBaseline:$${{ parameters.updateBaseline }}' - template: util/get-github-pat-steps.yml + parameters: + execCondition: and(succeeded(), ${{ parameters.updateBaseline }}) - task: PowerShell@2 displayName: Update Test Coverage Baseline diff --git a/.azure-pipelines/util/get-github-pat-steps.yml b/.azure-pipelines/util/get-github-pat-steps.yml index 3041c5764f96..34005a831253 100644 --- a/.azure-pipelines/util/get-github-pat-steps.yml +++ b/.azure-pipelines/util/get-github-pat-steps.yml @@ -1,11 +1,17 @@ +parameters: +- name: execCondition + type: string + default: succeeded() + steps: - task: AzurePowerShell@5 + displayName: Get GitHub PAT from Key Vault + condition: ${{ parameters.execCondition }} inputs: pwsh: true + azurePowerShellVersion: 'LatestVersion' azureSubscription: '$(AzureSubscription)' ScriptType: 'InlineScript' Inline: | $GithubToken = Get-AzKeyVaultSecret -VaultName $(GithubPATKeyVaultName) -Name $(GithubPATKeyVaultAccount) -AsPlainText Write-Host "##vso[task.setvariable variable=GithubToken;issecret=true]$GithubToken" - azurePowerShellVersion: 'LatestVersion' - displayName: Get Github PAT from Key Vault \ No newline at end of file diff --git a/tools/TestFx/Coverage/AnalyzeTestCoverage.ps1 b/tools/TestFx/Coverage/AnalyzeTestCoverage.ps1 index c8d7276dc330..824db0ddcdd0 100644 --- a/tools/TestFx/Coverage/AnalyzeTestCoverage.ps1 +++ b/tools/TestFx/Coverage/AnalyzeTestCoverage.ps1 @@ -61,17 +61,19 @@ $cvgReportCsv = Join-Path -Path $cvgResultsDir -ChildPath "Report.csv" ({} | Select-Object "Module", "TotalCommands", "TestedCommands", "CommandCoverage", "TotalParameterSets", "TestedParameterSets", "ParameterSetCoverage", "TotalParameters", "TestedParameters", "ParameterCoverage" | ConvertTo-Csv -NoTypeInformation)[0] | Out-File -LiteralPath $cvgReportCsv -Encoding utf8 -Force $allModules = Get-ChildItem -Path $debugDir -Filter "Az.*" -Directory -Name +$testedModules = $allModules if ($CalcBaseline.IsPresent) { - $testedModules = $allModules $cvgBaselineCsv = Join-Path -Path $cvgResultsDir -ChildPath "Baseline.csv" ({} | Select-Object "Module", "CommandCoverage" | ConvertTo-Csv -NoTypeInformation)[0] | Out-File -LiteralPath $cvgBaselineCsv -Encoding utf8 -Force } else { $ciPlanFilePath = Join-Path -Path $artifactsDir -ChildPath "PipelineResult" | Join-Path -ChildPath "CIPlan.json" - $ciPlan = Get-Content -Path $ciPlanFilePath -Raw | ConvertFrom-Json - if ($ciPlan.test.Length -gt 0) { - $testedModules = $allModules | Where-Object { $_.Substring(3) -in $ciPlan.test } + if (Test-Path -Path $ciPlanFilePath -PathType Leaf) { + $ciPlan = Get-Content -Path $ciPlanFilePath -Raw | ConvertFrom-Json + if ($ciPlan.test.Length -gt 0) { + $testedModules = $allModules | Where-Object { $_.Substring(3) -in $ciPlan.test } + } } } @@ -195,8 +197,8 @@ foreach ($moduleName in $testedModules) { if ($CalcBaseline.IsPresent) { $cvgBaseline = [PSCustomObject]@{ - Module = $simpleModuleName - CommandCoverage = $cvgCommand + Module = $simpleModuleName + CommandCoverage = $cvgCommand } $cvgBaseline | Export-Csv -Path $cvgBaselineCsv -Encoding utf8 -NoTypeInformation -Append -Force }