Skip to content

DeployTo setting supported as environment variable #1702

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

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
32b0ee6
Added env params to ReadSettings and logic to get DeployTo var from e…
spetersenms May 5, 2025
c26f52a
Added environmentName and environmentDeployToVariable value parms.
spetersenms May 5, 2025
27a2ab9
Added environmentName and environmentDeployToVariableValue params.
spetersenms May 5, 2025
a41820a
Passing new ReadSetting params in flows
spetersenms May 5, 2025
f5674c4
Precommit
spetersenms May 5, 2025
8df75d4
Adding token to ReadSettings action and passing to ReadSettings helper.
spetersenms May 6, 2025
23e0da8
Helper function to find deployment environment variables.
spetersenms May 6, 2025
053361f
Moving read deployment environment variable logic to DetermineDeploym…
spetersenms May 7, 2025
9647bf0
Merging DeployTo from settings file and env variable
spetersenms May 7, 2025
b0d2b95
Error handling
spetersenms May 7, 2025
401230d
Using ghTokenWorkflow for authenticating the variables api endpoint.
spetersenms May 8, 2025
3177598
Debug logs.
spetersenms May 8, 2025
afa11ce
Additional permissions for GITHUB_TOKEN
spetersenms May 8, 2025
e4f695f
Removed incorrect permission again.
spetersenms May 8, 2025
3a87b7b
Requesting needed permissions for api.
spetersenms May 8, 2025
3647d97
Updating permission param type to hashtable
spetersenms May 8, 2025
df0e312
Converting returned variable value from Json
spetersenms May 8, 2025
286680c
Converting to hashtable
spetersenms May 8, 2025
1599529
Removing debug logs
spetersenms May 8, 2025
dacf58b
Documentation updated.
spetersenms May 8, 2025
0728f17
Adjust deployment environment variable setting to take priority over …
spetersenms May 8, 2025
f6b5a31
Adding new param to app source yaml to match PTE flow.
spetersenms May 8, 2025
ba01203
pre-commit
spetersenms May 8, 2025
68fa02f
Mock variables api
spetersenms May 8, 2025
fa79500
Move url generation to try-catch for better error handling.
spetersenms May 8, 2025
449e009
Setting default value for ghTokenWorkflow to empty string.
spetersenms May 8, 2025
ff2175d
Adding test to verify that deployment environment variable takes prio…
spetersenms May 8, 2025
0f1fdde
Merge branch 'main' into DeployToEnvVar
spetersenms May 9, 2025
ed9c0aa
Merge branch 'DeployToEnvVar' of github.com:spetersenms/AL-Go into De…
spetersenms May 9, 2025
58f5538
Fixing missing variable in test.
spetersenms May 9, 2025
5f6d4b4
Passing ghTokenWorkflow to helper function.
spetersenms May 9, 2025
198e2b5
Debug comment removed.
spetersenms May 9, 2025
bbf6c54
Reverting changes to Init job.
spetersenms May 13, 2025
4332e5c
Printing warning if unsupported property is used in environment varia…
spetersenms May 15, 2025
dca4389
Reverting functionality to original state.
spetersenms May 19, 2025
1cc7766
Removed incorrect whitespace.
spetersenms May 19, 2025
aa2e709
Merge branch 'main' into DeployToEnvVar
spetersenms May 19, 2025
f59d583
Added back param accidentally removed while fixing conflict from merg…
spetersenms May 19, 2025
8998640
Reverting test changes.
spetersenms May 19, 2025
b0ba1f1
Added release notes.
spetersenms May 19, 2025
ae59ef9
Merge branch 'main' into DeployToEnvVar
spetersenms May 19, 2025
c166955
Merge branch 'main' into DeployToEnvVar
spetersenms Jun 16, 2025
fd1b9a4
Moved release notes.
spetersenms Jun 16, 2025
efbccd7
Merge branch 'main' into DeployToEnvVar
spetersenms Jun 16, 2025
c8aa5d1
Merge branch 'main' into DeployToEnvVar
spetersenms Jun 16, 2025
512eaf8
Merge branch 'main' into DeployToEnvVar
spetersenms Jun 17, 2025
e9cc5cd
Merge branch 'main' into DeployToEnvVar
spetersenms Jun 18, 2025
937cd81
Merge branch 'main' into DeployToEnvVar
spetersenms Jun 23, 2025
aeea15e
Readding logic accidentally removed during merge from main conflict h…
spetersenms Jun 23, 2025
e155e85
Using more generic name for environment settings, and testing use of …
spetersenms Jul 4, 2025
f5058b3
Moving env to step
spetersenms Jul 4, 2025
4349eaf
Trying to set env vars in new step.
spetersenms Jul 4, 2025
0cdd7a1
Corrected syntax.
spetersenms Jul 4, 2025
2e2b4fc
Compressing json.
spetersenms Jul 4, 2025
9b27b42
Forcing string type.
spetersenms Jul 4, 2025
055fd42
Single quotes instead of double
spetersenms Jul 4, 2025
0b38ecd
Using env variables instead of passing param.
spetersenms Jul 4, 2025
0eeec84
Removing all param passing of repo env variable and use passing as en…
spetersenms Jul 4, 2025
2dafad6
Merge branch 'main' into DeployToEnvVar
spetersenms Jul 7, 2025
4d94f33
Consistency across workflows.
spetersenms Jul 7, 2025
138fc2e
Aligning format of environment settings to be similar to org and repo…
spetersenms Jul 7, 2025
bfaf06f
Merge branch 'DeployToEnvVar' of github.com:spetersenms/AL-Go into De…
spetersenms Jul 7, 2025
a5649f6
Better formatting of warning.
spetersenms Jul 7, 2025
b63b47e
Typo.
spetersenms Jul 7, 2025
09c82fc
Using ALGoEnvironmentSettings instead of DeployTo for env setting var…
spetersenms Jul 7, 2025
af5af45
Removing debug comment.
spetersenms Jul 7, 2025
eb205b3
pre-commit
spetersenms Jul 7, 2025
c6323d7
Updated action readme.
spetersenms Jul 7, 2025
257ed70
Updated release notes.
spetersenms Jul 7, 2025
c982d24
pre-commit
spetersenms Jul 7, 2025
0cf6585
Fixed function documentation error.
spetersenms Jul 7, 2025
2376f12
Merge branch 'main' into DeployToEnvVar
spetersenms Jul 8, 2025
7cbf9a9
Adjusted release notes to fit more generic implementation.
spetersenms Jul 9, 2025
90fa6fb
Using OutputWarning.
spetersenms Jul 9, 2025
46b2b50
Merge branch 'DeployToEnvVar' of github.com:spetersenms/AL-Go into De…
spetersenms Jul 9, 2025
dc3dcce
Merge branch 'main' into DeployToEnvVar
spetersenms Jul 9, 2025
7eabca3
Using job env to set repo env var value
spetersenms Jul 10, 2025
efcaea2
Removed warning.
spetersenms Jul 14, 2025
3725574
Merge branch 'main' into DeployToEnvVar
spetersenms Jul 14, 2025
c74046d
Aligning workflows.
spetersenms Jul 14, 2025
8716c6e
Merge branch 'DeployToEnvVar' of github.com:spetersenms/AL-Go into De…
spetersenms Jul 14, 2025
3a5d393
Merge branch 'main' into DeployToEnvVar
spetersenms Jul 16, 2025
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
8 changes: 8 additions & 0 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,8 @@ function ReadSettings {
[string] $branchName = "$ENV:GITHUB_REF_NAME",
[string] $orgSettingsVariableValue = "$ENV:ALGoOrgSettings",
[string] $repoSettingsVariableValue = "$ENV:ALGoRepoSettings",
[string] $environmentName = "",
[string] $environmentDeployToVariableValue = "",
[switch] $silent
)

Expand Down Expand Up @@ -746,6 +748,12 @@ function ReadSettings {
$projectSettingsObject = GetSettingsObject -Path (Join-Path $projectFolder $ALGoSettingsFile)
$settingsObjects += @($projectSettingsObject)
}
if ($environmentDeployToVariableValue) {
# Read settings from environment variable (parameter)
$environmentVariableObject = [pscustomobject]@{"DeployTo$environmentName" = ($environmentDeployToVariableValue | ConvertFrom-Json) }
Write-Host "Environment variable settings: $environmentVariableObject"
$settingsObjects += @($environmentVariableObject)
}
if ($workflowName) {
# Read settings from workflow settings file
$workflowSettingsObject = GetSettingsObject -Path (Join-Path $gitHubFolder "$workflowName.settings.json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
[string] $getEnvironments,
[Parameter(HelpMessage = "Type of deployment (CD, Publish or All)", Mandatory = $true)]
[ValidateSet('CD','Publish','All')]
[string] $type
[string] $type,
[Parameter(HelpMessage = "ghTokenWorkflow secret used to read deployment environment variables", Mandatory = $false)]
[string] $ghTokenWorkflow
)

function IsGitHubPagesAvailable() {
Expand Down Expand Up @@ -56,6 +58,25 @@
}
}

function Get-DeployToEnvironmentVariable($ghEnvironment) {
$headers = GetHeaders -token $ghTokenWorkflow

$ghEnvironmentDeployToVariable = $null

$url = "$($ghEnvironment.url)/variables"
try {
Write-Host "Requesting deployment environment variables from GitHub for environment $($ghEnvironment.name)"
$ghEnvironmentVariables = (InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json
$ghEnvironmentDeployToVariable = $ghEnvironmentVariables.variables | Where-Object { $_.name -eq 'DeployTo' } | ForEach-Object { $_.value }
Write-Host "Debug found env variable: $($ghEnvironmentDeployToVariable | ConvertTo-Json -Depth 99)"
}
catch {
Write-Host "Failed to get deployment environment variables from GitHub API - Environments are not supported in this repository"
}

return $ghEnvironmentDeployToVariable
}

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

$settings = $env:Settings | ConvertFrom-Json | ConvertTo-HashTable -recurse
Expand Down Expand Up @@ -127,6 +148,7 @@
foreach($environmentName in $environments) {
Write-Host "Environment: $environmentName"
$envName = $environmentName.Split(' ')[0]
$ghEnvironment = $ghEnvironments | Where-Object { $_.name -eq $environmentName }

# Check Obsolete Settings
foreach($obsoleteSetting in "$($envName)-Projects","$($envName)_Projects") {
Expand Down Expand Up @@ -169,6 +191,15 @@
# If a DeployTo<environmentName> setting exists - use values from this (over the defaults)
Write-Host "Setting $settingsName"
$deployTo = $settings."$settingsName"
$deployToEnvironmentVariable = Get-DeployToEnvironmentVariable -ghEnvironment $ghEnvironment
if ($deployToEnvironmentVariable) {
$evKeys = @($deployToEnvironmentVariable.Keys)
Write-Host "Debug deployTo before: $($deployTo | ConvertTo-Json -Depth 99)"
foreach($key in $evKeys) {
$deployTo."$key" = $deployToEnvironmentVariable."$key"
}
Write-Host "Debug deployTo after: $($deployTo | ConvertTo-Json -Depth 99)"
}
$keys = @($deployTo.Keys)
foreach($key in $keys) {
if ($deploymentSettings.ContainsKey($key)) {
Expand Down Expand Up @@ -202,7 +233,6 @@
}

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

# Include Environment if:
Expand Down
6 changes: 5 additions & 1 deletion Actions/DetermineDeploymentEnvironments/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ inputs:
type:
description: Type of deployment (CD, Publish or All)
required: true
ghTokenWorkflow:
description: ghTokenWorkflow secret used to read deployment environment variables
required: false
outputs:
EnvironmentsMatrixJson:
description: The Environment matrix to use for the Deploy step in compressed JSON format
Expand Down Expand Up @@ -39,9 +42,10 @@ runs:
env:
_getEnvironments: ${{ inputs.getEnvironments }}
_type: ${{ inputs.type }}
_ghTokenWorkflow: ${{ inputs.ghTokenWorkflow }}
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "DetermineDeploymentEnvironments" -Action {
${{ github.action_path }}/DetermineDeploymentEnvironments.ps1 -getEnvironments $ENV:_getEnvironments -type $ENV:_type
${{ github.action_path }}/DetermineDeploymentEnvironments.ps1 -getEnvironments $ENV:_getEnvironments -type $ENV:_type -ghTokenWorkflow $ENV:_ghTokenWorkflow
}
branding:
icon: terminal
Expand Down
2 changes: 1 addition & 1 deletion Actions/Github-Helper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1347,4 +1347,4 @@ function Invoke-CommandWithRetry {
}
}
}
}
}
8 changes: 6 additions & 2 deletions Actions/ReadSettings/ReadSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
[Parameter(HelpMessage = "Build mode", Mandatory = $false)]
[string] $buildMode = "Default",
[Parameter(HelpMessage = "Specifies which properties to get from the settings file, default is all", Mandatory = $false)]
[string] $get = ""
[string] $get = "",
[Parameter(HelpMessage = "Current environment name", Mandatory = $false)]
[string] $environmentName = "",
[Parameter(HelpMessage = "Environment deploy to variable", Mandatory = $false)]
[string] $environmentDeployToVariableValue = ""
)

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

$settings = ReadSettings -project $project -buildMode $buildMode
$settings = ReadSettings -project $project -buildMode $buildMode -environmentName $environmentName -environmentDeployToVariableValue $environmentDeployToVariableValue
if ($get) {
$getSettings = $get.Split(',').Trim()
}
Expand Down
12 changes: 11 additions & 1 deletion Actions/ReadSettings/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ inputs:
description: Specifies which properties to get from the settings file, default is all
required: false
default: ''
environmentName:
description: Environment name to use for the settings file
required: false
default: ''
environmentDeployToVariableValue:
description: Deploy to settings variable defined in the github environment
required: false
default: ''
outputs:
GitHubRunnerJson:
description: GitHubRunner in compressed Json format
Expand All @@ -34,9 +42,11 @@ runs:
_project: ${{ inputs.project }}
_buildMode: ${{ inputs.buildMode }}
_get: ${{ inputs.get }}
_environmentName: ${{ inputs.environmentName }}
_environmentDeployToVariableValue: ${{ inputs.environmentDeployToVariableValue }}
run: |
${{ github.action_path }}/../Invoke-AlGoAction.ps1 -ActionName "ReadSettings" -Action {
${{ github.action_path }}/ReadSettings.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -get $ENV:_get
${{ github.action_path }}/ReadSettings.ps1 -project $ENV:_project -buildMode $ENV:_buildMode -get $ENV:_get -environmentName $ENV:_environmentName -environmentDeployToVariableValue $ENV:_environmentDeployToVariableValue
}
branding:
icon: terminal
Expand Down
2 changes: 2 additions & 0 deletions Templates/AppSource App/.github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ jobs:
with:
shell: ${{ matrix.shell }}
get: type,powerPlatformSolutionFolder
environmentName: ${{ matrix.environment }}
environmentDeployToVariableValue: ${{ vars.DeployTo }}

- name: EnvName
id: envName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ jobs:
with:
shell: ${{ matrix.shell }}
get: type,powerPlatformSolutionFolder
environmentName: ${{ matrix.environment }}
environmentDeployToVariableValue: ${{ vars.DeployTo }}

- name: Read secrets
id: ReadSecrets
Expand Down
3 changes: 3 additions & 0 deletions Templates/Per Tenant Extension/.github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ jobs:
shell: powershell
getEnvironments: '*'
type: 'CD'
ghTokenWorkflow: '${{ secrets.ghTokenWorkflow }}'

CheckForUpdates:
needs: [ Initialization ]
Expand Down Expand Up @@ -283,6 +284,8 @@ jobs:
with:
shell: ${{ matrix.shell }}
get: type,powerPlatformSolutionFolder
environmentName: ${{ matrix.environment }}
environmentDeployToVariableValue: ${{ vars.DeployTo }}

- name: EnvName
id: envName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ jobs:
with:
shell: ${{ matrix.shell }}
get: type,powerPlatformSolutionFolder
environmentName: ${{ matrix.environment }}
environmentDeployToVariableValue: ${{ vars.DeployTo }}

- name: Read secrets
id: ReadSecrets
Expand Down
Loading