Skip to content

Commit f16d6c5

Browse files
authored
Check if apps are already installed on a higher version before deploying (#1756)
Emit warnings when apps are installed on a higher version when deploying. Issue #1722
1 parent 7617069 commit f16d6c5

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

Actions/Deploy/Deploy.ps1

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,32 @@ function CheckIfAppNeedsInstallOrUpgrade {
5050
return $needsInstall, $needsUpgrade
5151
}
5252

53+
# Check if the apps are already installed and emit a warning if the installed version is higher than the version in the app file
54+
function CheckInstalledApps {
55+
Param(
56+
[hashtable] $bcAuthContext,
57+
[string] $environment,
58+
[string[]] $appFiles
59+
)
60+
61+
$installedApps = Get-BcInstalledExtensions -bcAuthContext $bcAuthContext -environment $environment | Where-Object { $_.isInstalled }
62+
foreach($appFile in $appFiles) {
63+
# Get AppJson (works for full .app files, symbol files and also runtime packages)
64+
$appJson = Get-AppJsonFromAppFile -appFile $appFile
65+
$installedApp = $installedApps | Where-Object { $_.id -eq $appJson.id }
66+
67+
# Check if the version of the installed app is lower than the version in the app file
68+
if ($installedApp) {
69+
$currentVersion = [version]::new($appJson.Version)
70+
$installedVersion = [version]::new($installedApp.versionMajor, $installedApp.versionMinor, $installedApp.versionBuild, $installedApp.versionRevision)
71+
72+
if ($currentVersion -lt $installedVersion) {
73+
Write-Host "::WARNING::App $($appJson.name) is already installed in version $installedVersion, which is higher than $currentVersion, used in app.json. In order to install version $currentVersion, the higher version must be uninstalled first."
74+
}
75+
}
76+
}
77+
}
78+
5379
function InstallOrUpgradeApps {
5480
Param(
5581
[hashtable] $bcAuthContext,
@@ -403,6 +429,9 @@ else {
403429
if ($syncMode -eq 'ForceSync') { $syncMode = 'Force' }
404430
$parameters += @{ "SchemaSyncMode" = $syncMode }
405431
}
432+
433+
CheckInstalledApps -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName -appFiles $apps
434+
406435
Write-Host "Publishing apps using automation API"
407436
Publish-PerTenantExtensionApps @parameters
408437
}

RELEASENOTES.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ AL-Go now offers a dataexplorer dashboard to get started with AL-Go telemetry. A
55
### Issues
66

77
- Issue 1770 Wrong type of _projects_ setting in settings schema
8-
- Issue 1787: Publish to Environment from PR fails in private repos
8+
- Issue 1787 Publish to Environment from PR fails in private repos
9+
- Issue 1722 Check if apps are already installed on a higher version before deploying
910

1011
### Add custom jobs to AL-Go workflows
1112

0 commit comments

Comments
 (0)