Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
500 changes: 500 additions & 0 deletions Actions/.Modules/AdminCenterApi.psm1

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Actions/.Modules/ReadSettings.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ function GetDefaultSettings
}
"pullRequestTrigger" = "pull_request"
"skipDraftPullRequests" = $false
"adminCenterApi" = [ordered]@{
"baseUrl" = "https://api.businesscentral.dynamics.com"
"applicationFamily" = "BusinessCentral"
}
"bcptThresholds" = [ordered]@{
"DurationWarning" = 10
"DurationError" = 25
Expand Down
25 changes: 24 additions & 1 deletion Actions/.Modules/settings.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,29 @@
"description": "Schema for AL-Go settings",
"type": "object",
"properties": {
"adminCenterApi": {
"type": "object",
"default": {
"baseUrl": "https://api.businesscentral.dynamics.com",
"applicationFamily": "BusinessCentral"
},
"description": "Optional repository target for native Admin Center reads, PTE publishing and polling in the standard Deploy action in both templates (CI/CD and Publish To Environment). Independent of BcContainerHelper configuration. Does not change Automation, AppSource or web-client configuration. See https://aka.ms/ALGoSettings#adminCenterApi",
"properties": {
"baseUrl": {
"type": "string",
"default": "https://api.businesscentral.dynamics.com",
"pattern": "^(|https://[^\\s?#]+)$",
"description": "HTTPS API root without credentials, query or fragment. Defaults to https://api.businesscentral.dynamics.com; an explicit empty string also uses this endpoint. Sets the default resource for an isolated Admin authentication context; explicit AUTHCONTEXT scopes or resource are preserved."
},
"applicationFamily": {
"type": "string",
"minLength": 1,
"pattern": "\\S",
"default": "BusinessCentral",
"description": "Application family used by Admin Center installed-app reads, PTE publishing and operation polling. Never inferred from baseUrl. Automation URLs do not contain a family segment."
}
}
},
"type": {
"type": "string",
"minLength": 1,
Expand Down Expand Up @@ -990,7 +1013,7 @@
"unpublishOldVersions": {
"type": "boolean",
"default": false,
"description": "When set to true, AL-Go unpublishes old, uninstalled versions of the deployed apps from the environment after a successful deployment. Only applies to PTE deployments (Scope PTE) and is non-fatal. See https://aka.ms/ALGoSettings#deployto"
"description": "Optional boolean, default false. After successful Scope PTE deployment through Automation on Business Central 25.4 or later, unpublishes only selected primary apps' uninstalled versions older than the currently installed version, including apps skipped because the same or a newer version is installed. With the Admin Center route, explicit cleanup is skipped; Business Central manages background cleanup, whose timing and retained versions are not guaranteed. This setting does not control background cleanup. Skipped cleanup and cleanup failures are warnings; does not apply to Scope Dev or custom deployments. See https://aka.ms/ALGoSettings#deployto"
}
}
}
Expand Down
29 changes: 23 additions & 6 deletions Actions/Deploy/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Param(
)

Import-Module (Join-Path -Path $PSScriptRoot "Deploy.psm1")
Import-Module (Join-Path $PSScriptRoot '..\.Modules\AdminCenterApi.psm1') -DisableNameChecking
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
DownloadAndImportBcContainerHelper

Expand Down Expand Up @@ -167,6 +168,23 @@ else {
Write-Host "::Warning::Ignoring environment $($deploymentSettings.EnvironmentName), which is a production environment, as deploying from a PR is only supported in sandbox environments"
}
else {
$hasPTEDependencies = $false
if ($scope -eq 'Dev' -and $deploymentSettings.DependencyInstallMode -ne 'ignore') {
foreach ($dependency in $dependencies) {
$appJson = Get-AppJsonFromAppFile -appFile $dependency
if ($appJson.idRanges.from -ge 50000 -and $appJson.idRanges.from -lt 100000) {
Comment thread
spetersenms marked this conversation as resolved.
Resolved
$hasPTEDependencies = $true
break
}
}
}
if ($scope -eq 'PTE' -or $hasPTEDependencies) {
# This copy will eventually be replaced by AL-Go native auth.
$adminAuthContext = $bcAuthContext.Clone()
Initialize-AdminCenterAuthContext -authContext $adminAuthContext -settings $settings `
-preserveScopes:([bool]($authContextParams['scopes'] -or $authContextParams['resource']))
Initialize-PTEPublishingApi -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName
}
if ($dependencies) {
InstallOrUpgradeApps -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName -Apps $dependencies -installMode $deploymentSettings.DependencyInstallMode
}
Expand All @@ -193,15 +211,14 @@ else {
Publish-BcContainerApp @parameters -useDevEndpoint -checkAlreadyInstalled -excludeRuntimePackages -replacePackageId
}
else {
# Use automation API for production environments (Publish-PerTenantExtensionApps)
$parameters = @{
"bcAuthContext" = $bcAuthContext
"environment" = $deploymentSettings.EnvironmentName
"appFiles" = $apps
}
if ($deploymentSettings.SyncMode) {
if (@('Add','ForceSync') -notcontains $deploymentSettings.SyncMode) {
throw "Invalid SyncMode $($deploymentSettings.SyncMode) when deploying using the automation API. Valid values are Add and ForceSync."
throw "Invalid SyncMode $($deploymentSettings.SyncMode) when deploying Per Tenant Extensions. Valid values are Add and ForceSync."
}
Write-Host "Using $($deploymentSettings.SyncMode)"
$syncMode = $deploymentSettings.SyncMode
Expand All @@ -211,18 +228,18 @@ else {

CheckInstalledApps -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName -appFiles $apps

Write-Host "Publishing apps using automation API"
Publish-PerTenantExtensionApps @parameters
Write-Host "Publishing Per Tenant Extensions"
PublishPTEApps @parameters
Comment thread
spetersenms marked this conversation as resolved.
Resolved

if (($deploymentSettings['unpublishOldVersions'] -is [bool]) -and $deploymentSettings['unpublishOldVersions']) {
Write-Host "Unpublishing old app versions"
Write-Host "Checking cleanup of old app versions"
UnpublishOldAppVersions -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName -appFiles $apps
}
}
}
}
catch {
OutputError -message "Deploying to $environmentName failed.$([environment]::Newline) $($_.Exception.Message)"
OutputError -message "Deploying to $environmentName failed.$([environment]::Newline) $_"
exit
}
}
Loading
Loading