Skip to content

Commit 9f4425b

Browse files
azure-sdkraych1
andauthored
Sync eng/common directory with azure-sdk-tools for PR 15215 (#46495)
* Install PS modules from CFS * Reverted change of adding auth in module installation command * reverted quotation mark change * Removed fallback logic of installation module * Change installation to be required version --------- Co-authored-by: Ray Chen <raychen@microsoft.com>
1 parent f12c4f8 commit 9f4425b

3 files changed

Lines changed: 11 additions & 41 deletions

File tree

eng/common/pipelines/templates/steps/run-pester-tests.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ parameters:
1414
steps:
1515

1616
- pwsh: |
17-
Install-Module -Name Pester -Force
17+
. (Join-Path "$(Build.SourcesDirectory)" eng common scripts Helpers PSModule-Helpers.ps1)
18+
Install-ModuleIfNotInstalled "Pester" "5.7.1" | Import-Module
1819
displayName: Install Pester
1920
2021
# default test steps

eng/common/scripts/Helpers/PSModule-Helpers.ps1

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -46,23 +46,6 @@ function Update-PSModulePathForCI() {
4646
}
4747
}
4848

49-
function Get-ModuleRepositories([string]$moduleName) {
50-
$DefaultPSRepositoryUrl = "https://www.powershellgallery.com/api/v2"
51-
# List of modules+versions we want to replace with internal feed sources for reliability, security, etc.
52-
$packageFeedOverrides = @{
53-
'powershell-yaml' = 'https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-tools/nuget/v2'
54-
}
55-
56-
$repoUrls = if ($packageFeedOverrides.Contains("${moduleName}")) {
57-
@($packageFeedOverrides["${moduleName}"], $DefaultPSRepositoryUrl)
58-
}
59-
else {
60-
@($DefaultPSRepositoryUrl)
61-
}
62-
63-
return $repoUrls
64-
}
65-
6649
function moduleIsInstalled([string]$moduleName, [string]$version) {
6750
if (-not (Test-Path variable:script:InstalledModules)) {
6851
$script:InstalledModules = @{}
@@ -100,13 +83,13 @@ function installModule([string]$moduleName, [string]$version, $repoUrl) {
10083
Set-PSRepository -Name $repo.Name -InstallationPolicy "Trusted" | Out-Null
10184
}
10285

103-
Write-Verbose "Installing module $moduleName with min version $version from $repoUrl"
86+
Write-Verbose "Installing module $moduleName with version $version from $repoUrl"
10487
# Install under CurrentUser scope so that the end up under $CurrentUserModulePath for caching
105-
Install-Module $moduleName -MinimumVersion $version -Repository $repo.Name -Scope CurrentUser -Force -WhatIf:$false
88+
Install-Module $moduleName -RequiredVersion $version -Repository $repo.Name -Scope CurrentUser -Force -WhatIf:$false
10689
# Ensure module installed
10790
$modules = (Get-Module -ListAvailable $moduleName)
10891
if ($version -as [Version]) {
109-
$modules = $modules.Where({ [Version]$_.Version -ge [Version]$version })
92+
$modules = $modules.Where({ [Version]$_.Version -eq [Version]$version })
11093
}
11194
if ($modules.Count -eq 0) {
11295
throw "Failed to install module $moduleName with version $version"
@@ -151,26 +134,11 @@ function Install-ModuleIfNotInstalled() {
151134
$module = moduleIsInstalled -moduleName $moduleName -version $version
152135
if ($module) { return $module }
153136

154-
$repoUrls = Get-ModuleRepositories $moduleName
155-
156-
foreach ($url in $repoUrls) {
157-
try {
158-
$module = installModule -moduleName $moduleName -version $version -repoUrl $url
159-
}
160-
catch {
161-
if ($url -ne $repoUrls[-1]) {
162-
Write-Warning "Failed to install powershell module from '$url'. Retrying with fallback repository"
163-
Write-Warning $_
164-
continue
165-
}
166-
else {
167-
Write-Warning "Failed to install powershell module from $url"
168-
throw
169-
}
170-
}
171-
break
172-
}
137+
# Use internal Azure Artifacts feed only.
138+
$repoUrl = "https://pkgs.dev.azure.com/azure-sdk/public/_packaging/azure-sdk-tools/nuget/v2"
139+
Write-Host "Module '$moduleName' with version '$version' is not installed. Attempting to install from $repoUrl."
173140

141+
$module = installModule -moduleName $moduleName -version $version -repoUrl $repoUrl
174142
Write-Verbose "Using module '$($module.Name)' with version '$($module.Version)'."
175143
}
176144
finally {

eng/common/scripts/Verify-Resource-Ref.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
. (Join-Path $PSScriptRoot common.ps1)
2-
Install-Module -Name powershell-yaml -RequiredVersion 0.4.7 -Force -Scope CurrentUser
2+
. (Join-Path $PSScriptRoot Helpers PSModule-Helpers.ps1)
3+
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.7" | Import-Module
34
$ymlfiles = Get-ChildItem $RepoRoot -recurse | Where-Object {$_ -like '*.yml'}
45
$affectedRepos = [System.Collections.ArrayList]::new()
56

0 commit comments

Comments
 (0)