Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function ModifyBuildWorkflows {
# Modify Deliver and Deploy steps depending on build jobs
if ($deploy) {
$deploy.Replace('needs:', "needs: [ $($needs -join ', ') ]")
$deploy.Replace('if:', "if: (!cancelled())$ifpart && needs.Initialization.outputs.environmentCount > 0")
$deploy.Replace('if:', "if: (!cancelled())$ifpart && fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environmentCount > 0")
$yaml.Replace('jobs:/Deploy:/', $deploy.content)
$postProcessNeeds += @('Deploy')
}
Expand Down
33 changes: 28 additions & 5 deletions Actions/Deploy/Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ Param(
[Parameter(HelpMessage = "Type of deployment (CD or Publish)", Mandatory = $false)]
[ValidateSet('CD','Publish')]
[string] $type = "CD",
[Parameter(HelpMessage = "The settings for all Deployment Environments", Mandatory = $true)]
[string] $deploymentEnvironmentsJson,
[Parameter(HelpMessage = "Artifacts version. Used to check if this is a deployment from a PR", Mandatory = $false)]
[string] $artifactsVersion = ''
)
Expand All @@ -18,13 +16,38 @@ Import-Module (Join-Path -Path $PSScriptRoot "Deploy.psm1")
. (Join-Path -Path $PSScriptRoot -ChildPath "..\AL-Go-Helper.ps1" -Resolve)
DownloadAndImportBcContainerHelper

$deploymentEnvironments = $deploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse
$deploymentSettings = $deploymentEnvironments."$environmentName"

$envName = $environmentName.Split(' ')[0]

# Default deployment settings
$deploymentSettings = @{
"EnvironmentType" = "SaaS"
"EnvironmentName" = $envName
"Projects" = @('*')
"DependencyInstallMode" = "install" # ignore, install, upgrade or forceUpgrade
"SyncMode" = $null
"Scope" = $null
"buildMode" = $null
"continuousDeployment" = $null
"companyId" = ''
"ppEnvironmentUrl" = ''
"includeTestAppsInSandboxEnvironment" = $false
"excludeAppIds" = @()
}

$secrets = $env:Secrets | ConvertFrom-Json
$settings = $env:Settings | ConvertFrom-Json

# If there is a deployTo<environamentName> settings, overwrite the default settings
$settingsName = "deployTo$($envName)"
if($settings.PSObject.Properties.Name -contains $settingsName) {
Write-Host "Using custom settings for environment $environmentName"

$customDeploymentSettings = $settings."$settingsName"
foreach ($key in $customDeploymentSettings.PSObject.Properties.Name) {
$deploymentSettings.$key = $customDeploymentSettings.$key
}
}

$authContext = $null
foreach($secretName in "$($envName)-AuthContext","$($envName)_AuthContext","AuthContext") {
if ($secrets."$secretName") {
Expand Down
1 change: 0 additions & 1 deletion Actions/Deploy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Deploy Apps to online environment
| environmentName | Yes | Name of environment to deploy to |
| artifactsFolder | Yes | Path to the downloaded artifacts to deploy | |
| type | | Type of delivery (CD or Release) | CD |
| deploymentEnvironmentsJson | Yes | The settings for all Deployment Environments | |

## OUTPUT

Expand Down
6 changes: 1 addition & 5 deletions Actions/Deploy/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ inputs:
description: Type of deployment (CD or Publish)
required: false
default: 'CD'
deploymentEnvironmentsJson:
description: The settings for all Deployment Environments
required: true
artifactsVersion:
description: Artifacts version. Used to check if this is a deployment from a PR
required: false
Expand All @@ -41,11 +38,10 @@ runs:
_environmentName: ${{ inputs.environmentName }}
_artifactsFolder: ${{ inputs.artifactsFolder }}
_type: ${{ inputs.type }}
_deploymentEnvironmentsJson: ${{ inputs.deploymentEnvironmentsJson }}
_artifactsVersion: ${{ inputs.artifactsVersion }}
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "Deploy" -Action {
${{ github.action_path }}/Deploy.ps1 -token $ENV:_token -environmentName $ENV:_environmentName -artifactsFolder $ENV:_artifactsFolder -type $ENV:_type -deploymentEnvironmentsJson $ENV:_deploymentEnvironmentsJson -artifactsVersion $ENV:_artifactsVersion
${{ github.action_path }}/Deploy.ps1 -token $ENV:_token -environmentName $ENV:_environmentName -artifactsFolder $ENV:_artifactsFolder -type $ENV:_type -artifactsVersion $ENV:_artifactsVersion
}
branding:
icon: terminal
Expand Down
1 change: 0 additions & 1 deletion Actions/DeployPowerPlatform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Deploy the Power Platform solution from the artifacts folder
| environmentName | Yes | Name of environment to deploy to |
| artifactsFolder | | Path to the downloaded artifacts to deploy (when deploying from a build) | |
| solutionFolder | | Path to the unpacked solutions to deploy (when deploying from branch) | |
| deploymentEnvironmentsJson | Yes | The settings for all Deployment Environments | |

Either artifactsFolder or solutionFolder needs to be specified

Expand Down
9 changes: 5 additions & 4 deletions Actions/DeployPowerPlatform/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ inputs:
description: Path to the unpacked solution to deploy (when deploying from branch)
required: false
default: ''
deploymentEnvironmentsJson:
description: The settings for all Deployment Environments
required: true
runs:
using: composite
steps:
Expand All @@ -42,12 +39,16 @@ runs:
ref: ${{ env.actionsRef }}
path: ${{ env.actionsPath }}

- name: Read settings
uses: ./_AL-Go/Actions/ReadSettings@main
with:
shell: ${{ matrix.shell }}

- name: Parse DeployToSettings and AuthContext
id: ReadPowerPlatformSettings
uses: ./_AL-Go/Actions/ReadPowerPlatformSettings
with:
shell: ${{ inputs.shell }}
deploymentEnvironmentsJson: ${{ inputs.deploymentEnvironmentsJson }}
environmentName: ${{ inputs.environmentName }}

- name: Determine Power Platform solution location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,40 +98,28 @@ $environments = @($ghEnvironments | ForEach-Object { $_.name }) + @($settings.en

Write-Host "Environments found: $($environments -join ', ')"

$deploymentEnvironments = @{}
$deploymentEnvironments = @{
"environments" = @();
"environmentCount" = 0
}
$unknownEnvironment = 0

if (!($environments)) {
# If no environments are defined and the user specified a single environment, use that environment
# This allows the user to specify a single environment without having to define it in the settings
if ($getenvironments -notcontains '*' -and $getenvironments -notcontains '?' -and $getenvironments -notcontains ',') {
$envName = $getEnvironments.Split(' ')[0]
$deploymentEnvironments += @{
"$getEnvironments" = @{
"EnvironmentType" = "SaaS"
"EnvironmentName" = $envName
"Branches" = $null
"BranchesFromPolicy" = @()
"Projects" = '*'
"DependencyInstallMode" = "install" # ignore, install, upgrade or forceUpgrade
"SyncMode" = $null
"Scope" = $null
"buildMode" = $null
"continuousDeployment" = !($getEnvironments -like '* (PROD)' -or $getEnvironments -like '* (Production)' -or $getEnvironments -like '* (FAT)' -or $getEnvironments -like '* (Final Acceptance Test)')
if ($getEnvironments -notcontains '*' -and $getEnvironments -notcontains '?' -and $getEnvironments -notcontains ',') {
$deploymentEnvironments.environments += @{
"environmentName" = $getEnvironments
"runs-on" = $settings."runs-on"
"shell" = $settings."shell"
"companyId" = ''
"ppEnvironmentUrl" = ''
"includeTestAppsInSandboxEnvironment" = $false
"excludeAppIds" = @()
}
}

$unknownEnvironment = 1
}
}
else {
foreach($environmentName in $environments) {
Write-Host "Environment: $environmentName"
Write-Host "Evaluating Environment for deployment: $environmentName"
$envName = $environmentName.Split(' ')[0]

# Check Obsolete Settings
Expand All @@ -142,31 +130,16 @@ else {
}

# Default Deployment settings are:
# - environment name: same
# - branches: main
# - projects: all
# - branches: empty (means all branches)
# - continuous deployment: only for environments not tagged with PROD or FAT
# - runs-on: same as settings."runs-on"
# - shell: same as settings."shell"
# - no companyId
# - no ppEnvironmentUrl
$deploymentSettings = @{
"EnvironmentType" = "SaaS"
"EnvironmentName" = $envName
"Branches" = @()
"BranchesFromPolicy" = @()
"Projects" = '*'
"DependencyInstallMode" = "install" # ignore, install, upgrade or forceUpgrade
"SyncMode" = $null
"Scope" = $null
"buildMode" = $null
"branches" = @()
"branchesFromPolicy" = @()
"continuousDeployment" = $null
"runs-on" = $settings."runs-on"
"shell" = $settings."shell"
"companyId" = ''
"ppEnvironmentUrl" = ''
"includeTestAppsInSandboxEnvironment" = $false
"excludeAppIds" = @()
}

# Check DeployTo<environmentName> setting
Expand All @@ -188,15 +161,8 @@ else {
Write-Host "::WARNING::The property $key in $settingsName is expected to be of type $($deploymentSettings."$key".GetType().Name)"
}
}
Write-Host "Property $key = $($deployTo."$key")"
$deploymentSettings."$key" = $deployTo."$key"
}
else {
$deploymentSettings += @{
"$key" = $deployTo."$key"
}
}

}
if ($deploymentSettings."shell" -ne 'pwsh' -and $deploymentSettings."shell" -ne 'powershell') {
throw "The shell setting in $settingsName must be either 'pwsh' or 'powershell'"
Expand All @@ -209,7 +175,7 @@ else {

# Get Branch policies on GitHub Environment
$ghEnvironment = $ghEnvironments | Where-Object { $_.name -eq $environmentName }
$deploymentSettings.BranchesFromPolicy = @(Get-BranchesFromPolicy -ghEnvironment $ghEnvironment)
$deploymentSettings.branchesFromPolicy = @(Get-BranchesFromPolicy -ghEnvironment $ghEnvironment)

# Include Environment if:
# - Type is not Continous Deployment
Expand Down Expand Up @@ -244,18 +210,18 @@ else {
}
elseif ($type -ne 'All') {
# Check whether any GitHub policy disallows this branch to deploy to this environment
if ($deploymentSettings.BranchesFromPolicy) {
if ($deploymentSettings.branchesFromPolicy) {
# Check whether GITHUB_REF_NAME is allowed to deploy to this environment
$includeEnvironment = $deploymentSettings.BranchesFromPolicy | Where-Object { $ENV:GITHUB_REF_NAME -like $_ }
if ($deploymentSettings.Branches -and $includeEnvironment) {
$includeEnvironment = $deploymentSettings.branchesFromPolicy | Where-Object { $ENV:GITHUB_REF_NAME -like $_ }
if ($deploymentSettings.branches -and $includeEnvironment) {
# Branches are also defined in settings for this environment - only include branches that also exists in settings
$includeEnvironment = $deploymentSettings.Branches | Where-Object { $ENV:GITHUB_REF_NAME -like $_ }
$includeEnvironment = $deploymentSettings.branches | Where-Object { $ENV:GITHUB_REF_NAME -like $_ }
}
}
else {
if ($deploymentSettings.Branches) {
if ($deploymentSettings.branches) {
# Branches are defined in settings for this environment - only include branches that exists in settings
$includeEnvironment = $deploymentSettings.Branches | Where-Object { $ENV:GITHUB_REF_NAME -like $_ }
$includeEnvironment = $deploymentSettings.branches | Where-Object { $ENV:GITHUB_REF_NAME -like $_ }
}
else {
# If no branch policies are defined in GitHub nor in settings - only allow main branch to deploy
Expand All @@ -266,30 +232,22 @@ else {
Write-Host "Environment $environmentName is not setup for deployments from branch $ENV:GITHUB_REF_NAME"
}
}

if ($includeEnvironment) {
$deploymentEnvironments += @{ "$environmentName" = $deploymentSettings }
# Dump Deployment settings for included environments
$deploymentSettings | ConvertTo-Json -Depth 99 | Out-Host
$deploymentEnvironments.environments += @{
"environmentName" = $environmentName
"runs-on" = "$(ConvertTo-Json -InputObject @($deploymentSettings."runs-on".Split(',').Trim()) -compress)"
"shell" = $deploymentSettings."shell"
}
}
}
}

# Calculate deployment matrix
$json = @{"matrix" = @{ "include" = @() }; "fail-fast" = $false }
$deploymentEnvironments.Keys | Sort-Object | ForEach-Object {
$deploymentEnvironment = $deploymentEnvironments."$_"
$json.matrix.include += @{ "environment" = $_; "os" = "$(ConvertTo-Json -InputObject @($deploymentEnvironment."runs-on".Split(',').Trim()) -compress)"; "shell" = $deploymentEnvironment."shell" }
}
$environmentsMatrixJson = $json | ConvertTo-Json -Depth 99 -compress
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "EnvironmentsMatrixJson=$environmentsMatrixJson"
Write-Host "EnvironmentsMatrixJson=$environmentsMatrixJson"
$deploymentEnvironments.environmentCount = $deploymentEnvironments.environments.Count

$deploymentEnvironmentsJson = ConvertTo-Json -InputObject $deploymentEnvironments -Depth 99 -Compress
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "DeploymentEnvironmentsJson=$deploymentEnvironmentsJson"
Write-Host "DeploymentEnvironmentsJson=$deploymentEnvironmentsJson"

Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "EnvironmentCount=$($deploymentEnvironments.Keys.Count)"
Write-Host "EnvironmentCount=$($deploymentEnvironments.Keys.Count)"

Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "UnknownEnvironment=$unknownEnvironment"
Write-Host "UnknownEnvironment=$unknownEnvironment"
4 changes: 1 addition & 3 deletions Actions/DetermineDeploymentEnvironments/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ Determines the environments to be used for a build or a publish

## OUTPUT

| EnvironmentsMatrixJson | The Environment matrix to use for the Deploy step in compressed JSON format |
| DeploymentEnvironmentsJson | Deployment Environments with settings in compressed JSON format |
| EnvironmentCount | Number of Deployment Environments |
| DeploymentEnvironmentsJson | The JSON representation of the environment that are suitable for deployment |
| UnknownEnvironment | Flag determining whether we try to publish to an unknown environment (invoke device code flow) |
| GenerateALDocArtifact | Flag determining whether to generate the ALDoc artifact |
| DeployALDocArtifact | Flag determining whether to deploy the ALDoc artifact to GitHub Pages |
Expand Down
8 changes: 1 addition & 7 deletions Actions/DetermineDeploymentEnvironments/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,9 @@ inputs:
description: Type of deployment (CD, Publish or All)
required: true
outputs:
EnvironmentsMatrixJson:
description: The Environment matrix to use for the Deploy step in compressed JSON format
value: ${{ steps.determineDeploymentEnvironments.outputs.EnvironmentsMatrixJson }}
DeploymentEnvironmentsJson:
description: Deployment Environments with settings in compressed JSON format
description: The JSON representation of the environment that are suitable for deployment
value: ${{ steps.determineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }}
EnvironmentCount:
description: Number of Deployment Environments
value: ${{ steps.determineDeploymentEnvironments.outputs.EnvironmentCount }}
UnknownEnvironment:
description: Flag determining whether the environment is unknown
value: ${{ steps.determineDeploymentEnvironments.outputs.UnknownEnvironment }}
Expand Down
9 changes: 5 additions & 4 deletions Actions/PullPowerPlatformChanges/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ inputs:
description: Name of the solution to download and folder in which to download the solution
required: false
default: ''
deploymentEnvironmentsJson:
description: The settings for all Deployment Environments
required: true
updateBranch:
description: Set the branch to update
required: false
Expand Down Expand Up @@ -54,12 +51,16 @@ runs:
ref: ${{ env.actionsRef }}
path: ${{ env.actionsPath }}

- name: Read settings
uses: ./_AL-Go/Actions/ReadSettings@main
with:
shell: ${{ matrix.shell }}

- name: Parse DeployToSettings and AuthContext
id: ReadPowerPlatformSettings
uses: ./_AL-Go/Actions/ReadPowerPlatformSettings
with:
shell: ${{ inputs.shell }}
deploymentEnvironmentsJson: ${{ inputs.deploymentEnvironmentsJson }}
environmentName: ${{ inputs.environmentName }}

- name: Set up new branch for changes
Expand Down
1 change: 0 additions & 1 deletion Actions/ReadPowerPlatformSettings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Read settings for Power Platform deployment from settings and secrets
| Name | Required | Description | Default value |
| :-- | :-: | :-- | :-- |
| shell | | The shell (powershell or pwsh) in which the PowerShell script in this action should run | powershell |
| deploymentEnvironmentsJson | Yes | The settings for all Deployment Environments | |
| environmentName | Yes | Name of environment to deploy to | |

## OUTPUT
Expand Down
Loading
Loading