Skip to content

Commit 8803ab9

Browse files
chore: dev to main merge
2 parents 678bedc + 79a01f5 commit 8803ab9

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

run.ps1

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ function Initialize-AutomationEnvironment {
8989
}
9090
}
9191

92-
Import-Module Az.Accounts -ErrorAction Stop | Out-Null
92+
# Guard: skip import when Az.Accounts is already loaded (e.g. by postprovision.ps1)
93+
# to avoid "Assembly with same name is already loaded" on CI runners.
94+
if (-not (Get-Module Az.Accounts)) {
95+
Import-Module Az.Accounts -ErrorAction Stop | Out-Null
96+
}
9397
}
9498

9599
function Test-HasFabricLakehouseSensitivityLabels {
@@ -121,6 +125,32 @@ function Test-HasFabricLakehouseSensitivityLabels {
121125
}
122126

123127
Initialize-AutomationEnvironment -RequireExchange:$ConnectM365
128+
129+
# Shadow Import-Module so downstream scripts skip modules already in memory,
130+
# preventing "Assembly with same name is already loaded" on CI runners where
131+
# postprovision.ps1 pre-loads Az modules before invoking run.ps1.
132+
function Import-Module {
133+
[System.Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidOverwritingBuiltInCmdlets','')]
134+
[CmdletBinding()]
135+
param(
136+
[Parameter(Mandatory=$true, Position=0)][ValidateNotNullOrEmpty()][string[]]$Name,
137+
[switch]$Force,
138+
[string]$MinimumVersion
139+
)
140+
$toImport = @($Name | Where-Object {
141+
$loaded = Get-Module $_
142+
if (-not $loaded) { return $true }
143+
if ($Force) { return $true }
144+
if ($MinimumVersion -and $loaded.Version -lt [version]$MinimumVersion) { return $true }
145+
return $false
146+
})
147+
if ($toImport.Count -eq 0) { return }
148+
$params = @{ Name = $toImport; ErrorAction = $ErrorActionPreference }
149+
if ($Force) { $params['Force'] = $true }
150+
if ($MinimumVersion) { $params['MinimumVersion'] = $MinimumVersion }
151+
Microsoft.PowerShell.Core\Import-Module @params
152+
}
153+
124154
$planEntry = {
125155
param([int]$Order,[string]$File,[string[]]$Tags,[bool]$NeedsSpec,[hashtable]$Parameters)
126156
[pscustomobject]@{
@@ -195,7 +225,6 @@ Write-Host "Running steps for tags: $($Tags -join ', ')" -ForegroundColor Cyan
195225

196226
$fabricLabelsConfigured = Test-HasFabricLakehouseSensitivityLabels -Path $SpecPath
197227

198-
# PSScriptAnalyzerSuppressMessage("PSAvoidAssignmentToAutomaticVariable", "", "No automatic variables are assigned; parameters are tracked via local ordered hashtable")
199228
foreach ($step in $selected) {
200229
if ($step.File -eq "scripts/governance/dspmPurview/26-Apply-FabricLakehouseSensitivity.ps1" -and -not $fabricLabelsConfigured) {
201230
Write-Host "Skipping Fabric lakehouse label apply step because no lakehouse sensitivity labels are configured in spec." -ForegroundColor DarkGray

0 commit comments

Comments
 (0)