diff --git a/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 b/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 index 83e79150aa..7d9a8d59d5 100644 --- a/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 +++ b/Actions/CheckForUpdates/CheckForUpdates.HelperFunctions.ps1 @@ -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') } diff --git a/Actions/Deploy/Deploy.ps1 b/Actions/Deploy/Deploy.ps1 index 8612105cd6..cdbb94b3bc 100644 --- a/Actions/Deploy/Deploy.ps1 +++ b/Actions/Deploy/Deploy.ps1 @@ -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 = '' ) @@ -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 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") { diff --git a/Actions/Deploy/README.md b/Actions/Deploy/README.md index c0fe51d2bc..a0a323180b 100644 --- a/Actions/Deploy/README.md +++ b/Actions/Deploy/README.md @@ -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 diff --git a/Actions/Deploy/action.yaml b/Actions/Deploy/action.yaml index 4e594444d3..0c5a5df7c6 100644 --- a/Actions/Deploy/action.yaml +++ b/Actions/Deploy/action.yaml @@ -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 @@ -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 diff --git a/Actions/DeployPowerPlatform/README.md b/Actions/DeployPowerPlatform/README.md index 25ed241547..a3f974d74d 100644 --- a/Actions/DeployPowerPlatform/README.md +++ b/Actions/DeployPowerPlatform/README.md @@ -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 diff --git a/Actions/DeployPowerPlatform/action.yaml b/Actions/DeployPowerPlatform/action.yaml index 68fc07ced4..d476e69148 100644 --- a/Actions/DeployPowerPlatform/action.yaml +++ b/Actions/DeployPowerPlatform/action.yaml @@ -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: @@ -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 diff --git a/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 b/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 index 0a27f9e422..75b406c4e7 100644 --- a/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 +++ b/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 @@ -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 @@ -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 setting @@ -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'" @@ -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 @@ -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 @@ -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" diff --git a/Actions/DetermineDeploymentEnvironments/README.md b/Actions/DetermineDeploymentEnvironments/README.md index 2a34e96c93..0678035596 100644 --- a/Actions/DetermineDeploymentEnvironments/README.md +++ b/Actions/DetermineDeploymentEnvironments/README.md @@ -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 | diff --git a/Actions/DetermineDeploymentEnvironments/action.yaml b/Actions/DetermineDeploymentEnvironments/action.yaml index d913710cb2..949232f432 100644 --- a/Actions/DetermineDeploymentEnvironments/action.yaml +++ b/Actions/DetermineDeploymentEnvironments/action.yaml @@ -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 }} diff --git a/Actions/PullPowerPlatformChanges/action.yaml b/Actions/PullPowerPlatformChanges/action.yaml index 46cd654a75..f51ea6883a 100644 --- a/Actions/PullPowerPlatformChanges/action.yaml +++ b/Actions/PullPowerPlatformChanges/action.yaml @@ -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 @@ -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 diff --git a/Actions/ReadPowerPlatformSettings/README.md b/Actions/ReadPowerPlatformSettings/README.md index c5f7324be6..c9ff8bb400 100644 --- a/Actions/ReadPowerPlatformSettings/README.md +++ b/Actions/ReadPowerPlatformSettings/README.md @@ -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 diff --git a/Actions/ReadPowerPlatformSettings/ReadPowerPlatformSettings.ps1 b/Actions/ReadPowerPlatformSettings/ReadPowerPlatformSettings.ps1 index dccab375ef..55fd241a80 100644 --- a/Actions/ReadPowerPlatformSettings/ReadPowerPlatformSettings.ps1 +++ b/Actions/ReadPowerPlatformSettings/ReadPowerPlatformSettings.ps1 @@ -1,6 +1,4 @@ param( - [Parameter(Mandatory = $true)] - [string] $deploymentEnvironmentsJson, [Parameter(Mandatory = $true)] [string] $environmentName ) @@ -8,17 +6,49 @@ $ErrorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-S $envName = $environmentName.Split(' ')[0] -# Read the deployment settings -$deploymentEnvironments = $deploymentEnvironmentsJson | ConvertFrom-Json -$deploymentSettings = $deploymentEnvironments."$environmentName" +$settings = $env:Settings | ConvertFrom-Json + +# 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" = @() +} + +# If there is a deployTo 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 + } +} foreach($property in 'ppEnvironmentUrl','companyId','environmentName') { - if ($deploymentSettings | Get-Member -MemberType Properties -name $property) { + if ($deploymentSettings.Keys -contains $property) { Write-Host "Setting $property" Add-Content -Encoding utf8 -Path $env:GITHUB_OUTPUT -Value "$property=$($deploymentSettings."$property")" } else { - throw "$envName setting must contain '$property' property" + throw "DeployTo$envName setting must contain '$property' property" # Defensive check + } +} + +# Make sure required settings are not empty +foreach($property in 'ppEnvironmentUrl','companyId','environmentName') { + if ([string]::IsNullOrWhiteSpace($deploymentSettings."$property")) { + throw "DeployTo$envName setting must contain '$property' property" } } @@ -27,7 +57,7 @@ $secrets = $env:Secrets | ConvertFrom-Json # Read the authentication context from secrets $authContext = $null foreach($secretName in "$($envName)-AuthContext","$($envName)_AuthContext","AuthContext") { - if ($secrets."$secretName") { + if ($secrets.PSObject.Properties.Name -contains "$secretName") { Write-Host "Setting authentication context from secret $secretName" $authContext = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($secrets."$secretName")) | ConvertFrom-Json 'ppTenantId','ppApplicationId','ppClientSecret','ppUserName','ppPassword' | ForEach-Object { diff --git a/Actions/ReadPowerPlatformSettings/action.yaml b/Actions/ReadPowerPlatformSettings/action.yaml index bbfabe9236..d13753408c 100644 --- a/Actions/ReadPowerPlatformSettings/action.yaml +++ b/Actions/ReadPowerPlatformSettings/action.yaml @@ -5,9 +5,6 @@ inputs: description: Shell in which you want to run the action (powershell or pwsh) required: false default: powershell - deploymentEnvironmentsJson: - description: The settings for all Deployment Environments - required: true environmentName: description: Name of environment to deploy to required: true @@ -43,11 +40,10 @@ runs: shell: ${{ inputs.shell }} id: ReadPowerPlatformSettings env: - _deploymentEnvironmentsJson: ${{ inputs.deploymentEnvironmentsJson }} _environmentName: ${{ inputs.environmentName }} run: | ${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "ReadPowerPlatformSettings" -Action { - ${{ github.action_path }}/ReadPowerPlatformSettings.ps1 -deploymentEnvironmentsJson $ENV:_deploymentEnvironmentsJson -environmentName $ENV:_environmentName + ${{ github.action_path }}/ReadPowerPlatformSettings.ps1 -environmentName $ENV:_environmentName } branding: icon: terminal diff --git a/Scenarios/settings.md b/Scenarios/settings.md index 533af9e23a..2e7c695e26 100644 --- a/Scenarios/settings.md +++ b/Scenarios/settings.md @@ -472,8 +472,8 @@ In the `needs` property, you specify which jobs should be complete before this j ``` Deploy: needs: [ Initialization, Build, CustomJob-PrepareDeploy ] - if: always() && needs.Build.result == 'Success' && needs.Initialization.outputs.environmentCount > 0 - strategy: ${{ fromJson(needs.Initialization.outputs.environmentsMatrixJson) }} + if: always() && needs.Build.result == 'Success' && fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environmentCount > 0 + strategy: ... ``` Custom jobs will be preserved when running Update AL-Go System Files. diff --git a/Templates/AppSource App/.github/workflows/CICD.yaml b/Templates/AppSource App/.github/workflows/CICD.yaml index a092ef20e7..5b26a9d505 100644 --- a/Templates/AppSource App/.github/workflows/CICD.yaml +++ b/Templates/AppSource App/.github/workflows/CICD.yaml @@ -31,9 +31,7 @@ jobs: runs-on: [ windows-latest ] outputs: telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }} - environmentsMatrixJson: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentsMatrixJson }} - environmentCount: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentCount }} - deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }} + DeploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }} generateALDocArtifact: ${{ steps.DetermineDeploymentEnvironments.outputs.GenerateALDocArtifact }} deployALDocArtifact: ${{ steps.DetermineDeploymentEnvironments.outputs.DeployALDocArtifact }} deliveryTargetsJson: ${{ steps.DetermineDeliveryTargets.outputs.DeliveryTargetsJson }} @@ -285,19 +283,22 @@ jobs: Deploy: needs: [ Initialization, Build ] - if: (!cancelled()) && (needs.Build.result == 'success' || needs.Build.result == 'skipped') && needs.Initialization.outputs.environmentCount > 0 - strategy: ${{ fromJson(needs.Initialization.outputs.environmentsMatrixJson) }} - runs-on: ${{ fromJson(matrix.os) }} - name: Deploy to ${{ matrix.environment }} + if: (!cancelled()) && (needs.Build.result == 'success' || needs.Build.result == 'skipped') && fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environmentCount > 0 + strategy: + matrix: + include: ${{ fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environments }} + fail-fast: false + runs-on: ${{ fromJson(matrix.runs-on) }} + name: Deploy to ${{ matrix.environmentName }} defaults: run: shell: ${{ matrix.shell }} environment: - name: ${{ matrix.environment }} + name: ${{ matrix.environmentName }} url: ${{ steps.Deploy.outputs.environmentUrl }} env: ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }} - ALGoEnvName: ${{ matrix.environment }} + ALGoEnvName: ${{ matrix.environmentName }} steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 @@ -317,7 +318,7 @@ jobs: id: envName run: | $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 - $envName = '${{ matrix.environment }}'.split(' ')[0] + $envName = '${{ matrix.environmentName }}'.split(' ')[0] Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName" - name: Read secrets @@ -335,10 +336,9 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: ${{ matrix.shell }} - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' type: 'CD' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} - name: Deploy to Power Platform if: env.type == 'PTE' && env.powerPlatformSolutionFolder != '' @@ -347,9 +347,8 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: powershell - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} Deliver: needs: [ Initialization, Build ] diff --git a/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml b/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml index 0f1021c8ac..fa1b91cbc5 100644 --- a/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml @@ -31,8 +31,6 @@ jobs: needs: [ ] runs-on: [ windows-latest ] outputs: - environmentsMatrixJson: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentsMatrixJson }} - environmentCount: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentCount }} deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }} deviceCode: ${{ steps.Authenticate.outputs.deviceCode }} telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }} @@ -72,7 +70,7 @@ jobs: if: steps.DetermineDeploymentEnvironments.outputs.UnknownEnvironment == 1 run: | $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 - $envName = '${{ fromJson(steps.DetermineDeploymentEnvironments.outputs.environmentsMatrixJson).matrix.include[0].environment }}'.split(' ')[0] + $envName = '${{ fromJson(steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson).environments[0].name }}'.split(' ')[0] Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName" - name: Read secrets @@ -119,20 +117,23 @@ jobs: Deploy: needs: [ Initialization ] - if: needs.Initialization.outputs.environmentCount > 0 - strategy: ${{ fromJson(needs.Initialization.outputs.environmentsMatrixJson) }} - runs-on: ${{ fromJson(matrix.os) }} - name: Deploy to ${{ matrix.environment }} + if: fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environmentCount > 0 + strategy: + matrix: + include: ${{ fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environments }} + fail-fast: false + runs-on: ${{ fromJson(matrix.runs-on) }} + name: Deploy to ${{ matrix.environmentName }} defaults: run: shell: ${{ matrix.shell }} environment: - name: ${{ matrix.environment }} + name: ${{ matrix.environmentName }} url: ${{ steps.Deploy.outputs.environmentUrl }} env: deviceCode: ${{ needs.Initialization.outputs.deviceCode }} ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }} - ALGoEnvName: ${{ matrix.environment }} + ALGoEnvName: ${{ matrix.environmentName }} steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 @@ -141,7 +142,7 @@ jobs: id: envName run: | $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 - $envName = '${{ matrix.environment }}'.split(' ')[0] + $envName = '${{ matrix.environmentName }}'.split(' ')[0] Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName" - name: Read settings @@ -172,10 +173,9 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: ${{ matrix.shell }} - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' type: 'Publish' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} artifactsVersion: ${{ github.event.inputs.appVersion }} - name: Deploy to Power Platform @@ -185,9 +185,8 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: ${{ matrix.shell }} - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} PostProcess: needs: [ Initialization, Deploy ] diff --git a/Templates/Per Tenant Extension/.github/workflows/CICD.yaml b/Templates/Per Tenant Extension/.github/workflows/CICD.yaml index 92302f7290..2a1cded056 100644 --- a/Templates/Per Tenant Extension/.github/workflows/CICD.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/CICD.yaml @@ -31,8 +31,6 @@ jobs: runs-on: [ windows-latest ] outputs: telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }} - environmentsMatrixJson: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentsMatrixJson }} - environmentCount: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentCount }} deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }} generateALDocArtifact: ${{ steps.DetermineDeploymentEnvironments.outputs.GenerateALDocArtifact }} deployALDocArtifact: ${{ steps.DetermineDeploymentEnvironments.outputs.DeployALDocArtifact }} @@ -217,7 +215,7 @@ jobs: parentTelemetryScopeJson: ${{ needs.Initialization.outputs.telemetryScopeJson }} project: ${{ needs.Initialization.outputs.powerPlatformSolutionFolder }} projectName: ${{ needs.Initialization.outputs.powerPlatformSolutionFolder }} - publishArtifacts: ${{ github.ref_name == 'main' || startswith(github.ref_name, 'release/') || startswith(github.ref_name, 'releases/') || needs.Initialization.outputs.deliveryTargetsJson != '[]' || needs.Initialization.outputs.environmentCount > 0 }} + publishArtifacts: ${{ github.ref_name == 'main' || startswith(github.ref_name, 'release/') || startswith(github.ref_name, 'releases/') || needs.Initialization.outputs.deliveryTargetsJson != '[]' || fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environmentCount > 0 }} CodeAnalysisUpload: needs: [ Initialization, Build ] @@ -299,19 +297,22 @@ jobs: Deploy: needs: [ Initialization, Build, BuildPP ] - if: (!cancelled()) && (needs.Build.result == 'success' || needs.Build.result == 'skipped') && (needs.BuildPP.result == 'success' || needs.BuildPP.result == 'skipped') && needs.Initialization.outputs.environmentCount > 0 - strategy: ${{ fromJson(needs.Initialization.outputs.environmentsMatrixJson) }} - runs-on: ${{ fromJson(matrix.os) }} - name: Deploy to ${{ matrix.environment }} + if: (!cancelled()) && (needs.Build.result == 'success' || needs.Build.result == 'skipped') && (needs.BuildPP.result == 'success' || needs.BuildPP.result == 'skipped') && fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environmentCount > 0 + strategy: + matrix: + include: ${{ fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environments }} + fail-fast: false + runs-on: ${{ fromJson(matrix.runs-on) }} + name: Deploy to ${{ matrix.environmentName }} defaults: run: shell: ${{ matrix.shell }} environment: - name: ${{ matrix.environment }} + name: ${{ matrix.environmentName }} url: ${{ steps.Deploy.outputs.environmentUrl }} env: ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }} - ALGoEnvName: ${{ matrix.environment }} + ALGoEnvName: ${{ matrix.environmentName }} steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 @@ -331,7 +332,7 @@ jobs: id: envName run: | $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 - $envName = '${{ matrix.environment }}'.split(' ')[0] + $envName = '${{ matrix.environmentName }}'.split(' ')[0] Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName" - name: Read secrets @@ -349,10 +350,9 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: ${{ matrix.shell }} - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' type: 'CD' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} - name: Deploy to Power Platform if: env.type == 'PTE' && env.powerPlatformSolutionFolder != '' @@ -361,9 +361,8 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: powershell - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} Deliver: needs: [ Initialization, Build, BuildPP ] diff --git a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml index 0f1021c8ac..fa1b91cbc5 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml @@ -31,8 +31,6 @@ jobs: needs: [ ] runs-on: [ windows-latest ] outputs: - environmentsMatrixJson: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentsMatrixJson }} - environmentCount: ${{ steps.DetermineDeploymentEnvironments.outputs.EnvironmentCount }} deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson }} deviceCode: ${{ steps.Authenticate.outputs.deviceCode }} telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }} @@ -72,7 +70,7 @@ jobs: if: steps.DetermineDeploymentEnvironments.outputs.UnknownEnvironment == 1 run: | $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 - $envName = '${{ fromJson(steps.DetermineDeploymentEnvironments.outputs.environmentsMatrixJson).matrix.include[0].environment }}'.split(' ')[0] + $envName = '${{ fromJson(steps.DetermineDeploymentEnvironments.outputs.DeploymentEnvironmentsJson).environments[0].name }}'.split(' ')[0] Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName" - name: Read secrets @@ -119,20 +117,23 @@ jobs: Deploy: needs: [ Initialization ] - if: needs.Initialization.outputs.environmentCount > 0 - strategy: ${{ fromJson(needs.Initialization.outputs.environmentsMatrixJson) }} - runs-on: ${{ fromJson(matrix.os) }} - name: Deploy to ${{ matrix.environment }} + if: fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environmentCount > 0 + strategy: + matrix: + include: ${{ fromJson(needs.Initialization.outputs.deploymentEnvironmentsJson).environments }} + fail-fast: false + runs-on: ${{ fromJson(matrix.runs-on) }} + name: Deploy to ${{ matrix.environmentName }} defaults: run: shell: ${{ matrix.shell }} environment: - name: ${{ matrix.environment }} + name: ${{ matrix.environmentName }} url: ${{ steps.Deploy.outputs.environmentUrl }} env: deviceCode: ${{ needs.Initialization.outputs.deviceCode }} ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }} - ALGoEnvName: ${{ matrix.environment }} + ALGoEnvName: ${{ matrix.environmentName }} steps: - name: Checkout uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 @@ -141,7 +142,7 @@ jobs: id: envName run: | $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 - $envName = '${{ matrix.environment }}'.split(' ')[0] + $envName = '${{ matrix.environmentName }}'.split(' ')[0] Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "envName=$envName" - name: Read settings @@ -172,10 +173,9 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: ${{ matrix.shell }} - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' type: 'Publish' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} artifactsVersion: ${{ github.event.inputs.appVersion }} - name: Deploy to Power Platform @@ -185,9 +185,8 @@ jobs: Secrets: '${{ steps.ReadSecrets.outputs.Secrets }}' with: shell: ${{ matrix.shell }} - environmentName: ${{ matrix.environment }} + environmentName: ${{ matrix.environmentName }} artifactsFolder: '.artifacts' - deploymentEnvironmentsJson: ${{ needs.Initialization.outputs.deploymentEnvironmentsJson }} PostProcess: needs: [ Initialization, Deploy ] diff --git a/Templates/Per Tenant Extension/.github/workflows/PullPowerPlatformChanges.yaml b/Templates/Per Tenant Extension/.github/workflows/PullPowerPlatformChanges.yaml index df85744d34..783c16dd53 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PullPowerPlatformChanges.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PullPowerPlatformChanges.yaml @@ -98,7 +98,6 @@ jobs: directCommit: ${{ inputs.directCommit }} environmentName: ${{ inputs.environment }} solutionFolder: ${{ env.solutionFolder }} - deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.deploymentEnvironmentsJson }} - name: Finalize the workflow if: always() diff --git a/Templates/Per Tenant Extension/.github/workflows/PushPowerPlatformChanges.yaml b/Templates/Per Tenant Extension/.github/workflows/PushPowerPlatformChanges.yaml index 51ccd5c6b9..a2616d9576 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PushPowerPlatformChanges.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PushPowerPlatformChanges.yaml @@ -87,7 +87,6 @@ jobs: shell: powershell environmentName: ${{ inputs.environment }} solutionFolder: ${{ env.solutionFolder }} - deploymentEnvironmentsJson: ${{ steps.DetermineDeploymentEnvironments.outputs.deploymentEnvironmentsJson }} - name: Finalize the workflow if: always() diff --git a/Tests/DetermineDeploymentEnvironments.Test.ps1 b/Tests/DetermineDeploymentEnvironments.Test.ps1 index dd28dd7757..93132b3f45 100644 --- a/Tests/DetermineDeploymentEnvironments.Test.ps1 +++ b/Tests/DetermineDeploymentEnvironments.Test.ps1 @@ -38,9 +38,7 @@ Describe "DetermineDeploymentEnvironments Action Test" { It 'Test action.yaml matches script' { $outputs = [ordered]@{ - "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 the environment is unknown" "GenerateALDocArtifact" = "Flag determining whether to generate the ALDoc artifact" "DeployALDocArtifact" = "Flag determining whether to deploy the ALDoc artifact to GitHub Pages" @@ -57,15 +55,28 @@ Describe "DetermineDeploymentEnvironments Action Test" { $env:Settings = @{ "type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' ); "alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false } } | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh"};@{"environment"="test";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false} - $DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"test"=@{"EnvironmentType"="SaaS";"EnvironmentName"="test";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()};"another"=@{"EnvironmentType"="SaaS";"EnvironmentName"="another";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}} - $EnvironmentCount | Should -Be 2 - . (Join-Path $scriptRoot $scriptName) -getEnvironments 'test' -type 'CD' + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 2 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + $deploymentEnvironments.environments[1].environmentName | Should -Be 'another' + $deploymentEnvironments.environments[1].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[1].shell | Should -Be 'pwsh' + + . (Join-Path $scriptRoot $scriptName) -getEnvironments 'test' -type 'CD' PassGeneratedOutput - $EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="test";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false} - $DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"test"=@{"EnvironmentType"="SaaS";"EnvironmentName"="test";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}} - $EnvironmentCount | Should -Be 1 + + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' } # 2 environments defined in GitHub - one with branch policy = protected branches @@ -78,16 +89,32 @@ Describe "DetermineDeploymentEnvironments Action Test" { } $env:Settings = @{ "type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' ); "alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false } } | ConvertTo-Json -Compress + + $env:GITHUB_REF_NAME = 'main' # This is not a protected branch, so the _test_ environment should not be included, while _another_ environment should be included (no branch policy) . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false} - $DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"another"=@{"EnvironmentType"="SaaS";"EnvironmentName"="another";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}} - $EnvironmentCount | Should -Be 1 + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'another' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + Set-Variable -Name deploymentEnvironments -Value $null # clean up variable - $env:GITHUB_REF_NAME = 'branch' + $env:GITHUB_REF_NAME = 'branch' # This is a protected branch, so the _test_ environment should be included. _another_ environment should not be included as it has no branch policy (in that case deployment is only allowed from _main_ branch) . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + Set-Variable -Name deploymentEnvironments -Value $null # clean up variable } # 2 environments defined in GitHub - one with branch policy = branch. the other with no branch policy @@ -104,26 +131,47 @@ Describe "DetermineDeploymentEnvironments Action Test" { $env:Settings = @{ "type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @(); "excludeEnvironments" = @( 'github-pages' ); "alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false } } | ConvertTo-Json -Compress # Only another environment should be included when deploying from main + + $env:GITHUB_REF_NAME = 'main' # This is not a protected branch, so the _test_ environment should not be included, while _another_ environment should be included (no branch policy) . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"matrix"=@{"include"=@(@{"environment"="another";"os"="[""ubuntu-latest""]";"shell"="pwsh"})};"fail-fast"=$false} - $DeploymentEnvironmentsJson | ConvertFrom-Json | ConvertTo-HashTable -recurse | Should -MatchHashtable @{"another"=@{"EnvironmentType"="SaaS";"EnvironmentName"="another";"Branches"=@();"BranchesFromPolicy"=@();"Projects"="*";"DependencyInstallMode"="install";"Scope"=$null;"syncMode"=$null;"buildMode"=$null;"continuousDeployment"=$null;"runs-on"=@("ubuntu-latest");"shell"="pwsh";"ppEnvironmentUrl"="";"companyId"="";"includeTestAppsInSandboxEnvironment"=$false;"excludeAppIds"=@()}} - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "another" + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'another' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + Set-Variable -Name deploymentEnvironments -Value $null # clean up variable - # Change branch to branch - now only test environment should be included (due to branch policy) - $env:GITHUB_REF_NAME = 'branch' + + $env:GITHUB_REF_NAME = 'branch' # Change branch to _branch_ - now only test environment should be included (due to branch policy) . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "test" + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + Set-Variable -Name deploymentEnvironments -Value $null # clean up variable + - # Change branch to branch2 - test environment should still be included (due to branch policy) - $env:GITHUB_REF_NAME = 'branch2' + $env:GITHUB_REF_NAME = 'branch2' # Change branch to branch2 - test environment should still be included (due to branch policy) . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "test" + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + Set-Variable -Name deploymentEnvironments -Value $null # clean up variable # Add Branch policy to settings to only allow branch to deploy to test environment - now no environments should be included $settings += @{ @@ -134,14 +182,24 @@ Describe "DetermineDeploymentEnvironments Action Test" { $env:Settings = $settings | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 0 + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 0 + $deploymentEnvironments.environments | Should -BeNullOrEmpty + Set-Variable -Name deploymentEnvironments -Value $null # clean up variable # Change branch to branch - test environment should still be included (due to branch policy) $env:GITHUB_REF_NAME = 'branch' . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "test" + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' } # 2 environments defined in GitHub, 1 in settings - exclude another environment @@ -152,36 +210,82 @@ Describe "DetermineDeploymentEnvironments Action Test" { $settings = @{ "type" = "PTE"; "runs-on" = "ubuntu-latest"; "shell" = "pwsh"; "environments" = @("settingsenv"); "excludeEnvironments" = @( 'github-pages' ); "alDoc" = @{ "continuousDeployment" = $false; "deployToGitHubPages" = $false } } $env:Settings = $settings | ConvertTo-Json -Compress + + # All 3 environments should be included . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 3 - # Exclude another environment + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 3 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 3 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + $deploymentEnvironments.environments[1].environmentName | Should -Be 'another' + $deploymentEnvironments.environments[1].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[1].shell | Should -Be 'pwsh' + $deploymentEnvironments.environments[2].environmentName | Should -Be 'settingsenv' + $deploymentEnvironments.environments[2].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[2].shell | Should -Be 'pwsh' + Set-Variable -Name deploymentEnvironments -Value $null # clean up variable + + + # Exclude _another_ environment $settings.excludeEnvironments += @('another') $env:Settings = $settings | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 2 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Not -Contain "another" - # Add Branch policy to settings to only allow branch to deploy to test environment + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 2 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 2 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + $deploymentEnvironments.environments[1].environmentName | Should -Be 'settingsenv' + $deploymentEnvironments.environments[1].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[1].shell | Should -Be 'pwsh' + + # Add Branch policy to settings to only allow branch to deploy to _test_ environment $settings += @{ "DeployToTest" = @{ "Branches" = @("branch") } } + $settings.excludeEnvironments = @() # Clear exclude environments + $env:GITHUB_REF_NAME = 'main' $env:Settings = $settings | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "settingsenv" + + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 2 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 2 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'another' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' + $deploymentEnvironments.environments[1].environmentName | Should -Be 'settingsenv' + $deploymentEnvironments.environments[1].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[1].shell | Should -Be 'pwsh' # Changing branch to branch - now only test environment should be included (due to settings branch policy) $env:GITHUB_REF_NAME = 'branch' . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "test" + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' } # 2 environments defined in Settings - one PROD and one non-PROD (name based) @@ -195,15 +299,29 @@ Describe "DetermineDeploymentEnvironments Action Test" { $env:Settings = $settings | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "another" + + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'another' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' # Publish to test environment - test is included $env:Settings = $settings | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments 'test' -type 'Publish' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "test (PROD)" + + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test (PROD)' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' } # 2 environments defined in Settings - one PROD and one non-PROD (settings based) @@ -227,14 +345,27 @@ Describe "DetermineDeploymentEnvironments Action Test" { $env:Settings = $settings | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments '*' -type 'CD' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "another" + + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'another' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' # Publish to test environment - test is included $env:Settings = $settings | ConvertTo-Json -Compress . (Join-Path $scriptRoot $scriptName) -getEnvironments 'test' -type 'Publish' PassGeneratedOutput - $EnvironmentCount | Should -Be 1 - ($EnvironmentsMatrixJson | ConvertFrom-Json | ConvertTo-HashTable -recurse).matrix.include.environment | Should -Contain "test (PROD)" + $deploymentEnvironments = $DeploymentEnvironmentsJson | ConvertFrom-Json + $deploymentEnvironments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environmentCount | Should -Be 1 + $deploymentEnvironments.environments | Should -Not -BeNullOrEmpty + $deploymentEnvironments.environments.Count | Should -Be 1 + $deploymentEnvironments.environments[0].environmentName | Should -Be 'test (PROD)' + $deploymentEnvironments.environments[0].'runs-on' | Should -Be '["ubuntu-latest"]' + $deploymentEnvironments.environments[0].shell | Should -Be 'pwsh' } } diff --git a/Tests/ReadPowerPlatformSettings.Action.Test.ps1 b/Tests/ReadPowerPlatformSettings.Action.Test.ps1 index 4dae598dc1..cacb1101c0 100644 --- a/Tests/ReadPowerPlatformSettings.Action.Test.ps1 +++ b/Tests/ReadPowerPlatformSettings.Action.Test.ps1 @@ -17,7 +17,7 @@ Describe "Read Power Platform Settings Action Tests" { [Parameter(Mandatory = $true)] [hashtable] $deployToDevProperties ) - return @{ + $env:Settings = @{ type = "PTE" powerPlatformSolutionFolder = "CoffeMR" DeployToDev = $deployToDevProperties @@ -30,12 +30,11 @@ Describe "Read Power Platform Settings Action Tests" { [hashtable] $secretProperties ) $testSecret = $secretProperties | ConvertTo-Json - $env:Secrets = '{"DeployToDev-AuthContext": "' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($testSecret)) + '"}' + $env:Secrets = '{"Dev-AuthContext": "' + [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($testSecret)) + '"}' } } BeforeEach { - Write-Host "Before test" $env:GITHUB_OUTPUT = [System.IO.Path]::GetTempFileName() $env:GITHUB_ENV = [System.IO.Path]::GetTempFileName() @@ -46,7 +45,6 @@ Describe "Read Power Platform Settings Action Tests" { } AfterEach { - Write-Host "After test" Remove-Item -Path $env:GITHUB_OUTPUT -Force Remove-Item -Path $env:GITHUB_ENV -Force @@ -60,7 +58,7 @@ Describe "Read Power Platform Settings Action Tests" { companyId = "11111111-1111-1111-1111-111111111111" ppEnvironmentUrl = "https://TestUrL.crm.dynamics.com" } - $jsonInput = ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties + ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties # Setup secrets as GitHub environment variable $secretProperties = @{ @@ -71,7 +69,7 @@ Describe "Read Power Platform Settings Action Tests" { SetSecretsEnvVariable -secretProperties $secretProperties # Run the action - ReadPowerPlatformSettings -deploymentEnvironmentsJson $jsonInput -environmentName "DeployToDev" + . (Join-Path $scriptRoot $scriptName) -environmentName "Dev" # Assert the GitHub environment variables are set correctly $gitHubEnvPlaceholder = Get-Content -Path $env:GITHUB_OUTPUT @@ -90,7 +88,7 @@ Describe "Read Power Platform Settings Action Tests" { companyId = "11111111-1111-1111-1111-111111111111" ppEnvironmentUrl = "https://TestUrL.crm.dynamics.com" } - $jsonInput = ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties + ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties # Setup secrets as GitHub environment variable $secretProperties = @{ @@ -100,7 +98,7 @@ Describe "Read Power Platform Settings Action Tests" { SetSecretsEnvVariable -secretProperties $secretProperties # Run the action - ReadPowerPlatformSettings -deploymentEnvironmentsJson $jsonInput -environmentName "DeployToDev" + . (Join-Path $scriptRoot $scriptName) -environmentName "Dev" # Assert the GitHub environment variables are set correctly $gitHubEnvPlaceholder = Get-Content -Path $env:GITHUB_OUTPUT @@ -117,14 +115,13 @@ Describe "Read Power Platform Settings Action Tests" { param ( [hashtable] $deployToDevProperties ) - # Convert hashtables to JSON strings - $jsonInput = ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties + ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties $errorObject = $null $HasThrownException = $false # Run the action try { - ReadPowerPlatformSettings -deploymentEnvironmentsJson $jsonInput -environmentName "DeployToDev" + . (Join-Path $scriptRoot $scriptName) -environmentName "Dev" } catch { $errorObject = $_ @@ -141,6 +138,7 @@ Describe "Read Power Platform Settings Action Tests" { companyId = "11111111-1111-1111-1111-111111111111" } $errorMessage = runMissingSettingsTest -deployToDevProperties $deployToDevProperties + Write-Host "Settings are: $($env:Settings)" $errorMessage | Should -Be "DeployToDev setting must contain 'ppEnvironmentUrl' property" # Test missing companyId @@ -150,15 +148,6 @@ Describe "Read Power Platform Settings Action Tests" { } $errorMessage = runMissingSettingsTest -deployToDevProperties $deployToDevProperties $errorMessage | Should -Be "DeployToDev setting must contain 'companyId' property" - - # Test missing environmentName - $deployToDevProperties = @{ - companyId = "11111111-1111-1111-1111-111111111111" - ppEnvironmentUrl = "https://TestUrL.crm.dynamics.com" - } - $errorMessage = runMissingSettingsTest -deployToDevProperties $deployToDevProperties - $errorMessage | Should -Be "DeployToDev setting must contain 'environmentName' property" - } It 'Fails if required secret settings are missing' { @@ -169,13 +158,13 @@ Describe "Read Power Platform Settings Action Tests" { companyId = "11111111-1111-1111-1111-111111111111" ppEnvironmentUrl = "https://TestUrL.crm.dynamics.com" } - # Convert hashtables to JSON strings - $jsonInput = ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties + + ConvertToDeployToSettings -deployToDevProperties $deployToDevProperties $errorObject = $null # Run the action try { - ReadPowerPlatformSettings -deploymentEnvironmentsJson $jsonInput -environmentName "DeployToDev" + . (Join-Path $scriptRoot $scriptName) -environmentName "Dev" } catch { $errorObject = $_ @@ -193,7 +182,7 @@ Describe "Read Power Platform Settings Action Tests" { } SetSecretsEnvVariable -secretProperties $secretProperties $errorMessage = runMissingSecretsTest - $errorMessage | Should -Be "Secret DeployToDev-AuthContext must contain either 'ppUserName' and 'ppPassword' properties or 'ppApplicationId', 'ppClientSecret' and 'ppTenantId' properties" + $errorMessage | Should -Be "Secret Dev-AuthContext must contain either 'ppUserName' and 'ppPassword' properties or 'ppApplicationId', 'ppClientSecret' and 'ppTenantId' properties" # Test secret missing username @@ -202,7 +191,7 @@ Describe "Read Power Platform Settings Action Tests" { } SetSecretsEnvVariable -secretProperties $secretProperties $errorMessage = runMissingSecretsTest - $errorMessage | Should -Be "Secret DeployToDev-AuthContext must contain either 'ppUserName' and 'ppPassword' properties or 'ppApplicationId', 'ppClientSecret' and 'ppTenantId' properties" + $errorMessage | Should -Be "Secret Dev-AuthContext must contain either 'ppUserName' and 'ppPassword' properties or 'ppApplicationId', 'ppClientSecret' and 'ppTenantId' properties" }