@@ -19,7 +19,6 @@ $defaultCICDPushBranches = @( 'main', 'release/*', 'feature/*' )
19
19
$defaultCICDPullRequestBranches = @ ( ' main' )
20
20
$runningLocal = $local.IsPresent
21
21
$defaultBcContainerHelperVersion = " latest" # Must be double quotes. Will be replaced by BcContainerHelperVersion if necessary in the deploy step - ex. "https://github.com/organization/navcontainerhelper/archive/refs/heads/branch.zip"
22
- $microsoftTelemetryConnectionString = " InstrumentationKey=84bd9223-67d4-4378-8590-9e4a46023be2;IngestionEndpoint=https://westeurope-1.in.applicationinsights.azure.com/"
23
22
$notSecretProperties = @ (" Scopes" , " TenantId" , " BlobName" , " ContainerName" , " StorageAccountName" , " ServerUrl" , " ppUserName" )
24
23
25
24
$runAlPipelineOverrides = @ (
@@ -631,13 +630,19 @@ function ReadSettings {
631
630
" cacheImageName" = " my"
632
631
" cacheKeepDays" = 3
633
632
" alwaysBuildAllProjects" = $false
634
- " microsoftTelemetryConnectionString" = $microsoftTelemetryConnectionString
633
+ " microsoftTelemetryConnectionString" = " InstrumentationKey=cd2cc63e-0f37-4968-b99a-532411a314b8;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/ "
635
634
" partnerTelemetryConnectionString" = " "
636
635
" sendExtendedTelemetryToMicrosoft" = $false
637
636
" environments" = @ ()
638
637
" buildModes" = @ ()
639
638
" useCompilerFolder" = $false
640
639
" pullRequestTrigger" = " pull_request_target"
640
+ " bcptThresholds" = [ordered ]@ {
641
+ " DurationWarning" = 10
642
+ " DurationError" = 25
643
+ " NumberOfSqlStmtsWarning" = 5
644
+ " NumberOfSqlStmtsError" = 10
645
+ }
641
646
" fullBuildPatterns" = @ ()
642
647
" excludeEnvironments" = @ ()
643
648
" alDoc" = [ordered ]@ {
@@ -1263,21 +1268,25 @@ function GetProjectFolders {
1263
1268
$projectFolders
1264
1269
}
1265
1270
1266
- function installModules {
1271
+ function InstallModule {
1267
1272
Param (
1268
- [String []] $modules
1273
+ [String ] $name ,
1274
+ [System.Version ] $minimumVersion = $null
1269
1275
)
1270
1276
1271
- $modules | ForEach-Object {
1272
- if (-not (get-installedmodule - Name $_ - ErrorAction SilentlyContinue)) {
1273
- Write-Host " Installing module $_ "
1274
- Install-Module $_ - Force | Out-Null
1275
- }
1277
+ if ($null -eq $minimumVersion ) {
1278
+ $minimumVersion = [System.Version ](GetPackageVersion - packageName $name )
1276
1279
}
1277
- $modules | ForEach-Object {
1278
- Write-Host " Importing module $_ "
1279
- Import-Module $_ - DisableNameChecking - WarningAction SilentlyContinue | Out-Null
1280
+ $module = Get-Module - name $name - ListAvailable | Select-Object - First 1
1281
+ if ($module -and $module.Version -ge $minimumVersion ) {
1282
+ Write-Host " Module $name is available in version $ ( $module.Version ) "
1283
+ }
1284
+ else {
1285
+ Write-Host " Installing module $name (minimum version $minimumVersion )"
1286
+ Install-Module - Name $name - MinimumVersion " $minimumVersion " - Force | Out-Null
1280
1287
}
1288
+ Write-Host " Importing module $name (minimum version $minimumVersion )"
1289
+ Import-Module - Name $name - MinimumVersion $minimumVersion - DisableNameChecking - WarningAction SilentlyContinue | Out-Null
1281
1290
}
1282
1291
1283
1292
function CloneIntoNewFolder {
@@ -1323,6 +1332,7 @@ function CommitFromNewFolder {
1323
1332
Param (
1324
1333
[string ] $serverUrl ,
1325
1334
[string ] $commitMessage ,
1335
+ [string ] $body = $commitMessage ,
1326
1336
[string ] $branch
1327
1337
)
1328
1338
@@ -1351,7 +1361,7 @@ function CommitFromNewFolder {
1351
1361
}
1352
1362
invoke-git push - u $serverUrl $branch
1353
1363
try {
1354
- invoke-gh pr create -- fill -- head $branch -- repo $env: GITHUB_REPOSITORY -- base $ENV: GITHUB_REF_NAME
1364
+ invoke-gh pr create -- fill -- head $branch -- repo $env: GITHUB_REPOSITORY -- base $ENV: GITHUB_REF_NAME -- body " $body "
1355
1365
}
1356
1366
catch {
1357
1367
OutputError(" GitHub actions are not allowed to create Pull Requests (see GitHub Organization or Repository Actions Settings). You can create the PR manually by navigating to $ ( $env: GITHUB_SERVER_URL ) /$ ( $env: GITHUB_REPOSITORY ) /tree/$branch " )
@@ -1657,7 +1667,7 @@ function CreateDevEnv {
1657
1667
1658
1668
if (($settings.keyVaultName ) -and -not ($bcAuthContext )) {
1659
1669
Write-Host " Reading Key Vault $ ( $settings.keyVaultName ) "
1660
- installModules - modules @ ( ' Az.KeyVault' )
1670
+ InstallAzModuleIfNeeded - name ' Az.KeyVault'
1661
1671
1662
1672
if ($kind -eq " local" ) {
1663
1673
$LicenseFileSecret = Get-AzKeyVaultSecret - VaultName $settings.keyVaultName - Name $settings.licenseFileUrlSecretName
@@ -2350,14 +2360,86 @@ function GetProjectsFromRepository {
2350
2360
return @ (GetMatchingProjects - projects $projects - selectProjects $selectProjects )
2351
2361
}
2352
2362
2353
- function Get-PackageVersion ( $PackageName ) {
2363
+ function GetPackageVersion ( $packageName ) {
2354
2364
$alGoPackages = Get-Content - Path " $PSScriptRoot \Packages.json" | ConvertFrom-Json
2355
2365
2356
2366
# Check if the package is in the list of packages
2357
- if ($alGoPackages.PSobject.Properties.name -match $PackageName ) {
2358
- return $alGoPackages .$PackageName
2367
+ if ($alGoPackages.PSobject.Properties.name -eq $PackageName ) {
2368
+ return $alGoPackages ." $PackageName "
2359
2369
}
2360
2370
else {
2361
2371
throw " Package $PackageName is not in the list of packages"
2362
2372
}
2363
2373
}
2374
+
2375
+ function InstallAzModuleIfNeeded {
2376
+ Param (
2377
+ [string ] $name ,
2378
+ [System.version ] $minimumVersion = $null
2379
+ )
2380
+
2381
+ if ($null -eq $minimumVersion ) {
2382
+ $minimumVersion = [System.Version ](GetPackageVersion - packageName $name )
2383
+ }
2384
+ $azModule = Get-Module - Name $name
2385
+ if ($azModule -and $azModule.Version -ge $minimumVersion ) {
2386
+ # Already installed
2387
+ return
2388
+ }
2389
+ # GitHub hosted Linux runners have AZ PowerShell module saved in /usr/share/powershell/Modules/Az.*
2390
+ if ($isWindows ) {
2391
+ # GitHub hosted Windows Runners have AzureRm PowerShell modules installed (deprecated)
2392
+ # GitHub hosted Windows Runners have AZ PowerShell module saved in C:\Modules\az_*
2393
+ # Remove AzureRm modules from PSModulePath and add AZ modules
2394
+ if (Test-Path ' C:\Modules\az_*' ) {
2395
+ $azModulesPath = Get-ChildItem ' C:\Modules\az_*' | Where-Object { $_.PSIsContainer }
2396
+ if ($azModulesPath ) {
2397
+ Write-Host " Adding AZ module path: $ ( $azModulesPath.FullName ) "
2398
+ $ENV: PSModulePath = " $ ( $azModulesPath.FullName ) ;$ ( (" $ENV: PSModulePath " .Split(' ;' ) | Where-Object { $_ -notlike ' C:\\Modules\Azure*' }) -join ' ;' ) "
2399
+ }
2400
+ }
2401
+ }
2402
+ InstallModule - name $name - minimumVersion $minimumVersion
2403
+ }
2404
+
2405
+ $script :AzConnected = $false
2406
+
2407
+ function ConnectAz {
2408
+ [Diagnostics.CodeAnalysis.SuppressMessageAttribute (' PSAvoidUsingConvertToSecureStringWithPlainText' , ' ' , Justification = ' GitHub Secrets come in as plain text' )]
2409
+ param (
2410
+ [PsCustomObject ] $azureCredentials
2411
+ )
2412
+ if ($script :AzConnected ) {
2413
+ return
2414
+ }
2415
+ InstallAzModuleIfNeeded - name ' Az.KeyVault'
2416
+ try {
2417
+ Clear-AzContext - Scope Process
2418
+ Clear-AzContext - Scope CurrentUser - Force - ErrorAction SilentlyContinue
2419
+ if ($azureCredentials.PSObject.Properties.Name -eq ' ClientSecret' -and $azureCredentials.ClientSecret ) {
2420
+ Write-Host " Connecting to Azure using clientId and clientSecret."
2421
+ $credential = New-Object pscredential - ArgumentList $azureCredentials.ClientId , (ConvertTo-SecureString - string $azureCredentials.ClientSecret - AsPlainText - Force)
2422
+ Connect-AzAccount - ServicePrincipal - Tenant $azureCredentials.TenantId - Credential $credential - WarningAction SilentlyContinue | Out-Null
2423
+ }
2424
+ else {
2425
+ try {
2426
+ Write-Host " Query federated token"
2427
+ $result = Invoke-RestMethod - Method GET - UseBasicParsing - Headers @ { " Authorization" = " bearer $ENV: ACTIONS_ID_TOKEN_REQUEST_TOKEN " ; " Accept" = " application/vnd.github+json" } - Uri " $ENV: ACTIONS_ID_TOKEN_REQUEST_URL &audience=api://AzureADTokenExchange"
2428
+ }
2429
+ catch {
2430
+ throw " Unable to get federated token, maybe id_token: write permissions are missing. Error was $ ( $_.Exception.Message ) "
2431
+ }
2432
+ Write-Host " Connecting to Azure using clientId and federated token."
2433
+ Connect-AzAccount - ApplicationId $azureCredentials.ClientId - Tenant $azureCredentials.TenantId - FederatedToken $result.value - WarningAction SilentlyContinue | Out-Null
2434
+ }
2435
+ if ($azureCredentials.PSObject.Properties.Name -eq ' SubscriptionId' -and $azureCredentials.SubscriptionId ) {
2436
+ Write-Host " Selecting subscription $ ( $azureCredentials.SubscriptionId ) "
2437
+ Set-AzContext - SubscriptionId $azureCredentials.SubscriptionId - Tenant $azureCredentials.TenantId - ErrorAction SilentlyContinue - WarningAction SilentlyContinue | Out-Null
2438
+ }
2439
+ $script :AzConnected = $true
2440
+ Write-Host " Successfully connected to Azure"
2441
+ }
2442
+ catch {
2443
+ throw " Error trying to authenticate to Azure. Error was $ ( $_.Exception.Message ) "
2444
+ }
2445
+ }
0 commit comments