Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Actions/ReadSettings/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ none
| :-- | :-- |
| GitHubRunnerJson | GitHubRunner in compressed Json format |
| GitHubRunnerShell | Shell for GitHubRunner jobs |
| SelectedSettingsJson | Selected settings from the get parameter in compressed JSON format |
6 changes: 6 additions & 0 deletions Actions/ReadSettings/ReadSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ if ($settings.versioningstrategy -ne -1) {
}

$outSettings = @{}
$selectedSettings = @{}
$settings.Keys | ForEach-Object {
$setting = $_
$settingValue = $settings."$setting"
Expand All @@ -71,6 +72,7 @@ $settings.Keys | ForEach-Object {
else {
Add-Content -Encoding UTF8 -Path $env:GITHUB_ENV -Value "$setting=$settingValue"
}
$selectedSettings[$setting] = $settingValue
}
}

Expand All @@ -85,3 +87,7 @@ Write-Host "GitHubRunnerJson=$githubRunner"
$gitHubRunnerShell = $settings.githubRunnerShell
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "GitHubRunnerShell=$githubRunnerShell"
Write-Host "GitHubRunnerShell=$githubRunnerShell"

$selectedSettingsJson = $selectedSettings | ConvertTo-Json -Depth 99 -Compress
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "SelectedSettingsJson=$selectedSettingsJson"
Write-Host "SelectedSettingsJson=$selectedSettingsJson"
3 changes: 3 additions & 0 deletions Actions/ReadSettings/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ outputs:
GitHubRunnerShell:
description: Shell for GitHubRunner jobs
value: ${{ steps.readsettings.outputs.GitHubRunnerShell }}
SelectedSettingsJson:
description: Selected settings from the get parameter in compressed JSON format
value: ${{ steps.readsettings.outputs.SelectedSettingsJson }}
runs:
using: composite
steps:
Expand Down
15 changes: 2 additions & 13 deletions Templates/AppSource App/.github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }}
baselineWorkflowRunId: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowRunId }}
baselineWorkflowSHA: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowSHA }}
workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }}
powerPlatformSolutionFolder: ${{ steps.DeterminePowerPlatformSolutionFolder.outputs.powerPlatformSolutionFolder }}
workflowDepth: ${{ env.workflowDepth }}
powerPlatformSolutionFolder: ${{ fromJson(steps.ReadSettings.outputs.SelectedSettingsJson).powerPlatformSolutionFolder }}
steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main
Expand Down Expand Up @@ -87,24 +87,13 @@ jobs:
submodules: ${{ env.useGitSubmodules }}
token: '${{ fromJson(steps.ReadSubmodulesToken.outputs.Secrets).gitSubmodulesToken }}'

- name: Determine Workflow Depth
id: DetermineWorkflowDepth
run: |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "WorkflowDepth=$($env:workflowDepth)"

- name: Determine Projects To Build
id: determineProjectsToBuild
uses: microsoft/AL-Go-Actions/DetermineProjectsToBuild@main
with:
shell: powershell
maxBuildDepth: ${{ env.workflowDepth }}

- name: Determine PowerPlatform Solution Folder
id: DeterminePowerPlatformSolutionFolder
if: env.type == 'PTE'
run: |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "powerPlatformSolutionFolder=$($env:powerPlatformSolutionFolder)"

- name: Determine Delivery Target Secrets
id: DetermineDeliveryTargetSecrets
uses: microsoft/AL-Go-Actions/DetermineDeliveryTargets@main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }}
baselineWorkflowRunId: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowRunId }}
baselineWorkflowSHA: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowSHA }}
workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }}
artifactsRetentionDays: ${{ steps.DetermineWorkflowDepth.outputs.ArtifactsRetentionDays }}
workflowDepth: ${{ env.workflowDepth }}
artifactsRetentionDays: ${{ fromJson(steps.ReadSettings.outputs.SelectedSettingsJson).shortLivedArtifactsRetentionDays }}
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
steps:
- name: Dump Workflow Information
Expand All @@ -68,12 +68,6 @@ jobs:
shell: powershell
get: shortLivedArtifactsRetentionDays

- name: Determine Workflow Depth
id: DetermineWorkflowDepth
run: |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "WorkflowDepth=$($env:workflowDepth)"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "ArtifactsRetentionDays=$($env:shortLivedArtifactsRetentionDays)"

- name: Determine Projects To Build
id: determineProjectsToBuild
uses: microsoft/AL-Go-Actions/DetermineProjectsToBuild@main
Expand Down
15 changes: 2 additions & 13 deletions Templates/Per Tenant Extension/.github/workflows/CICD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }}
baselineWorkflowRunId: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowRunId }}
baselineWorkflowSHA: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowSHA }}
workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }}
powerPlatformSolutionFolder: ${{ steps.DeterminePowerPlatformSolutionFolder.outputs.powerPlatformSolutionFolder }}
workflowDepth: ${{ env.workflowDepth }}
powerPlatformSolutionFolder: ${{ fromJson(steps.ReadSettings.outputs.SelectedSettingsJson).powerPlatformSolutionFolder }}
Comment on lines +47 to +48
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can just assign workflowDepth to ${{ env.workflowDepth }} couldn't we do the same for powerPlatformSolutionFolder.

The settings defined in the "get" parameter are already assigned to an environment variable AFAIK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works for workflowDepth because it's a global environment variable defined on line 23. The environment variables created by readsettings for things in the get param can't be used for job outputs, hence the need for putting everything in "get" into a separate output variable which can then be used for the job output.

That said, it seems the workflowDepth output is not actually used. In this PR I kept it for now, but we can probably remove it completely as the whole workflow should have access to env.workflowDepth given it's defined on the global level.

steps:
- name: Dump Workflow Information
uses: microsoft/AL-Go-Actions/DumpWorkflowInfo@main
Expand Down Expand Up @@ -87,24 +87,13 @@ jobs:
submodules: ${{ env.useGitSubmodules }}
token: '${{ fromJson(steps.ReadSubmodulesToken.outputs.Secrets).gitSubmodulesToken }}'

- name: Determine Workflow Depth
id: DetermineWorkflowDepth
run: |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "WorkflowDepth=$($env:workflowDepth)"

- name: Determine Projects To Build
id: determineProjectsToBuild
uses: microsoft/AL-Go-Actions/DetermineProjectsToBuild@main
with:
shell: powershell
maxBuildDepth: ${{ env.workflowDepth }}

- name: Determine PowerPlatform Solution Folder
id: DeterminePowerPlatformSolutionFolder
if: env.type == 'PTE'
run: |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "powerPlatformSolutionFolder=$($env:powerPlatformSolutionFolder)"

- name: Determine Delivery Target Secrets
id: DetermineDeliveryTargetSecrets
uses: microsoft/AL-Go-Actions/DetermineDeliveryTargets@main
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ jobs:
buildOrderJson: ${{ steps.determineProjectsToBuild.outputs.BuildOrderJson }}
baselineWorkflowRunId: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowRunId }}
baselineWorkflowSHA: ${{ steps.determineProjectsToBuild.outputs.BaselineWorkflowSHA }}
workflowDepth: ${{ steps.DetermineWorkflowDepth.outputs.WorkflowDepth }}
artifactsRetentionDays: ${{ steps.DetermineWorkflowDepth.outputs.ArtifactsRetentionDays }}
workflowDepth: ${{ env.workflowDepth }}
artifactsRetentionDays: ${{ fromJson(steps.ReadSettings.outputs.SelectedSettingsJson).shortLivedArtifactsRetentionDays }}
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
steps:
- name: Dump Workflow Information
Expand All @@ -68,12 +68,6 @@ jobs:
shell: powershell
get: shortLivedArtifactsRetentionDays

- name: Determine Workflow Depth
id: DetermineWorkflowDepth
run: |
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "WorkflowDepth=$($env:workflowDepth)"
Add-Content -Encoding UTF8 -Path $env:GITHUB_OUTPUT -Value "ArtifactsRetentionDays=$($env:shortLivedArtifactsRetentionDays)"

- name: Determine Projects To Build
id: determineProjectsToBuild
uses: microsoft/AL-Go-Actions/DetermineProjectsToBuild@main
Expand Down
49 changes: 49 additions & 0 deletions Tests/ReadSettings.Action.Test.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Get-Module TestActionsHelper | Remove-Module -Force
Get-Module ReadSettings | Remove-Module -Force
Import-Module (Join-Path $PSScriptRoot 'TestActionsHelper.psm1')
$errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0

Expand All @@ -11,6 +12,22 @@ Describe "ReadSettings Action Tests" {
$scriptPath = Join-Path $scriptRoot $scriptName
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'actionScript', Justification = 'False positive.')]
$actionScript = GetActionScript -scriptRoot $scriptRoot -scriptName $scriptName
$testFolder = (Join-Path ([System.IO.Path]::GetTempPath()) "readSettingsActionTest")
$ENV:GITHUB_WORKSPACE = $testFolder
Mock Write-Host { }
Mock Out-Host { }
}

BeforeEach {
New-Item -Path $testFolder -ItemType Directory -Force | Out-Null
$env:GITHUB_ENV = (Join-Path $testFolder "githubEnv")
$env:GITHUB_OUTPUT = (Join-Path $testFolder "githubOutput")
New-Item -Path $env:GITHUB_ENV -ItemType file -Force | Out-Null
New-Item -Path $env:GITHUB_OUTPUT -ItemType file -Force | Out-Null
}

AfterEach {
Remove-Item -Path $testFolder -Recurse -Force -ErrorAction SilentlyContinue
}

It 'Compile Action' {
Expand All @@ -21,7 +38,39 @@ Describe "ReadSettings Action Tests" {
$outputs = [ordered]@{
"GitHubRunnerJson" = "GitHubRunner in compressed Json format"
"GitHubRunnerShell" = "Shell for GitHubRunner jobs"
"SelectedSettingsJson" = "Selected settings from the get parameter in compressed JSON format"
}
YamlTest -scriptRoot $scriptRoot -actionName $actionName -actionScript $actionScript -outputs $outputs
}

It 'Settings in get param are correctly added to SelectedSettingsJson output' {
& $scriptPath `
-project '' `
-get 'shortLivedArtifactsRetentionDays,powerPlatformSolutionFolder'

# Read the output file content
$outputContent = Get-Content $env:GITHUB_OUTPUT

# Find the SelectedSettingsJson line and extract its value
$selectedSettingsLine = $outputContent | Where-Object { $_ -match '^SelectedSettingsJson=(.*)$' }
$selectedSettingsLine | Should -Not -BeNullOrEmpty

# Extract the JSON value from the line
if ($selectedSettingsLine -match '^SelectedSettingsJson=(.*)$') {
$jsonValue = $Matches[1]

# Parse the JSON to verify it's valid
$settingsObject = $jsonValue | ConvertFrom-Json

# Verify the expected properties are present
$settingsObject.PSObject.Properties.Name | Should -Contain 'shortLivedArtifactsRetentionDays'
$settingsObject.PSObject.Properties.Name | Should -Contain 'powerPlatformSolutionFolder'

# Verify the values are correct (assuming default values)
$settingsObject.shortLivedArtifactsRetentionDays | Should -Be 1
$settingsObject.powerPlatformSolutionFolder | Should -Be ''
} else {
throw "Could not extract JSON value from SelectedSettingsJson output"
}
}
}
Loading