@@ -280,6 +280,106 @@ function Publish-RMModule
280
280
}
281
281
}
282
282
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
+ }
283
383
284
384
285
385
if ([string ]::IsNullOrEmpty($buildConfig ))
@@ -336,10 +436,17 @@ if ($repo -ne $null) {
336
436
Register-PSRepository - Name $tempRepoName - SourceLocation $tempRepoPath - PublishLocation $tempRepoPath - InstallationPolicy Trusted - PackageManagementProvider NuGet
337
437
}
338
438
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
340
446
341
447
try {
342
448
$modulesInScope = Get-TargetModules - buildConfig $buildConfig - Scope $scope - PublishLocal $publishToLocal - Profile $Profile
449
+ Save-PackagesFromPsGallery - ModulePaths $modulesInScope - TempRepo $tempRepoName - TempRepoPath $tempRepoPath
343
450
foreach ($modulePath in $modulesInScope ) {
344
451
# filter out AzureRM.Profile which always gets published first
345
452
# And "Azure.Storage" which is built out as test dependencies
0 commit comments