Skip to content

Commit 1598a2b

Browse files
authored
DeployTo setting supported as environment variable (#1702)
With this change, it is now possible to define your DeployTo setting as an environment variable in your GitHub environments.
1 parent 3dc6fa1 commit 1598a2b

File tree

6 files changed

+57
-0
lines changed

6 files changed

+57
-0
lines changed

Actions/.Modules/ReadSettings.psm1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ function GetDefaultSettings
237237
- .github/<workflowName>.settings.json = Workflow settings file
238238
- <project>/.AL-Go/<workflowName>.settings.json = Project workflow settings file
239239
- <project>/.AL-Go/<userName>.settings.json = User settings file
240+
- ALGoEnvSettings (github Variable) = Deployment Environment settings variable
240241
.PARAMETER baseFolder
241242
The base folder where the settings files are located. Default is $ENV:GITHUB_WORKSPACE when running in GitHub Actions.
242243
.PARAMETER repoName
@@ -255,6 +256,10 @@ function GetDefaultSettings
255256
The value of the organization settings variable. Default is $ENV:ALGoOrgSettings.
256257
.PARAMETER repoSettingsVariableValue
257258
The value of the repository settings variable. Default is $ENV:ALGoRepoSettings.
259+
.PARAMETER environmentSettingsVariableValue
260+
The value of the current GitHub environment settings variable, based on workflow context. Default is $ENV:ALGoEnvSettings.
261+
.PARAMETER environmentName
262+
The value of the environment name, based on the workflow context. Default is $ENV:ALGoEnvName.
258263
.PARAMETER silent
259264
If specified, the function will not output any messages to the console.
260265
#>
@@ -269,6 +274,8 @@ function ReadSettings {
269274
[string] $branchName = "$ENV:GITHUB_REF_NAME",
270275
[string] $orgSettingsVariableValue = "$ENV:ALGoOrgSettings",
271276
[string] $repoSettingsVariableValue = "$ENV:ALGoRepoSettings",
277+
[string] $environmentSettingsVariableValue = "$ENV:ALGoEnvSettings",
278+
[string] $environmentName = "$ENV:ALGoEnvName",
272279
[switch] $silent
273280
)
274281

@@ -353,6 +360,24 @@ function ReadSettings {
353360
}
354361
}
355362

363+
if ($environmentSettingsVariableValue) {
364+
# Read settings from environment variable (parameter)
365+
$environmentVariableObject = $environmentSettingsVariableValue | ConvertFrom-Json
366+
# Warn user that 'DeployTo' setting needs to include environment name
367+
if ($environmentVariableObject.PSObject.Properties.Name -contains "DeployTo") {
368+
OutputWarning "The environment settings variable contains the property 'DeployTo'. Did you intend to use 'DeployTo$environmentName' instead? The 'DeployTo' property without a specific environment name is not supported."
369+
}
370+
# Warn user if 'runs-on', 'shell' or 'ContinuousDeployment' is defined in the environment settings variable, as these are not supported when defined there.
371+
if ($environmentVariableObject.PSObject.Properties.Name -contains "DeployTo$environmentName") {
372+
@('runs-on', 'shell', 'ContinuousDeployment') | ForEach-Object {
373+
if ($environmentVariableObject."DeployTo$environmentName".PSObject.Properties.Name -contains $_) {
374+
OutputWarning "The property $_ in the DeployTo setting is not supported when defined within a GitHub deployment environment variable. Please define this property elsewhere."
375+
}
376+
}
377+
}
378+
$settingsObjects += @($environmentVariableObject)
379+
}
380+
356381
foreach($settingsJson in $settingsObjects) {
357382
if ($settingsJson) {
358383
MergeCustomObjectIntoOrderedDictionary -dst $settings -src $settingsJson

RELEASENOTES.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
AL-Go now offers a dataexplorer dashboard to get started with AL-Go telemetry. Additionally, we've updated the documentation to include a couple of kusto queries if you would rather build your own reports.
44

5+
### Support for AL-Go settings as GitHub environment variable: ALGoEnvSettings
6+
7+
AL-Go settings can now be defined in GitHub environment variables. To use this feature, create a new variable under your GitHub environment called `ALGoEnvironmentSettings`. Please note that this variable should not include your environment name.
8+
9+
Settings loaded this way, will only be available during the Deploy step of the CI/CD or Publish to Environment actions, but not the Build step, making it most suitable for the [DeployTo setting](https://aka.ms/algosettings#deployto). Settings defined in this variable will take priority over any setting defined in AL-Go repo, org or settings files.
10+
11+
The contents of the variable should be a JSON block, similar to any other settings file or variable. When defining the `DeployTo\<EnvName>` setting in this variable, it should still include the environment name. Eg:
12+
13+
```
14+
{
15+
DeployToProduction {
16+
"Branches": [
17+
"*"
18+
],
19+
"includeTestAppsInSandboxEnvironment": false,
20+
"excludeAppIds": [ 1234 ]
21+
}
22+
}
23+
```
24+
25+
Please note, that due to certain security limitations, the properties `runs-on`, `shell` and `ContinousDeployment` of the `DeployTo` setting will <ins>**NOT**</ins> be respected if defined in a GitHub environment variable. To use these properties, please keep them defined elsewhere, such as your AL-Go settings file or Org/Repo settings variables.
26+
527
### Issues
628

729
- Issue 1770 Wrong type of _projects_ setting in settings schema

Templates/AppSource App/.github/workflows/CICD.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ jobs:
256256
environment:
257257
name: ${{ matrix.environment }}
258258
url: ${{ steps.Deploy.outputs.environmentUrl }}
259+
env:
260+
ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }}
261+
ALGoEnvName: ${{ matrix.environment }}
259262
steps:
260263
- name: Checkout
261264
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Templates/AppSource App/.github/workflows/PublishToEnvironment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ jobs:
131131
url: ${{ steps.Deploy.outputs.environmentUrl }}
132132
env:
133133
deviceCode: ${{ needs.Initialization.outputs.deviceCode }}
134+
ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }}
135+
ALGoEnvName: ${{ matrix.environment }}
134136
steps:
135137
- name: Checkout
136138
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Templates/Per Tenant Extension/.github/workflows/CICD.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ jobs:
270270
environment:
271271
name: ${{ matrix.environment }}
272272
url: ${{ steps.Deploy.outputs.environmentUrl }}
273+
env:
274+
ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }}
275+
ALGoEnvName: ${{ matrix.environment }}
273276
steps:
274277
- name: Checkout
275278
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ jobs:
131131
url: ${{ steps.Deploy.outputs.environmentUrl }}
132132
env:
133133
deviceCode: ${{ needs.Initialization.outputs.deviceCode }}
134+
ALGoEnvSettings: ${{ vars.ALGoEnvironmentSettings }}
135+
ALGoEnvName: ${{ matrix.environment }}
134136
steps:
135137
- name: Checkout
136138
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

0 commit comments

Comments
 (0)