Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install dependencies #1225

Merged
merged 33 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
459a8fd
Install dependencies
freddydk Sep 27, 2024
3c5de06
tests and precommit
freddydk Sep 27, 2024
1d22653
test
freddydk Sep 27, 2024
9862608
re-read installed extensions
freddydk Sep 27, 2024
a58962e
comment
freddydk Sep 27, 2024
0c84806
use test containerhelper
freddydk Sep 27, 2024
a929e40
add .app
freddydk Sep 27, 2024
4aaa860
getappfiles
freddydk Sep 27, 2024
a2db01b
remove temp folder
freddydk Sep 27, 2024
c74e291
remove function
freddydk Sep 27, 2024
5c499ba
get fullname
freddydk Sep 27, 2024
716e911
warning
freddydk Sep 27, 2024
b3e8cd3
do not upgrade Dev Scope uploaded appsource apps
freddydk Sep 27, 2024
d71d2ad
warning
freddydk Sep 27, 2024
b6bfecb
warning
freddydk Sep 27, 2024
f2b8bb5
docs and release notes
freddydk Sep 27, 2024
b5c0247
use preview
freddydk Sep 27, 2024
df8c9fd
add to warning message
freddydk Sep 28, 2024
e6909a0
Merge branch 'main' into issue1215
freddydk Oct 4, 2024
48d1074
Merge branch 'main' into issue1215
freddydk Oct 7, 2024
7db6f9e
move release notes
freddydk Oct 7, 2024
32191cc
move
freddydk Oct 7, 2024
c119273
Merge branch 'main' into issue1215
freddydk Oct 8, 2024
01b2b9f
Merge branch 'main' into issue1215
freddydk Oct 11, 2024
7cddca7
review
freddydk Oct 14, 2024
f3255d6
review
freddydk Oct 14, 2024
4f55bf3
Merge branch 'main' into issue1215
freddydk Oct 23, 2024
2e6e5e0
Merge branch 'main' into issue1215
freddydk Oct 25, 2024
3d185ae
plings
freddydk Oct 28, 2024
3ccea30
Merge branch 'main' into issue1215
freddydk Oct 28, 2024
10ca4d3
Merge branch 'main' into issue1215
freddydk Oct 28, 2024
699d744
split out function
freddydk Oct 28, 2024
72fa78c
Merge branch 'main' into issue1215
freddydk Oct 29, 2024
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
169 changes: 136 additions & 33 deletions Actions/Deploy/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,85 @@ Param(
[string] $deploymentEnvironmentsJson
)

function InstallOrUpgradeApps {
Param(
[hashtable] $bcAuthContext,
[string] $environment,
[string[]] $apps,
[string] $installMode
)

$schemaSyncMode = 'Add'
if ($installMode -eq 'ForceUpgrade') {
freddydk marked this conversation as resolved.
Show resolved Hide resolved
$schemaSyncMode = 'Force'
$installMode = 'upgrade'
}
$tempPath = Join-Path ([System.IO.Path]::GetTempPath()) ([GUID]::NewGuid().ToString())
New-Item -ItemType Directory -Path $tempPath | Out-Null
try {
Copy-AppFilesToFolder -appFiles $apps -folder $tempPath | Out-Null
$apps = @(Get-ChildItem -Path $tempPath -Filter *.app | ForEach-Object { $_.FullName })
$installedApps = Get-BcInstalledExtensions -bcAuthContext $bcAuthContext -environment $environment | Where-Object { $_.isInstalled }
$PTEsToInstall = @()
# Run through all apps and install or upgrade AppSource apps first (and collect PTEs)
foreach($app in $apps) {
# Get AppJson (works for full .app files, symbol files and also runtime packages)
$appJson = Get-AppJsonFromAppFile -appFile $app
$isPTE = ($appjson.idRanges.from -lt 100000 -and $appjson.idRanges.from -ge 50000)
$installedApp = $installedApps | Where-Object { $_.id -eq $appJson.id }
$needsUpgrade = $false
$needsInstall = $false
if ($installedApp) {
$newVersion = [version]::new($appJson.Version)
freddydk marked this conversation as resolved.
Show resolved Hide resolved
$installedVersion = [version]::new($installedApp.versionMajor, $installedApp.versionMinor, $installedApp.versionBuild, $installedApp.versionRevision)
if ($newVersion -gt $installedVersion) {
$msg = "Dependency app $($appJson.name) is already installed in version $installedVersion, which is lower than $newVersion."
if ($installMode -eq 'upgrade') {
Write-Host "$msg Needs upgrade."
$needsUpgrade = $true
}
else {
Write-Host "::WARNING::$msg Set DependencyInstallMode to 'upgrade' or 'forceUpgrade' to upgrade dependencies."
freddydk marked this conversation as resolved.
Show resolved Hide resolved
}
}
elseif ($newVersion -lt $installedVersion) {
Write-Host "::WARNING::Dependency app $($appJson.name) is already installed in version $installedVersion, which is higher than $newVersion, used for this build. Please update your local copy of this dependency."
}
else {
Write-Host "Dependency app $($appJson.name) is already installed in version $installedVersion."
}
}
else {
Write-Host "Dependency app $($appJson.name) is not installed."
$needsInstall = $true
}
if ($needsUpgrade) {
if (-not $isPTE -and $installedApp.publishedAs.Trim() -eq 'Dev') {
Write-Host "::WARNING::Dependency AppSource App $($appJson.name) is published in Dev scoope. Cannot upgrade."
$needsUpgrade = $false
}
}
if ($needsUpgrade -or $needsInstall) {
if ($isPTE) {
$PTEsToInstall += $app
}
else {
Install-BcAppFromAppSource -bcAuthContext $bcAuthContext -environment $environment -appId $appJson.id -acceptIsvEula -installOrUpdateNeededDependencies
# Update installed apps list as dependencies may have changed / been installed
$installedApps = Get-BcInstalledExtensions -bcAuthContext $bcAuthContext -environment $environment | Where-Object { $_.isInstalled }
}
}
}
if ($PTEsToInstall) {
# Install or upgrade PTEs
Publish-PerTenantExtensionApps -bcAuthContext $bcAuthContext -environment $environment -appFiles $PTEsToInstall -SchemaSyncMode $schemaSyncMode
}
}
finally {
Remove-Item -Path $tempPath -Force -Recurse
}
}

. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
DownloadAndImportBcContainerHelper

Expand Down Expand Up @@ -41,13 +120,17 @@ if (-not $authContext) {
}

$apps = @()
$dependencies = @()
$artifactsFolder = Join-Path $ENV:GITHUB_WORKSPACE $artifactsFolder
if (Test-Path $artifactsFolder -PathType Container) {
$deploymentSettings.Projects.Split(',') | ForEach-Object {
$project = $_.Replace('\','_').Replace('/','_')
$refname = "$ENV:GITHUB_REF_NAME".Replace('/','_')
Write-Host "project '$project'"
$projectApps = @((Get-ChildItem -Path $artifactsFolder -Filter "$project-$refname-$($buildMode)Apps-*.*.*.*") | ForEach-Object { $_.FullName })
if ($deploymentSettings.DependencyInstallMode -ne "ignore") {
$dependencies += @((Get-ChildItem -Path $artifactsFolder -Filter "$project-$refname-$($buildMode)Dependencies-*.*.*.*") | ForEach-Object { $_.FullName })
}
if (!($projectApps)) {
if ($project -ne '*') {
throw "There are no artifacts present in $artifactsFolder matching $project-$refname-$($buildMode)Apps-<version>."
Expand All @@ -63,7 +146,21 @@ else {
}

Write-Host "Apps to deploy"
$apps | Out-Host
$apps | ForEach-Object {
Write-Host "- $([System.IO.Path]::GetFileName($_))"
}

if ($deploymentSettings.DependencyInstallMode -ne "ignore") {
Write-Host "Dependencies to $($deploymentSettings.DependencyInstallMode)"
if ($dependencies) {
$dependencies | ForEach-Object {
Write-Host "- $([System.IO.Path]::GetFileName($_))"
}
}
else {
Write-Host "- None"
}
}

Set-Location $ENV:GITHUB_WORKSPACE

Expand All @@ -74,6 +171,7 @@ if (Test-Path $customScript) {
"type" = $type
"AuthContext" = $authContext
"Apps" = $apps
"Dependencies" = $dependencies
} + $deploymentSettings
. $customScript -parameters $parameters
}
Expand Down Expand Up @@ -120,43 +218,48 @@ else {
# Continuous deployment is undefined in settings - we will not deploy to production environments
Write-Host "::Warning::Ignoring environment $($deploymentSettings.EnvironmentName), which is a production environment"
}
elseif ($scope -eq 'Dev') {
if (!$sandboxEnvironment) {
throw "Scope Dev is only valid for sandbox environments"
}
$parameters = @{
"bcAuthContext" = $bcAuthContext
"environment" = $deploymentSettings.EnvironmentName
"appFile" = $apps
else {
if ($dependencies) {
InstallOrUpgradeApps -bcAuthContext $bcAuthContext -environment $deploymentSettings.EnvironmentName -Apps $dependencies -installMode $deploymentSettings.DependencyInstallMode
}
if ($deploymentSettings.SyncMode) {
if (@('Add','ForceSync', 'Clean', 'Development') -notcontains $deploymentSettings.SyncMode) {
throw "Invalid SyncMode $($deploymentSettings.SyncMode) when deploying using the development endpoint. Valid values are Add, ForceSync, Development and Clean."
if ($scope -eq 'Dev') {
if (!$sandboxEnvironment) {
throw "Scope Dev is only valid for sandbox environments"
}
Write-Host "Using $($deploymentSettings.SyncMode)"
$parameters += @{ "SyncMode" = $deploymentSettings.SyncMode }
}
Write-Host "Publishing apps using development endpoint"
Publish-BcContainerApp @parameters -useDevEndpoint -checkAlreadyInstalled -excludeRuntimePackages -replacePackageId
}
else {
# Use automation API for production environments (Publish-PerTenantExtensionApps)
$parameters = @{
"bcAuthContext" = $bcAuthContext
"environment" = $deploymentSettings.EnvironmentName
"appFiles" = $apps
$parameters = @{
"bcAuthContext" = $bcAuthContext
"environment" = $deploymentSettings.EnvironmentName
"appFile" = $apps
}
if ($deploymentSettings.SyncMode) {
if (@('Add','ForceSync', 'Clean', 'Development') -notcontains $deploymentSettings.SyncMode) {
throw "Invalid SyncMode $($deploymentSettings.SyncMode) when deploying using the development endpoint. Valid values are Add, ForceSync, Development and Clean."
}
Write-Host "Using $($deploymentSettings.SyncMode)"
$parameters += @{ "SyncMode" = $deploymentSettings.SyncMode }
}
Write-Host "Publishing apps using development endpoint"
Publish-BcContainerApp @parameters -useDevEndpoint -checkAlreadyInstalled -excludeRuntimePackages -replacePackageId
}
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."
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."
}
Write-Host "Using $($deploymentSettings.SyncMode)"
$syncMode = $deploymentSettings.SyncMode
if ($syncMode -eq 'ForceSync') { $syncMode = 'Force' }
$parameters += @{ "SchemaSyncMode" = $syncMode }
}
Write-Host "Using $($deploymentSettings.SyncMode)"
$syncMode = $deploymentSettings.SyncMode
if ($syncMode -eq 'ForceSync') { $syncMode = 'Force' }
$parameters += @{ "SchemaSyncMode" = $syncMode }
Write-Host "Publishing apps using automation API"
Publish-PerTenantExtensionApps @parameters
}
Write-Host "Publishing apps using automation API"
Publish-PerTenantExtensionApps @parameters
}
}
catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ else {
"Branches" = @()
"BranchesFromPolicy" = @()
"Projects" = '*'
"DependencyInstallMode" = "install" # ignore, install, upgrade or forceUpgrade
"SyncMode" = $null
"Scope" = $null
"buildMode" = $null
Expand Down
3 changes: 2 additions & 1 deletion RELEASENOTES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### Issues

- Issue 1241 Increment Version Number might produce wrong app.json
- `deployTo<environment>` now has an additional property called DependencyInstallMode, which determines how dependencies are deployed if GenerateDependencyArtifact is true. Default value is `install` to install dependencies if not already installed. Other values are `ignore` for ignoring dependencies, `upgrade` for upgrading dependencies if possible and `forceUpgrade` for force upgrading dependencies.

### New Project Settings

Expand Down Expand Up @@ -673,7 +674,7 @@ Setting the repo setting "runs-on" to "Ubuntu-Latest", followed by running Updat
### CI/CD and Publish To New Environment

- Base functionality for selecting a specific GitHub runner for an environment
- Include dependencies artifacts when deploying (if generateDependencyArtifacts is true)
- Include dependencies artifacts when deploying (if generateDependencyArtifact is true)

### localDevEnv.ps1 and cloudDevEnv.ps1

Expand Down
Loading
Loading