Skip to content

Commit 507b4df

Browse files
committed
Update tools and roll-up module dependencies
1 parent ccafa85 commit 507b4df

File tree

3 files changed

+111
-3
lines changed

3 files changed

+111
-3
lines changed

src/ServiceManagement/Azure.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CLRVersion = '4.0'
5151
# ProcessorArchitecture = ''
5252

5353
# Modules that must be imported into the global environment prior to importing this module
54-
#RequiredModules = ''
54+
RequiredModules = @(@{ModuleName = 'Azure.Storage'; ModuleVersion = '4.3.0'; })
5555

5656
# Assemblies that must be loaded prior to importing this module
5757
# RequiredAssemblies = @()

tools/AzureRM/AzureRM.psd1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ CLRVersion = '4.0'
5151
# ProcessorArchitecture = ''
5252

5353
# Modules that must be imported into the global environment prior to importing this module
54-
RequiredModules = @(@{ModuleName = 'AzureRM.Profile'; RequiredVersion = '5.0.0'; },
54+
RequiredModules = @(@{ModuleName = 'AzureRM.Profile'; ModuleVersion = '5.0.0'; },
55+
@{ModuleName = 'Azure.Storage'; ModuleVersion = '4.3.0'; },
5556
@{ModuleName = 'AzureRM.AnalysisServices'; RequiredVersion = '0.6.7'; },
5657
@{ModuleName = 'Azure.AnalysisServices'; RequiredVersion = '0.5.1'; },
5758
@{ModuleName = 'AzureRM.ApiManagement'; RequiredVersion = '6.0.0'; },

tools/PublishModules.ps1

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,106 @@ function Publish-RMModule
280280
}
281281
}
282282

283+
<#
284+
.SYNOPSIS
285+
Saves a module into the local temporary repository
286+
287+
.PARAMETER Module
288+
Module information.
289+
290+
.PARAMETER TempRepo
291+
Name of the local temporary repository
292+
293+
.PARAMETER TempRepoPath
294+
Path to the local temporary repository
295+
#>
296+
function Save-PackageLocally {
297+
[CmdletBinding()]
298+
param(
299+
$Module,
300+
[string]$TempRepo,
301+
[string]$TempRepoPath
302+
)
303+
304+
$ModuleName = $module['ModuleName']
305+
$RequiredVersion = $module['RequiredVersion']
306+
if ($RequiredVersion -eq $null)
307+
{
308+
$RequiredVersion = $module['ModuleVersion']
309+
}
310+
311+
# Only check for the modules that specifies = required exact dependency version
312+
if ($RequiredVersion -ne $null) {
313+
Write-Output "Checking for required module $ModuleName, $RequiredVersion"
314+
if (Find-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Repository $TempRepo -ErrorAction SilentlyContinue) {
315+
Write-Output "Required dependency $ModuleName, $RequiredVersion found in the repo $TempRepo"
316+
} elseif ((Get-Module -ListAvailable -Name $ModuleName | Where-Object {$_.Version -eq $RequiredVersion}) -ne $null) {
317+
Write-Output "Required dependency $ModuleName, $RequiredVersion found in build modules"
318+
} else {
319+
Write-Warning "Required dependency $ModuleName, $RequiredVersion not found in the repo $TempRepo"
320+
Write-Output "Downloading the package from PsGallery to the path $TempRepoPath"
321+
# We try to download the package from the PsGallery as we are likely intending to use the existing version of the module.
322+
# If the module not found in psgallery, the following commnad would fail and hence publish to local repo process would fail as well
323+
Save-Package -Name $ModuleName -RequiredVersion $RequiredVersion -ProviderName Nuget -Path $TempRepoPath -Source https://www.powershellgallery.com/api/v2 | Out-Null
324+
Write-Output "Downloaded the package sucessfully"
325+
}
326+
}
327+
}
328+
329+
<#
330+
.SYNOPSIS
331+
Save the packages from PsGallery to local repo path
332+
This is typically used in a scenario where we are intending to use the existing publshed version of the module as a dependency
333+
Checks whether the module is already published in the local temp repo, if not downloads from the PSGallery
334+
This is used only for the rollup modules AzureRm or AzureStack at the moment
335+
336+
.PARAMETER ModulePaths
337+
List of paths to modules.
338+
339+
.PARAMETER TempRepo
340+
Name of local temporary repository.
341+
342+
.PARAMETER TempRepoPath
343+
path to local temporary repository.
344+
345+
#>
346+
function Save-PackagesFromPsGallery {
347+
[CmdletBinding()]
348+
param(
349+
[String[]]$ModulePaths,
350+
351+
[ValidateNotNullOrEmpty()]
352+
[String]$TempRepo,
353+
354+
[ValidateNotNullOrEmpty()]
355+
[String]$TempRepoPath
356+
)
357+
PROCESS {
358+
359+
Write-Output "Saving..."
360+
361+
foreach ($modulePath in $ModulePaths) {
362+
363+
Write-Output "module path $modulePath"
364+
365+
$module = (Get-Item -Path $modulePath).Name
366+
$moduleManifest = $module + ".psd1"
367+
368+
Write-Host "Verifying $module has all the dependencies in the repo $TempRepo"
369+
370+
$psDataFile = Import-PowershellDataFile (Join-Path $modulePath -ChildPath $moduleManifest)
371+
$RequiredModules = $psDataFile['RequiredModules']
372+
373+
if ($RequiredModules -ne $null) {
374+
foreach ($tmp in $RequiredModules) {
375+
foreach ($module in $tmp) {
376+
Save-PackageLocally -Module $module -TempRepo $TempRepo -TempRepoPath $TempRepoPath
377+
}
378+
}
379+
}
380+
}
381+
}
382+
}
283383

284384

285385
if ([string]::IsNullOrEmpty($buildConfig))
@@ -336,10 +436,17 @@ if ($repo -ne $null) {
336436
Register-PSRepository -Name $tempRepoName -SourceLocation $tempRepoPath -PublishLocation $tempRepoPath -InstallationPolicy Trusted -PackageManagementProvider NuGet
337437
}
338438

339-
$env:PSModulePath="$env:PSModulePath;$tempRepoPath"
439+
440+
441+
$sourceModulePath = "$packageFolder\ResourceManager\AzureResourceManager"
442+
443+
$sourceModulePath
444+
$env:PSModulePath="$env:PSModulePath;$tempRepoPath;$sourceModulePath"
445+
$env:PSModulePath
340446

341447
try {
342448
$modulesInScope = Get-TargetModules -buildConfig $buildConfig -Scope $scope -PublishLocal $publishToLocal -Profile $Profile
449+
Save-PackagesFromPsGallery -ModulePaths $modulesInScope -TempRepo $tempRepoName -TempRepoPath $tempRepoPath
343450
foreach ($modulePath in $modulesInScope) {
344451
# filter out AzureRM.Profile which always gets published first
345452
# And "Azure.Storage" which is built out as test dependencies

0 commit comments

Comments
 (0)