diff --git a/.azure-pipelines/live-test.yml b/.azure-pipelines/live-test.yml index d44affa783a3..077e70daaf3c 100644 --- a/.azure-pipelines/live-test.yml +++ b/.azure-pipelines/live-test.yml @@ -52,6 +52,7 @@ schedules: branches: include: - shared/livetest + always: true pr: none trigger: none diff --git a/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 b/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 index 528ca50fa850..c4a2231e7242 100644 --- a/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 +++ b/tools/TestFx/Live/DebugLocalLiveTestScenarios.ps1 @@ -1,33 +1,52 @@ -param( +param ( [Parameter(Mandatory)] [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] [string] $RepoLocation ) -$debugDirectory = Join-Path -Path $RepoLocation -ChildPath "artifacts" | Join-Path -ChildPath "Debug" -$accountsModuleDirectory = Join-Path -Path $debugDirectory -ChildPath "Az.Accounts" -Write-Host "Start to import Azure PowerShell modules from artifacts/Debug." -ForegroundColor Green -Write-Host "If you see module import issue, please restart the PowerShell host." -ForegroundColor Magenta +New-Variable -Name LocalRepoLocation -Value $RepoLocation -Scope Script -Option ReadOnly -Write-Host "Importing Az.Accounts." -ForegroundColor Green -Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1") -Get-ChildItem -Path $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Filter "*.psd1" | ForEach-Object { - Write-Host "Importing $($_.FullName)." -ForegroundColor Green - Import-Module $_.FullName -Force -} -Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green +function ImportLocalAzModules { + param () + + $debugDirectory = Join-Path -Path $script:LocalRepoLocation -ChildPath "artifacts" | Join-Path -ChildPath "Debug" + $accountsModuleDirectory = Join-Path -Path $debugDirectory -ChildPath "Az.Accounts" + Write-Host "Start to import Azure PowerShell modules from artifacts/Debug." -ForegroundColor Green + Write-Host "If you see module import issue, please restart the PowerShell host." -ForegroundColor Magenta -$dataLocation = (Get-AzConfig -TestCoverageLocation).Value -if ([string]::IsNullOrWhiteSpace($dataLocation) -or !(Test-Path -LiteralPath $dataLocation -PathType Container)) { - $dataLocation = Join-Path -Path $env:USERPROFILE -ChildPath ".Azure" + Write-Host "Importing Az.Accounts." -ForegroundColor Green + Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1") + Get-ChildItem -Path $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Filter "*.psd1" | ForEach-Object { + Write-Host "Importing $($_.FullName)." -ForegroundColor Green + Import-Module $_.FullName -Force + } + Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green } -Write-Host "Data location is `"$dataLocation`"" -ForegroundColor Cyan - -$srcDir = Join-Path -Path $RepoLocation -ChildPath "src" -$liveScenarios = Get-ChildItem -Path $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File -$liveScenarios | ForEach-Object { - $moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value - Import-Module "./tools/TestFx/Assert.ps1" -Force - Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, "LocalDebug", "LocalDebug", "LocalDebug", $dataLocation -Force - . $_.FullName + +function InvokeLocalLiveTestScenarios { + param ( + [Parameter()] + [ValidateNotNullOrEmpty()] + [string[]] $TargetModules + ) + + $dataLocation = (Get-AzConfig -TestCoverageLocation).Value + if ([string]::IsNullOrWhiteSpace($dataLocation) -or !(Test-Path -LiteralPath $dataLocation -PathType Container)) { + $dataLocation = Join-Path -Path $env:USERPROFILE -ChildPath ".Azure" + } + Write-Host "Data location is `"$dataLocation`"" -ForegroundColor Cyan + + $srcDir = Join-Path -Path $script:LocalRepoLocation -ChildPath "src" + $liveScenarios = Get-ChildItem -Path $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File + $liveScenarios | ForEach-Object { + $moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value + if (!$PSBoundParameters.ContainsKey("TargetModules") -or $moduleName -in $TargetModules) { + Write-Host "Executing live test scenarios for module $moduleName" -ForegroundColor Cyan + Import-Module "./tools/TestFx/Assert.ps1" -Force + Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, "LocalDebug", "LocalDebug", "LocalDebug", $dataLocation -Force + . $_.FullName + } + } } + +ImportLocalAzModules