Skip to content

Commit e0080d1

Browse files
bcbuild-github-agentmicrosoft
and
microsoft
authored
Deploying AL-Go from main (a2c4efcc730e9b264f74cb321e7c2193c8c96b8d) to main (microsoft#62)
Deploying AL-Go from main (a2c4efcc730e9b264f74cb321e7c2193c8c96b8d) to main Co-authored-by: microsoft <[email protected]>
1 parent 6773072 commit e0080d1

File tree

95 files changed

+1981
-1689
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1981
-1689
lines changed

AL-Go-Helper.ps1

+99-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ $defaultCICDPushBranches = @( 'main', 'release/*', 'feature/*' )
1919
$defaultCICDPullRequestBranches = @( 'main' )
2020
$runningLocal = $local.IsPresent
2121
$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/"
2322
$notSecretProperties = @("Scopes","TenantId","BlobName","ContainerName","StorageAccountName","ServerUrl","ppUserName")
2423

2524
$runAlPipelineOverrides = @(
@@ -631,13 +630,19 @@ function ReadSettings {
631630
"cacheImageName" = "my"
632631
"cacheKeepDays" = 3
633632
"alwaysBuildAllProjects" = $false
634-
"microsoftTelemetryConnectionString" = $microsoftTelemetryConnectionString
633+
"microsoftTelemetryConnectionString" = "InstrumentationKey=cd2cc63e-0f37-4968-b99a-532411a314b8;IngestionEndpoint=https://northeurope-2.in.applicationinsights.azure.com/"
635634
"partnerTelemetryConnectionString" = ""
636635
"sendExtendedTelemetryToMicrosoft" = $false
637636
"environments" = @()
638637
"buildModes" = @()
639638
"useCompilerFolder" = $false
640639
"pullRequestTrigger" = "pull_request_target"
640+
"bcptThresholds" = [ordered]@{
641+
"DurationWarning" = 10
642+
"DurationError" = 25
643+
"NumberOfSqlStmtsWarning" = 5
644+
"NumberOfSqlStmtsError" = 10
645+
}
641646
"fullBuildPatterns" = @()
642647
"excludeEnvironments" = @()
643648
"alDoc" = [ordered]@{
@@ -1263,21 +1268,25 @@ function GetProjectFolders {
12631268
$projectFolders
12641269
}
12651270

1266-
function installModules {
1271+
function InstallModule {
12671272
Param(
1268-
[String[]] $modules
1273+
[String] $name,
1274+
[System.Version] $minimumVersion = $null
12691275
)
12701276

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)
12761279
}
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
12801287
}
1288+
Write-Host "Importing module $name (minimum version $minimumVersion)"
1289+
Import-Module -Name $name -MinimumVersion $minimumVersion -DisableNameChecking -WarningAction SilentlyContinue | Out-Null
12811290
}
12821291

12831292
function CloneIntoNewFolder {
@@ -1323,6 +1332,7 @@ function CommitFromNewFolder {
13231332
Param(
13241333
[string] $serverUrl,
13251334
[string] $commitMessage,
1335+
[string] $body = $commitMessage,
13261336
[string] $branch
13271337
)
13281338

@@ -1351,7 +1361,7 @@ function CommitFromNewFolder {
13511361
}
13521362
invoke-git push -u $serverUrl $branch
13531363
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"
13551365
}
13561366
catch {
13571367
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 {
16571667

16581668
if (($settings.keyVaultName) -and -not ($bcAuthContext)) {
16591669
Write-Host "Reading Key Vault $($settings.keyVaultName)"
1660-
installModules -modules @('Az.KeyVault')
1670+
InstallAzModuleIfNeeded -name 'Az.KeyVault'
16611671

16621672
if ($kind -eq "local") {
16631673
$LicenseFileSecret = Get-AzKeyVaultSecret -VaultName $settings.keyVaultName -Name $settings.licenseFileUrlSecretName
@@ -2350,14 +2360,86 @@ function GetProjectsFromRepository {
23502360
return @(GetMatchingProjects -projects $projects -selectProjects $selectProjects)
23512361
}
23522362

2353-
function Get-PackageVersion($PackageName) {
2363+
function GetPackageVersion($packageName) {
23542364
$alGoPackages = Get-Content -Path "$PSScriptRoot\Packages.json" | ConvertFrom-Json
23552365

23562366
# 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"
23592369
}
23602370
else {
23612371
throw "Package $PackageName is not in the list of packages"
23622372
}
23632373
}
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

Comments
 (0)