From c3309d569785d3028f3aa250594cd470dea34c3d Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 16:15:50 +0200 Subject: [PATCH 01/42] Importing debug helper. --- Actions/Invoke-AlGoAction.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/Actions/Invoke-AlGoAction.ps1 b/Actions/Invoke-AlGoAction.ps1 index 7cfd29c0a..d191dd141 100644 --- a/Actions/Invoke-AlGoAction.ps1 +++ b/Actions/Invoke-AlGoAction.ps1 @@ -12,6 +12,7 @@ $progressPreference = "SilentlyContinue" Set-StrictMode -Version 2.0 Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "TelemetryHelper.psm1" -Resolve) +Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "DebugLogHelper.psm1" -Resolve) try { Invoke-Command -ScriptBlock $Action From 68b9759aaceb718eff5b92c9521455afee4dc260 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 16:16:06 +0200 Subject: [PATCH 02/42] First draft of debug helper --- Actions/DebugLogHelper.psm1 | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Actions/DebugLogHelper.psm1 diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 new file mode 100644 index 000000000..392b3561f --- /dev/null +++ b/Actions/DebugLogHelper.psm1 @@ -0,0 +1,38 @@ +$debugLoggingEnabled = $false +if ($env:DEBUGLOGGING -eq 'true') { + $debugLoggingEnabled = $true +} + +# Debug logging that is only written when additional logging is enabled +function Write-Debug-Info { + param ( + [Parameter(Mandatory = $true)] + [string] $Message + ) + + if ($debugLoggingEnabled) { + Write-Host -ForegroundColor Green "DEBUG: $Message" + } +} + +# Function to write debug information about function calls +function Write-Debug-FunctionCallInfo { + param ( + [Parameter(Mandatory = $true)] + [string] $FunctionName, + [Parameter(Mandatory = $true)] + [System.Management.Automation.PSBoundParametersDictionary] $Parameters + ) + + if ($debugLoggingEnabled) { + Write-Host -ForegroundColor Green "DEBUG: Function '$functionName' called with parameters:" + foreach ($param in $Parameters.Keys) { + Write-Host -ForegroundColor Green " $($param): $($Parameters[$param])" + } + } +} + +# Regular log that is always written +function Write-Info { + +} \ No newline at end of file From 3fd68e6af71f9773fd45381498e9b993aa89efd2 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 16:16:18 +0200 Subject: [PATCH 03/42] Testing new debug helper functions. --- .../DetermineDeploymentEnvironments.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 b/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 index f94f1baee..36debbdc9 100644 --- a/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 +++ b/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 @@ -5,10 +5,13 @@ [ValidateSet('CD','Publish','All')] [string] $type ) +Write-Debug-FunctionCallInfo -FunctionName "DetermineDeploymentEnvironments" -Parameters $MyInvocation.BoundParameters function IsGitHubPagesAvailable() { + Write-Debug-FunctionCallInfo -FunctionName "IsGitHubPagesAvailable" -Parameters @{} $headers = GetHeaders -token $env:GITHUB_TOKEN $url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/pages" + Write-Debug-Info "Url: $url" try { Write-Host "Requesting GitHub Pages settings from GitHub" $ghPages = (InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json @@ -20,8 +23,10 @@ function IsGitHubPagesAvailable() { } function GetGitHubEnvironments() { + Write-Debug-FunctionCallInfo -FunctionName "GetGitHubEnvironments" -Parameters @{} $headers = GetHeaders -token $env:GITHUB_TOKEN $url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/environments" + Write-Debug-Info "Url: $url" try { Write-Host "Requesting environments from GitHub" $ghEnvironments = @(((InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json).environments) @@ -34,6 +39,7 @@ function GetGitHubEnvironments() { } function Get-BranchesFromPolicy($ghEnvironment) { + Write-Debug-FunctionCallInfo -FunctionName "Get-BranchesFromPolicy" -Parameters $MyInvocation.BoundParameters if ($ghEnvironment) { # Environment is defined in GitHub - check protection rules $headers = GetHeaders -token $env:GITHUB_TOKEN From 934bf8fb9f4ba5ef6209ad4cfe5b29a1a7235aec Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 16:27:34 +0200 Subject: [PATCH 04/42] Changing type for param --- Actions/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 392b3561f..d8ce34d98 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -21,7 +21,7 @@ function Write-Debug-FunctionCallInfo { [Parameter(Mandatory = $true)] [string] $FunctionName, [Parameter(Mandatory = $true)] - [System.Management.Automation.PSBoundParametersDictionary] $Parameters + [System.Object] $Parameters ) if ($debugLoggingEnabled) { From 45203829bbd7671215deabc32da474b8565d37c8 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 16:33:53 +0200 Subject: [PATCH 05/42] Log info on debug log variable. --- Actions/DebugLogHelper.psm1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index d8ce34d98..82b4f4e83 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -1,8 +1,14 @@ $debugLoggingEnabled = $false -if ($env:DEBUGLOGGING -eq 'true') { - $debugLoggingEnabled = $true +try { + Write-Host "DEBUGLOGGING environment variable: $env:DEBUGLOGGING" + if ($env:DEBUGLOGGING -eq 1 -or $env:DEBUGLOGGING -eq "true") { + $debugLoggingEnabled = $true + } +} catch { + Write-Host "Failed to parse DEBUGLOGGING environment variable. Defaulting to false." } + # Debug logging that is only written when additional logging is enabled function Write-Debug-Info { param ( From 90e03b181b55f2b5d6d4cee8a81c32902dd859ed Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 16:34:12 +0200 Subject: [PATCH 06/42] Add debug context var to env variable. --- .../.github/workflows/PublishToEnvironment.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml index 64fd019cb..4b5cd7244 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml @@ -23,6 +23,7 @@ defaults: env: ALGoOrgSettings: ${{ vars.ALGoOrgSettings }} ALGoRepoSettings: ${{ vars.ALGoRepoSettings }} + DebugLogging: ${{ runner.debug }} jobs: Initialization: From fd9969d02a6bbbb2c1823631674c28cef3924557 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 17:17:30 +0200 Subject: [PATCH 07/42] Removed runner context from top level env statement as it's not available there. --- .../.github/workflows/PublishToEnvironment.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml index 4b5cd7244..64fd019cb 100644 --- a/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml +++ b/Templates/Per Tenant Extension/.github/workflows/PublishToEnvironment.yaml @@ -23,7 +23,6 @@ defaults: env: ALGoOrgSettings: ${{ vars.ALGoOrgSettings }} ALGoRepoSettings: ${{ vars.ALGoRepoSettings }} - DebugLogging: ${{ runner.debug }} jobs: Initialization: From fe23a7a889ffb75c5cb378fc231d922dd9e90180 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 12 May 2025 17:19:49 +0200 Subject: [PATCH 08/42] Testing injecting runner context in action environment var section. --- Actions/DebugLogHelper.psm1 | 4 ++-- Actions/DetermineDeploymentEnvironments/action.yaml | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 82b4f4e83..f76b2927f 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -1,7 +1,7 @@ $debugLoggingEnabled = $false try { - Write-Host "DEBUGLOGGING environment variable: $env:DEBUGLOGGING" - if ($env:DEBUGLOGGING -eq 1 -or $env:DEBUGLOGGING -eq "true") { + Write-Host "DEBUGLOGGING environment variable: $env:_DEBUGLOGGING" + if ($env:_DEBUGLOGGING -eq 1 -or $env:_DEBUGLOGGING -eq "true") { $debugLoggingEnabled = $true } } catch { diff --git a/Actions/DetermineDeploymentEnvironments/action.yaml b/Actions/DetermineDeploymentEnvironments/action.yaml index d913710cb..a17406488 100644 --- a/Actions/DetermineDeploymentEnvironments/action.yaml +++ b/Actions/DetermineDeploymentEnvironments/action.yaml @@ -37,6 +37,7 @@ runs: shell: ${{ inputs.shell }} id: determineDeploymentEnvironments env: + _debugLogging: ${{ runner.debug }} _getEnvironments: ${{ inputs.getEnvironments }} _type: ${{ inputs.type }} run: | From db7531a098682cab308043499503b4ee8f81fe4c Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Tue, 13 May 2025 09:21:27 +0200 Subject: [PATCH 09/42] Added [Debug] tag to debug logs. --- Actions/DebugLogHelper.psm1 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index f76b2927f..288dcdd02 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -17,7 +17,7 @@ function Write-Debug-Info { ) if ($debugLoggingEnabled) { - Write-Host -ForegroundColor Green "DEBUG: $Message" + Write-Host -ForegroundColor Green "[Debug] $Message" } } @@ -31,7 +31,7 @@ function Write-Debug-FunctionCallInfo { ) if ($debugLoggingEnabled) { - Write-Host -ForegroundColor Green "DEBUG: Function '$functionName' called with parameters:" + Write-Host -ForegroundColor Green "[Debug] Function '$functionName' called with parameters:" foreach ($param in $Parameters.Keys) { Write-Host -ForegroundColor Green " $($param): $($Parameters[$param])" } @@ -40,5 +40,10 @@ function Write-Debug-FunctionCallInfo { # Regular log that is always written function Write-Info { + param ( + [Parameter(Mandatory = $true)] + [string] $Message + ) + Write-Host "$Message" } \ No newline at end of file From 9f0525548f76fb1acc17179f717b8ef92523787b Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 19 May 2025 13:47:35 +0200 Subject: [PATCH 10/42] Testing RUNNER_DEBUG variable. --- Actions/DebugLogHelper.psm1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 288dcdd02..7f39bb4d3 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -1,6 +1,7 @@ $debugLoggingEnabled = $false try { - Write-Host "DEBUGLOGGING environment variable: $env:_DEBUGLOGGING" + Write-Host "_DEBUGLOGGING environment variable: $env:_DEBUGLOGGING"#RUNNER_DEBUG + Write-Host "RUNNER_DEBUG environment variable: $env:RUNNER_DEBUG" if ($env:_DEBUGLOGGING -eq 1 -or $env:_DEBUGLOGGING -eq "true") { $debugLoggingEnabled = $true } From 70fdfb2df2ec01b65b522e8971c31db14e5e365e Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 19 May 2025 14:53:12 +0200 Subject: [PATCH 11/42] Switching to use RUNNER_DEBUG env var instead of passing github context. --- Actions/DebugLogHelper.psm1 | 5 ++--- Actions/DetermineDeploymentEnvironments/action.yaml | 1 - 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 7f39bb4d3..9dcac9c09 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -1,12 +1,11 @@ $debugLoggingEnabled = $false try { - Write-Host "_DEBUGLOGGING environment variable: $env:_DEBUGLOGGING"#RUNNER_DEBUG Write-Host "RUNNER_DEBUG environment variable: $env:RUNNER_DEBUG" - if ($env:_DEBUGLOGGING -eq 1 -or $env:_DEBUGLOGGING -eq "true") { + if ($env:RUNNER_DEBUG -eq 1) { $debugLoggingEnabled = $true } } catch { - Write-Host "Failed to parse DEBUGLOGGING environment variable. Defaulting to false." + Write-Host "Failed to parse RUNNER_DEBUG environment variable. Defaulting to false." } diff --git a/Actions/DetermineDeploymentEnvironments/action.yaml b/Actions/DetermineDeploymentEnvironments/action.yaml index a17406488..d913710cb 100644 --- a/Actions/DetermineDeploymentEnvironments/action.yaml +++ b/Actions/DetermineDeploymentEnvironments/action.yaml @@ -37,7 +37,6 @@ runs: shell: ${{ inputs.shell }} id: determineDeploymentEnvironments env: - _debugLogging: ${{ runner.debug }} _getEnvironments: ${{ inputs.getEnvironments }} _type: ${{ inputs.type }} run: | From 44ae29662db9068d9dff4cfb2ddae0a2a96f1355 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 19 May 2025 15:02:13 +0200 Subject: [PATCH 12/42] Improved formatting of debug messages. --- Actions/DebugLogHelper.psm1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 9dcac9c09..4f8f2a2dd 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -1,8 +1,10 @@ $debugLoggingEnabled = $false try { - Write-Host "RUNNER_DEBUG environment variable: $env:RUNNER_DEBUG" if ($env:RUNNER_DEBUG -eq 1) { $debugLoggingEnabled = $true + Write-Host "AL-Go extended debugging is enabled." + } else { + Write-Host "AL-Go extended debug logging is disabled." } } catch { Write-Host "Failed to parse RUNNER_DEBUG environment variable. Defaulting to false." @@ -17,7 +19,7 @@ function Write-Debug-Info { ) if ($debugLoggingEnabled) { - Write-Host -ForegroundColor Green "[Debug] $Message" + Write-Host -ForegroundColor Yellow "[AL-Go-Debug] $Message" } } @@ -31,9 +33,12 @@ function Write-Debug-FunctionCallInfo { ) if ($debugLoggingEnabled) { - Write-Host -ForegroundColor Green "[Debug] Function '$functionName' called with parameters:" + Write-Host -ForegroundColor Green "[AL-Go-Debug] Function '$functionName' called with parameters:" foreach ($param in $Parameters.Keys) { - Write-Host -ForegroundColor Green " $($param): $($Parameters[$param])" + Write-Host -ForegroundColor Green "[AL-Go-Debug] - $($param): $($Parameters[$param])" + } + if ($Parameters.Count -eq 0) { + Write-Host -ForegroundColor Green "[AL-Go-Debug] - None" } } } From c268aa8d05f66817a6e409dec607974b806f5706 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 19 May 2025 15:19:50 +0200 Subject: [PATCH 13/42] Coloring debug output --- Actions/DebugLogHelper.psm1 | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 4f8f2a2dd..55aea3152 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -10,6 +10,17 @@ try { Write-Host "Failed to parse RUNNER_DEBUG environment variable. Defaulting to false." } +# Colors +$colorCodeMagenta = '35' + +function Write-Debug-Base { + param ( + [Parameter(Mandatory = $true)] + [string] $Message + ) + + Write-Host "`e[${colorCodeMagenta}m[AL-Go-Debug]`e[0m $Message" +} # Debug logging that is only written when additional logging is enabled function Write-Debug-Info { @@ -19,7 +30,7 @@ function Write-Debug-Info { ) if ($debugLoggingEnabled) { - Write-Host -ForegroundColor Yellow "[AL-Go-Debug] $Message" + Write-Debug-Base $Message } } @@ -33,12 +44,12 @@ function Write-Debug-FunctionCallInfo { ) if ($debugLoggingEnabled) { - Write-Host -ForegroundColor Green "[AL-Go-Debug] Function '$functionName' called with parameters:" + Write-Debug-Base "Function '$functionName' called with parameters:" foreach ($param in $Parameters.Keys) { - Write-Host -ForegroundColor Green "[AL-Go-Debug] - $($param): $($Parameters[$param])" + Write-Debug-Base "- $($param): $($Parameters[$param])" } if ($Parameters.Count -eq 0) { - Write-Host -ForegroundColor Green "[AL-Go-Debug] - None" + Write-Debug-Base "- None" } } } @@ -50,5 +61,5 @@ function Write-Info { [string] $Message ) - Write-Host "$Message" + Write-Host $Message } \ No newline at end of file From 9e83be6a066f73eb685aa1c4754c83ebc474103f Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 19 May 2025 15:37:00 +0200 Subject: [PATCH 14/42] Using escape char that works in both Pwsh 5 and 7 --- Actions/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 55aea3152..f7ee2ccce 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -19,7 +19,7 @@ function Write-Debug-Base { [string] $Message ) - Write-Host "`e[${colorCodeMagenta}m[AL-Go-Debug]`e[0m $Message" + Write-Host "$([char] 27)[${colorCodeMagenta}m[AL-Go-Debug]$([char] 27)[0m $Message" } # Debug logging that is only written when additional logging is enabled From d3b265ffbd790167baa3a2d4baa9444aee18ee48 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Wed, 21 May 2025 13:30:05 +0200 Subject: [PATCH 15/42] Importing debug log helper in tests. --- Tests/TestActionsHelper.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tests/TestActionsHelper.psm1 b/Tests/TestActionsHelper.psm1 index 76d6f6f28..3edcff7e7 100644 --- a/Tests/TestActionsHelper.psm1 +++ b/Tests/TestActionsHelper.psm1 @@ -2,6 +2,8 @@ $env:GITHUB_OUTPUT = [System.IO.Path]::GetTempFileName() +Import-Module (Join-Path $PSScriptRoot '../Actions/DebugLogHelper.psm1') + function iReplace { Param( [string] $string, From 72ec7b20aa35adc2fe71076fe400bdc2f01538a5 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Wed, 21 May 2025 13:43:55 +0200 Subject: [PATCH 16/42] Importing logging module globally to make it useable by tests. --- Tests/TestActionsHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/TestActionsHelper.psm1 b/Tests/TestActionsHelper.psm1 index 3edcff7e7..78af1c516 100644 --- a/Tests/TestActionsHelper.psm1 +++ b/Tests/TestActionsHelper.psm1 @@ -2,7 +2,7 @@ $env:GITHUB_OUTPUT = [System.IO.Path]::GetTempFileName() -Import-Module (Join-Path $PSScriptRoot '../Actions/DebugLogHelper.psm1') +Import-Module (Join-Path $PSScriptRoot '../Actions/DebugLogHelper.psm1') -Global function iReplace { Param( From da613320fe751e89acb3f94b707bb1b5ebf6bfad Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Wed, 21 May 2025 13:47:17 +0200 Subject: [PATCH 17/42] pre-commit --- Actions/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index f7ee2ccce..96f3fbdd9 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -62,4 +62,4 @@ function Write-Info { ) Write-Host $Message -} \ No newline at end of file +} From 08754831fcec022bea5939742127d1d8d30f30a0 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 23 Jun 2025 13:25:29 +0200 Subject: [PATCH 18/42] Fixed inconsistent log. --- Actions/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 96f3fbdd9..30b70a65a 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -2,7 +2,7 @@ $debugLoggingEnabled = $false try { if ($env:RUNNER_DEBUG -eq 1) { $debugLoggingEnabled = $true - Write-Host "AL-Go extended debugging is enabled." + Write-Host "AL-Go extended debug logging is enabled." } else { Write-Host "AL-Go extended debug logging is disabled." } From 6ea22d44f6bacb13f1986198edc43e25614aac66 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 23 Jun 2025 13:51:19 +0200 Subject: [PATCH 19/42] Made parameters param of function debug optional, added helper functions to print groups and color support for regular logs. --- Actions/DebugLogHelper.psm1 | 46 +++++++++++++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 30b70a65a..82e00f836 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -11,7 +11,12 @@ try { } # Colors +$colorCodeRed = '31' +$colorCodeGreen = '32' +$colorCodeYellow = '33' +$colorCodeBlue = '34' $colorCodeMagenta = '35' +$colorCodeCyan = '36' function Write-Debug-Base { param ( @@ -35,12 +40,13 @@ function Write-Debug-Info { } # Function to write debug information about function calls +# The $parameters param should always be called with $MyInvocation.BoundParameters if the given function got parameters. function Write-Debug-FunctionCallInfo { param ( [Parameter(Mandatory = $true)] [string] $FunctionName, - [Parameter(Mandatory = $true)] - [System.Object] $Parameters + [Parameter(Mandatory = $false)] + [System.Object] $Parameters = @{} ) if ($debugLoggingEnabled) { @@ -54,12 +60,42 @@ function Write-Debug-FunctionCallInfo { } } -# Regular log that is always written -function Write-Info { +# Helper functions to wrap logs in groups for better overview in GitHub actions +function Write-GroupStart { param ( [Parameter(Mandatory = $true)] [string] $Message ) - Write-Host $Message + Write-Host "::group::$Message" +} + +function Write-GroupEnd { + Write-Host "::endgroup::" +} + +# Regular log that is always written and supports color coding +function Write-Info { + param ( + [Parameter(Mandatory = $true)] + [string] $Message, + [Parameter(Mandatory = $false)] + [ValidateSet('Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan')] + [string] $Color + ) + + if ($Color) { + $colorCode = 0 + switch ($Color) { + 'Red' { $colorCode = $colorCodeRed } + 'Green' { $colorCode = $colorCodeGreen } + 'Yellow' { $colorCode = $colorCodeYellow } + 'Blue' { $colorCode = $colorCodeBlue } + 'Magenta' { $colorCode = $colorCodeMagenta } + 'Cyan' { $colorCode = $colorCodeCyan } + } + Write-Host "$([char] 27)[${colorCode}m$Message$([char] 27)[0m" + } else { + Write-Host $Message + } } From 868b910a253c85bea46357e34437c8994984051e Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 7 Jul 2025 11:58:13 +0200 Subject: [PATCH 20/42] pre-commit --- Actions/DebugLogHelper.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/DebugLogHelper.psm1 index 82e00f836..e27c68875 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/DebugLogHelper.psm1 @@ -81,7 +81,7 @@ function Write-Info { [string] $Message, [Parameter(Mandatory = $false)] [ValidateSet('Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan')] - [string] $Color + [string] $Color ) if ($Color) { @@ -97,5 +97,5 @@ function Write-Info { Write-Host "$([char] 27)[${colorCode}m$Message$([char] 27)[0m" } else { Write-Host $Message - } + } } From 5f11ac64df01926c0f5d1c85e77190aa39ee32c9 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Thu, 10 Jul 2025 13:37:16 +0200 Subject: [PATCH 21/42] Moving debug module to module folder, and including OutPut* functions from AL-Go helper. --- Actions/{ => .Modules}/DebugLogHelper.psm1 | 75 ++++++++++++++++++++++ Actions/AL-Go-Helper.ps1 | 64 ------------------ Actions/Invoke-AlGoAction.ps1 | 2 +- 3 files changed, 76 insertions(+), 65 deletions(-) rename Actions/{ => .Modules}/DebugLogHelper.psm1 (66%) diff --git a/Actions/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 similarity index 66% rename from Actions/DebugLogHelper.psm1 rename to Actions/.Modules/DebugLogHelper.psm1 index e27c68875..0ccf4a262 100644 --- a/Actions/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -1,3 +1,12 @@ + +if ($env:GITHUB_ACTIONS -eq "true") { + Write-Host "Running in GitHub Actions" + $runningLocal = $false +} else { + Write-Host "Running locally" + $runningLocal = $true +} + $debugLoggingEnabled = $false try { if ($env:RUNNER_DEBUG -eq 1) { @@ -99,3 +108,69 @@ function Write-Info { Write-Host $Message } } + +function OutputError { + Param( + [string] $message + ) + + if ($runningLocal) { + throw $message + } + else { + Write-Host "::Error::$($message.Replace("`r",'').Replace("`n",' '))" + $host.SetShouldExit(1) + } +} + +function OutputWarning { + Param( + [string] $message + ) + + if ($runningLocal) { + Write-Host -ForegroundColor Yellow "WARNING: $message" + } + else { + Write-Host "::Warning::$message" + } +} + +function OutputNotice { + Param( + [string] $message + ) + + if ($runningLocal) { + Write-Host $message + } + else { + Write-Host "::Notice::$message" + } +} + +function MaskValueInLog { + Param( + [string] $value + ) + + if (!$runningLocal) { + Write-Host "`r::add-mask::$value" + } +} + +function OutputDebug { + Param( + [string] $message + ) + + if ($runningLocal) { + Write-Host $message + } + else { + Write-Host "::Debug::$message" + } +} + +Export-ModuleMember -Function Write-Debug-Info, Write-Debug-FunctionCallInfo, Write-GroupStart, Write-GroupEnd, Write-Info, OutputError, OutputWarning, OutputNotice, MaskValueInLog, OutputDebug +Export-ModuleMember -Variable debugLoggingEnabled \ No newline at end of file diff --git a/Actions/AL-Go-Helper.ps1 b/Actions/AL-Go-Helper.ps1 index cddbd9ddc..dd9293194 100644 --- a/Actions/AL-Go-Helper.ps1 +++ b/Actions/AL-Go-Helper.ps1 @@ -22,7 +22,6 @@ $RepoSettingsFile = Join-Path '.github' 'AL-Go-Settings.json' $defaultCICDPushBranches = @( 'main', 'release/*', 'feature/*' ) [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', 'defaultCICDPullRequestBranches', Justification = 'False positive.')] $defaultCICDPullRequestBranches = @( 'main' ) -$runningLocal = $local.IsPresent $defaultBcContainerHelperVersion = "preview" # Must be double quotes. Will be replaced by BcContainerHelperVersion if necessary in the deploy step - ex. "https://github.com/organization/navcontainerhelper/archive/refs/heads/branch.zip" $notSecretProperties = @("Scopes","TenantId","BlobName","ContainerName","StorageAccountName","ServerUrl","ppUserName","GitHubAppClientId","EnvironmentName") @@ -183,69 +182,6 @@ function ConvertTo-HashTable() { } } -function OutputError { - Param( - [string] $message - ) - - if ($runningLocal) { - throw $message - } - else { - Write-Host "::Error::$($message.Replace("`r",'').Replace("`n",' '))" - $host.SetShouldExit(1) - } -} - -function OutputWarning { - Param( - [string] $message - ) - - if ($runningLocal) { - Write-Host -ForegroundColor Yellow "WARNING: $message" - } - else { - Write-Host "::Warning::$message" - } -} - -function OutputNotice { - Param( - [string] $message - ) - - if ($runningLocal) { - Write-Host $message - } - else { - Write-Host "::Notice::$message" - } -} - -function MaskValueInLog { - Param( - [string] $value - ) - - if (!$runningLocal) { - Write-Host "`r::add-mask::$value" - } -} - -function OutputDebug { - Param( - [string] $message - ) - - if ($runningLocal) { - Write-Host $message - } - else { - Write-Host "::Debug::$message" - } -} - function GetUniqueFolderName { Param( [string] $baseFolder, diff --git a/Actions/Invoke-AlGoAction.ps1 b/Actions/Invoke-AlGoAction.ps1 index bd46c7754..854cf9021 100644 --- a/Actions/Invoke-AlGoAction.ps1 +++ b/Actions/Invoke-AlGoAction.ps1 @@ -14,7 +14,7 @@ $progressPreference = "SilentlyContinue" Set-StrictMode -Version 2.0 Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "TelemetryHelper.psm1" -Resolve) -Import-Module (Join-Path -Path $PSScriptRoot -ChildPath "DebugLogHelper.psm1" -Resolve) +Import-Module (Join-Path -Path $PSScriptRoot -ChildPath ".Modules/DebugLogHelper.psm1" -Resolve) try { $startTime = Get-Date From 6c8aaa582342a88cccb1239e1c67801aa0ab789a Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Thu, 10 Jul 2025 13:37:27 +0200 Subject: [PATCH 22/42] Testing stuff. --- Actions/.Modules/ReadSettings.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Actions/.Modules/ReadSettings.psm1 b/Actions/.Modules/ReadSettings.psm1 index 27aba1e1e..e56274b40 100644 --- a/Actions/.Modules/ReadSettings.psm1 +++ b/Actions/.Modules/ReadSettings.psm1 @@ -276,7 +276,7 @@ function ReadSettings { if (($env:GITHUB_EVENT_NAME -eq "pull_request") -and ($branchName -eq $ENV:GITHUB_REF_NAME)) { $branchName = $env:GITHUB_BASE_REF } - + OutputWarning -message "Debug - testing stuff..." function GetSettingsObject { Param( [string] $path @@ -472,4 +472,4 @@ function ValidateSettings { } Export-ModuleMember -Function ReadSettings -Export-ModuleMember -Variable ALGoFolderName, ALGoSettingsFile, RepoSettingsFile, CustomTemplateRepoSettingsFile, CustomTemplateProjectSettingsFile +Export-ModuleMember -Variable ALGoFolderName, ALGoSettingsFile, RepoSettingsFile, CustomTemplateRepoSettingsFile, CustomTemplateProjectSettingsFile \ No newline at end of file From fb8d73d4ce0dc1f76c31802a794aa541c05c6b5d Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Thu, 10 Jul 2025 14:11:00 +0200 Subject: [PATCH 23/42] Added detailed documentation to module. --- Actions/.Modules/DebugLogHelper.psm1 | 92 ++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 5 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 0ccf4a262..8165ff361 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -36,7 +36,15 @@ function Write-Debug-Base { Write-Host "$([char] 27)[${colorCodeMagenta}m[AL-Go-Debug]$([char] 27)[0m $Message" } -# Debug logging that is only written when additional logging is enabled +<# + .SYNOPSIS + Writes debug information if extended deubug logging is enabled. + .DESCRIPTION + Writes debug information to the console if extended debug logging is enabled. The message is prefixed with "[AL-Go-Debug]". + This is intended for debugging partner issues. + .PARAMETER Message + Message to be written to console. +#> function Write-Debug-Info { param ( [Parameter(Mandatory = $true)] @@ -48,8 +56,18 @@ function Write-Debug-Info { } } -# Function to write debug information about function calls -# The $parameters param should always be called with $MyInvocation.BoundParameters if the given function got parameters. +<# + .SYNOPSIS + Writes debug information about the function call and its parameters if extended debug logging is enabled. + .DESCRIPTION + Writes debug information about the function call and its parameters to the console if extended debug logging is enabled. + Should be called like: Write-Debug-FunctionCallInfo -FunctionName "" -Parameters $MyInvocation.BoundParameters + Or in case of no parameters: Write-Debug-FunctionCallInfo -FunctionName "". + .PARAMETER FunctionName + Name of the function being called. + .PARAMETER Parameters + Paraeters passed to the function. Should always be passed using $MyInvocation.BoundParameters. +#> function Write-Debug-FunctionCallInfo { param ( [Parameter(Mandatory = $true)] @@ -69,7 +87,14 @@ function Write-Debug-FunctionCallInfo { } } -# Helper functions to wrap logs in groups for better overview in GitHub actions +<# + .SYNOPSIS + Starts a console log group. + .DESCRIPTION + Starts a console log group. All subsequent log messages will be grouped under this message until Write-GroupEnd is called. + .PARAMETER Message + Name/Title of the group. +#> function Write-GroupStart { param ( [Parameter(Mandatory = $true)] @@ -79,11 +104,28 @@ function Write-GroupStart { Write-Host "::group::$Message" } +<# + .SYNOPSIS + Ends a console log group. + .DESCRIPTION + Ends a console log group started with Write-GroupStart. All subsequent log messages will be outside of this group. + .PARAMETER Message + Name/Title of the group. +#> function Write-GroupEnd { Write-Host "::endgroup::" } -# Regular log that is always written and supports color coding +<# + .SYNOPSIS + Writes to console with optional color. + .DESCRIPTION + Writes a message to the console with an optional color. If no color is specified, the message is written in the default console color. + .PARAMETER Message + Message to be written to console. + .PARAMETER Color + Optional color for the message. Valid values are 'Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan'. +#> function Write-Info { param ( [Parameter(Mandatory = $true)] @@ -109,6 +151,14 @@ function Write-Info { } } +<# + .SYNOPSIS + Write an error message to the console. + .DESCRIPTION + Writes an error message to the console. If running locally, it throws an exception with the message. + .PARAMETER Message + Message to be written to console. +#> function OutputError { Param( [string] $message @@ -123,6 +173,14 @@ function OutputError { } } +<# + .SYNOPSIS + Write a warning message to the console. + .DESCRIPTION + Writes a warning message to the console. If running locally, it writes the message in yellow. + .PARAMETER Message + Message to be written to console. +#> function OutputWarning { Param( [string] $message @@ -136,6 +194,14 @@ function OutputWarning { } } +<# + .SYNOPSIS + Write a notice message to the console. + .DESCRIPTION + Writes a notice message to the console. If running locally, it writes the message in blue. + .PARAMETER Message + Message to be written to console. +#> function OutputNotice { Param( [string] $message @@ -149,6 +215,14 @@ function OutputNotice { } } +<# + .SYNOPSIS + Mask a value in the log. + .DESCRIPTION + Masks a value in the log to prevent sensitive information from being displayed. If running locally, it writes the masked value to the console. + .PARAMETER Value + The value to be masked in the log. +#> function MaskValueInLog { Param( [string] $value @@ -159,6 +233,14 @@ function MaskValueInLog { } } +<# + .SYNOPSIS + Write a debug message to the console. + .DESCRIPTION + Writes a debug message to the console. If running locally, it writes the message in magenta. + .PARAMETER Message + Message to be written to console. +#> function OutputDebug { Param( [string] $message From 96fa8edafba0e091f7d28dfb5ee5b5f7bf7a411b Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Thu, 10 Jul 2025 14:11:09 +0200 Subject: [PATCH 24/42] Removed debug log. --- Actions/.Modules/ReadSettings.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/.Modules/ReadSettings.psm1 b/Actions/.Modules/ReadSettings.psm1 index e56274b40..28a107ad7 100644 --- a/Actions/.Modules/ReadSettings.psm1 +++ b/Actions/.Modules/ReadSettings.psm1 @@ -276,7 +276,7 @@ function ReadSettings { if (($env:GITHUB_EVENT_NAME -eq "pull_request") -and ($branchName -eq $ENV:GITHUB_REF_NAME)) { $branchName = $env:GITHUB_BASE_REF } - OutputWarning -message "Debug - testing stuff..." + function GetSettingsObject { Param( [string] $path From ad0e5196bd86024cdcc1c02ec4e36d1844207c67 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Thu, 10 Jul 2025 14:15:36 +0200 Subject: [PATCH 25/42] Loading debug module in AL-Go helper. --- Actions/AL-Go-Helper.ps1 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Actions/AL-Go-Helper.ps1 b/Actions/AL-Go-Helper.ps1 index dd9293194..1e5d3a8bc 100644 --- a/Actions/AL-Go-Helper.ps1 +++ b/Actions/AL-Go-Helper.ps1 @@ -4,6 +4,7 @@ Param( $gitHubHelperPath = Join-Path $PSScriptRoot 'Github-Helper.psm1' $readSettingsModule = Join-Path $PSScriptRoot '.Modules/ReadSettings.psm1' +$debugLoggingModule = Join-Path $PSScriptRoot '.Modules/DebugLogHelper.psm1' if (Test-Path $gitHubHelperPath) { Import-Module $gitHubHelperPath # If we are adding more dependencies here, then localDevEnv and cloudDevEnv needs to be updated @@ -13,6 +14,10 @@ if (Test-Path $readSettingsModule) { Import-Module $readSettingsModule } +if (Test-Path $debugLoggingModule) { + Import-Module $debugLoggingModule +} + $errorActionPreference = "Stop"; $ProgressPreference = "SilentlyContinue"; Set-StrictMode -Version 2.0 $ALGoFolderName = '.AL-Go' From eef9886cbcf7557ed768c311bf37f7e0fb2d87a6 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Thu, 10 Jul 2025 14:19:27 +0200 Subject: [PATCH 26/42] Fixing path to debug module in test helper. --- Tests/TestActionsHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/TestActionsHelper.psm1 b/Tests/TestActionsHelper.psm1 index 78af1c516..95bcc85dd 100644 --- a/Tests/TestActionsHelper.psm1 +++ b/Tests/TestActionsHelper.psm1 @@ -2,7 +2,7 @@ $env:GITHUB_OUTPUT = [System.IO.Path]::GetTempFileName() -Import-Module (Join-Path $PSScriptRoot '../Actions/DebugLogHelper.psm1') -Global +Import-Module (Join-Path $PSScriptRoot '../Actions/.Modules/DebugLogHelper.psm1') -Global function iReplace { Param( From 7b0389c7e273ece6d61a21d2ad8aa0c69870d115 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Thu, 10 Jul 2025 14:23:04 +0200 Subject: [PATCH 27/42] pre-commit --- Actions/.Modules/DebugLogHelper.psm1 | 2 +- Actions/.Modules/ReadSettings.psm1 | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 8165ff361..a2d529999 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -255,4 +255,4 @@ function OutputDebug { } Export-ModuleMember -Function Write-Debug-Info, Write-Debug-FunctionCallInfo, Write-GroupStart, Write-GroupEnd, Write-Info, OutputError, OutputWarning, OutputNotice, MaskValueInLog, OutputDebug -Export-ModuleMember -Variable debugLoggingEnabled \ No newline at end of file +Export-ModuleMember -Variable debugLoggingEnabled diff --git a/Actions/.Modules/ReadSettings.psm1 b/Actions/.Modules/ReadSettings.psm1 index 28a107ad7..27aba1e1e 100644 --- a/Actions/.Modules/ReadSettings.psm1 +++ b/Actions/.Modules/ReadSettings.psm1 @@ -276,7 +276,7 @@ function ReadSettings { if (($env:GITHUB_EVENT_NAME -eq "pull_request") -and ($branchName -eq $ENV:GITHUB_REF_NAME)) { $branchName = $env:GITHUB_BASE_REF } - + function GetSettingsObject { Param( [string] $path @@ -472,4 +472,4 @@ function ValidateSettings { } Export-ModuleMember -Function ReadSettings -Export-ModuleMember -Variable ALGoFolderName, ALGoSettingsFile, RepoSettingsFile, CustomTemplateRepoSettingsFile, CustomTemplateProjectSettingsFile \ No newline at end of file +Export-ModuleMember -Variable ALGoFolderName, ALGoSettingsFile, RepoSettingsFile, CustomTemplateRepoSettingsFile, CustomTemplateProjectSettingsFile From 6030d7acf990a25d217a99334292eafd8334b328 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 11:43:30 +0200 Subject: [PATCH 28/42] Comment explaining Char27 --- Actions/.Modules/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index a2d529999..8975cdcd4 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -32,7 +32,7 @@ function Write-Debug-Base { [Parameter(Mandatory = $true)] [string] $Message ) - + # Char 27 is the escape character for ANSI sequences. PowerShell 7 can use `e, but this is not supported in PowerShell 5. Write-Host "$([char] 27)[${colorCodeMagenta}m[AL-Go-Debug]$([char] 27)[0m $Message" } From 5f60c7f76070f09145c90bffa009848b16330454 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 11:43:42 +0200 Subject: [PATCH 29/42] Loading debug module in local dev env. --- Templates/AppSource App/.AL-Go/localDevEnv.ps1 | 2 ++ Templates/Per Tenant Extension/.AL-Go/localDevEnv.ps1 | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Templates/AppSource App/.AL-Go/localDevEnv.ps1 b/Templates/AppSource App/.AL-Go/localDevEnv.ps1 index 80622d5d0..e89df2b3e 100644 --- a/Templates/AppSource App/.AL-Go/localDevEnv.ps1 +++ b/Templates/AppSource App/.AL-Go/localDevEnv.ps1 @@ -57,12 +57,14 @@ $tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().To New-Item -Path $tmpFolder -ItemType Directory -Force | Out-Null $GitHubHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Github-Helper.psm1' -folder $tmpFolder -notifyAuthenticatedAttempt $ReadSettingsModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/ReadSettings.psm1' -folder $tmpFolder +$debugLoggingModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/DebugLogHelper.psm1' -folder $tmpFolder $ALGoHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/AL-Go-Helper.ps1' -folder $tmpFolder DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/settings.schema.json' -folder $tmpFolder | Out-Null DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Packages.json' -folder $tmpFolder | Out-Null Import-Module $GitHubHelperPath Import-Module $ReadSettingsModule +Import-Module $debugLoggingModule . $ALGoHelperPath -local $baseFolder = GetBaseFolder -folder $PSScriptRoot diff --git a/Templates/Per Tenant Extension/.AL-Go/localDevEnv.ps1 b/Templates/Per Tenant Extension/.AL-Go/localDevEnv.ps1 index 80622d5d0..e89df2b3e 100644 --- a/Templates/Per Tenant Extension/.AL-Go/localDevEnv.ps1 +++ b/Templates/Per Tenant Extension/.AL-Go/localDevEnv.ps1 @@ -57,12 +57,14 @@ $tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().To New-Item -Path $tmpFolder -ItemType Directory -Force | Out-Null $GitHubHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Github-Helper.psm1' -folder $tmpFolder -notifyAuthenticatedAttempt $ReadSettingsModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/ReadSettings.psm1' -folder $tmpFolder +$debugLoggingModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/DebugLogHelper.psm1' -folder $tmpFolder $ALGoHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/AL-Go-Helper.ps1' -folder $tmpFolder DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/settings.schema.json' -folder $tmpFolder | Out-Null DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Packages.json' -folder $tmpFolder | Out-Null Import-Module $GitHubHelperPath Import-Module $ReadSettingsModule +Import-Module $debugLoggingModule . $ALGoHelperPath -local $baseFolder = GetBaseFolder -folder $PSScriptRoot From f851b03ede07ebdcffa3ea5ac38cc652683048a9 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 11:47:17 +0200 Subject: [PATCH 30/42] pre-commit --- Actions/.Modules/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 8975cdcd4..fc0fec168 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -32,7 +32,7 @@ function Write-Debug-Base { [Parameter(Mandatory = $true)] [string] $Message ) - # Char 27 is the escape character for ANSI sequences. PowerShell 7 can use `e, but this is not supported in PowerShell 5. + # Char 27 is the escape character for ANSI sequences. PowerShell 7 can use `e, but this is not supported in PowerShell 5. Write-Host "$([char] 27)[${colorCodeMagenta}m[AL-Go-Debug]$([char] 27)[0m $Message" } From e549385ef9e04fa0a8c74c1afa99e2cdff7bc571 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 16:22:20 +0200 Subject: [PATCH 31/42] Using GitHub ::debug:: functionality. --- Actions/.Modules/DebugLogHelper.psm1 | 94 +++++++++++++--------------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index fc0fec168..b318d346f 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -1,9 +1,7 @@ if ($env:GITHUB_ACTIONS -eq "true") { - Write-Host "Running in GitHub Actions" $runningLocal = $false } else { - Write-Host "Running locally" $runningLocal = $true } @@ -27,35 +25,6 @@ $colorCodeBlue = '34' $colorCodeMagenta = '35' $colorCodeCyan = '36' -function Write-Debug-Base { - param ( - [Parameter(Mandatory = $true)] - [string] $Message - ) - # Char 27 is the escape character for ANSI sequences. PowerShell 7 can use `e, but this is not supported in PowerShell 5. - Write-Host "$([char] 27)[${colorCodeMagenta}m[AL-Go-Debug]$([char] 27)[0m $Message" -} - -<# - .SYNOPSIS - Writes debug information if extended deubug logging is enabled. - .DESCRIPTION - Writes debug information to the console if extended debug logging is enabled. The message is prefixed with "[AL-Go-Debug]". - This is intended for debugging partner issues. - .PARAMETER Message - Message to be written to console. -#> -function Write-Debug-Info { - param ( - [Parameter(Mandatory = $true)] - [string] $Message - ) - - if ($debugLoggingEnabled) { - Write-Debug-Base $Message - } -} - <# .SYNOPSIS Writes debug information about the function call and its parameters if extended debug logging is enabled. @@ -68,22 +37,37 @@ function Write-Debug-Info { .PARAMETER Parameters Paraeters passed to the function. Should always be passed using $MyInvocation.BoundParameters. #> -function Write-Debug-FunctionCallInfo { - param ( - [Parameter(Mandatory = $true)] - [string] $FunctionName, - [Parameter(Mandatory = $false)] - [System.Object] $Parameters = @{} - ) - - if ($debugLoggingEnabled) { - Write-Debug-Base "Function '$functionName' called with parameters:" - foreach ($param in $Parameters.Keys) { - Write-Debug-Base "- $($param): $($Parameters[$param])" - } - if ($Parameters.Count -eq 0) { - Write-Debug-Base "- None" +function OutputDebugFunctionCall { + if ($debugLoggingEnabled -or $runningLocal) { + try { + $caller = (Get-PSCallStack)[1] + $callerName = $caller.Command + $argString = $caller.Arguments + + OutputDebug "Function '$callerName' called with parameters:" + + if ($argString -match '^\{(.+)\}$') { + $inner = $matches[1] + + # Match key=value pairs, allowing for quoted strings with commas + $pattern = '(?\w+)\s*=\s*(?(?:(?!,\s*\w+\s*=).)+)' + $matches = [regex]::Matches($inner, $pattern) + + if ($matches.Count -eq 0) { + OutputDebug "No parameters found." + } + foreach ($match in $matches) { + $key = $match.Groups['key'].Value + $val = $match.Groups['value'].Value + OutputDebug "-$($key): $val" + } + } else { + OutputDebug "Unable to parse arguments." + } + } catch { + OutputDebug "Unable to parse arguments." } + } } @@ -95,13 +79,17 @@ function Write-Debug-FunctionCallInfo { .PARAMETER Message Name/Title of the group. #> -function Write-GroupStart { +function OutputGroupStart { param ( [Parameter(Mandatory = $true)] [string] $Message ) - Write-Host "::group::$Message" + if ($runningLocal) { + Write-Host "==== Group start: $Message ====" + } else { + Write-Host "::group::$Message" + } } <# @@ -112,8 +100,12 @@ function Write-GroupStart { .PARAMETER Message Name/Title of the group. #> -function Write-GroupEnd { - Write-Host "::endgroup::" +function OutputGroupEnd { + if ($runningLocal) { + Write-Host "==== Group end ====" + } else { + Write-Host "::endgroup::" + } } <# @@ -126,7 +118,7 @@ function Write-GroupEnd { .PARAMETER Color Optional color for the message. Valid values are 'Red', 'Green', 'Yellow', 'Blue', 'Magenta', 'Cyan'. #> -function Write-Info { +function OutputColor { param ( [Parameter(Mandatory = $true)] [string] $Message, From 89778f43717c877aea5d09c72edb02bdec5bee89 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 16:22:34 +0200 Subject: [PATCH 32/42] Using updated debug function names. --- .../DetermineDeploymentEnvironments.ps1 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 b/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 index 36debbdc9..0a27f9e42 100644 --- a/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 +++ b/Actions/DetermineDeploymentEnvironments/DetermineDeploymentEnvironments.ps1 @@ -5,13 +5,13 @@ [ValidateSet('CD','Publish','All')] [string] $type ) -Write-Debug-FunctionCallInfo -FunctionName "DetermineDeploymentEnvironments" -Parameters $MyInvocation.BoundParameters +OutputDebugFunctionCall function IsGitHubPagesAvailable() { - Write-Debug-FunctionCallInfo -FunctionName "IsGitHubPagesAvailable" -Parameters @{} + OutputDebugFunctionCall $headers = GetHeaders -token $env:GITHUB_TOKEN $url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/pages" - Write-Debug-Info "Url: $url" + OutputDebug "Url: $url" try { Write-Host "Requesting GitHub Pages settings from GitHub" $ghPages = (InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json @@ -23,10 +23,10 @@ function IsGitHubPagesAvailable() { } function GetGitHubEnvironments() { - Write-Debug-FunctionCallInfo -FunctionName "GetGitHubEnvironments" -Parameters @{} + OutputDebugFunctionCall $headers = GetHeaders -token $env:GITHUB_TOKEN $url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/environments" - Write-Debug-Info "Url: $url" + OutputDebug "Url: $url" try { Write-Host "Requesting environments from GitHub" $ghEnvironments = @(((InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json).environments) @@ -39,7 +39,7 @@ function GetGitHubEnvironments() { } function Get-BranchesFromPolicy($ghEnvironment) { - Write-Debug-FunctionCallInfo -FunctionName "Get-BranchesFromPolicy" -Parameters $MyInvocation.BoundParameters + OutputDebugFunctionCall if ($ghEnvironment) { # Environment is defined in GitHub - check protection rules $headers = GetHeaders -token $env:GITHUB_TOKEN From d7e1ec3c001f31e83e4d3a5e5980f268c6416fd5 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 16:28:59 +0200 Subject: [PATCH 33/42] Corrected exported names. --- Actions/.Modules/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index b318d346f..f9147b0fd 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -246,5 +246,5 @@ function OutputDebug { } } -Export-ModuleMember -Function Write-Debug-Info, Write-Debug-FunctionCallInfo, Write-GroupStart, Write-GroupEnd, Write-Info, OutputError, OutputWarning, OutputNotice, MaskValueInLog, OutputDebug +Export-ModuleMember -Function OutputColor, OutputDebugFunctionCall, OutputGroupStart, OutputGroupEnd, OutputError, OutputWarning, OutputNotice, MaskValueInLog, OutputDebug Export-ModuleMember -Variable debugLoggingEnabled From 1f90d932d0cb314e48805ece37a20c4d98db40ef Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 16:37:02 +0200 Subject: [PATCH 34/42] Corrected regex and added AL-Go prefix to debug messages. --- Actions/.Modules/DebugLogHelper.psm1 | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index f9147b0fd..45fd324a7 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -46,7 +46,7 @@ function OutputDebugFunctionCall { OutputDebug "Function '$callerName' called with parameters:" - if ($argString -match '^\{(.+)\}$') { + if ($argString -match '^\{(.*)\}$') { $inner = $matches[1] # Match key=value pairs, allowing for quoted strings with commas @@ -54,7 +54,7 @@ function OutputDebugFunctionCall { $matches = [regex]::Matches($inner, $pattern) if ($matches.Count -eq 0) { - OutputDebug "No parameters found." + OutputDebug "None" } foreach ($match in $matches) { $key = $match.Groups['key'].Value @@ -242,7 +242,7 @@ function OutputDebug { Write-Host $message } else { - Write-Host "::Debug::$message" + Write-Host "::Debug::[AL-Go]$message" } } From 9108ca2afe1e4b1bb0f9488a14d8fe8851b5ced7 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 16:41:07 +0200 Subject: [PATCH 35/42] Documentation correction --- Actions/.Modules/DebugLogHelper.psm1 | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 45fd324a7..2ab66e102 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -30,12 +30,7 @@ $colorCodeCyan = '36' Writes debug information about the function call and its parameters if extended debug logging is enabled. .DESCRIPTION Writes debug information about the function call and its parameters to the console if extended debug logging is enabled. - Should be called like: Write-Debug-FunctionCallInfo -FunctionName "" -Parameters $MyInvocation.BoundParameters - Or in case of no parameters: Write-Debug-FunctionCallInfo -FunctionName "". - .PARAMETER FunctionName - Name of the function being called. - .PARAMETER Parameters - Paraeters passed to the function. Should always be passed using $MyInvocation.BoundParameters. + Automatically retrieves the caller's name and arguments from the call stack. #> function OutputDebugFunctionCall { if ($debugLoggingEnabled -or $runningLocal) { From 7bee9846f7720239f7b114c04e2fef8aeaff9c02 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Fri, 11 Jul 2025 16:49:54 +0200 Subject: [PATCH 36/42] Pre-commit + changing variable name. --- Actions/.Modules/DebugLogHelper.psm1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 2ab66e102..67b28b41e 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -34,24 +34,24 @@ $colorCodeCyan = '36' #> function OutputDebugFunctionCall { if ($debugLoggingEnabled -or $runningLocal) { - try { + try { $caller = (Get-PSCallStack)[1] $callerName = $caller.Command $argString = $caller.Arguments OutputDebug "Function '$callerName' called with parameters:" - + if ($argString -match '^\{(.*)\}$') { $inner = $matches[1] # Match key=value pairs, allowing for quoted strings with commas $pattern = '(?\w+)\s*=\s*(?(?:(?!,\s*\w+\s*=).)+)' - $matches = [regex]::Matches($inner, $pattern) + $regexMatches = [regex]::Matches($inner, $pattern) - if ($matches.Count -eq 0) { + if ($regexMatches.Count -eq 0) { OutputDebug "None" } - foreach ($match in $matches) { + foreach ($match in $regexMatches) { $key = $match.Groups['key'].Value $val = $match.Groups['value'].Value OutputDebug "-$($key): $val" @@ -62,7 +62,7 @@ function OutputDebugFunctionCall { } catch { OutputDebug "Unable to parse arguments." } - + } } @@ -100,7 +100,7 @@ function OutputGroupEnd { Write-Host "==== Group end ====" } else { Write-Host "::endgroup::" - } + } } <# From 0dc0d5745015e345f8ffa8ddab3072c373aad504 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 14 Jul 2025 10:57:09 +0200 Subject: [PATCH 37/42] Using .InvocationInfo.BoundParamters to fetch function parameters. --- Actions/.Modules/DebugLogHelper.psm1 | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 67b28b41e..3518e9d43 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -37,32 +37,19 @@ function OutputDebugFunctionCall { try { $caller = (Get-PSCallStack)[1] $callerName = $caller.Command - $argString = $caller.Arguments + $callerParameters = $caller.InvocationInfo.BoundParameters OutputDebug "Function '$callerName' called with parameters:" - - if ($argString -match '^\{(.*)\}$') { - $inner = $matches[1] - - # Match key=value pairs, allowing for quoted strings with commas - $pattern = '(?\w+)\s*=\s*(?(?:(?!,\s*\w+\s*=).)+)' - $regexMatches = [regex]::Matches($inner, $pattern) - - if ($regexMatches.Count -eq 0) { - OutputDebug "None" - } - foreach ($match in $regexMatches) { - $key = $match.Groups['key'].Value - $val = $match.Groups['value'].Value - OutputDebug "-$($key): $val" - } - } else { - OutputDebug "Unable to parse arguments." + if ($callerParameters.Count -eq 0) { + OutputDebug "None" + } + foreach ($key in $callerParameters.Keys) { + $val = $callerParameters[$key] + OutputDebug "-$($key): $val" } } catch { OutputDebug "Unable to parse arguments." } - } } From b7557c7d0075616e105e9ee4dce6bec75240df13 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 14 Jul 2025 10:58:50 +0200 Subject: [PATCH 38/42] Using Write-Debug instead of Write-Host for running locally. --- Actions/.Modules/DebugLogHelper.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 3518e9d43..cff07f08c 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -221,7 +221,7 @@ function OutputDebug { ) if ($runningLocal) { - Write-Host $message + Write-Debug $message } else { Write-Host "::Debug::[AL-Go]$message" From 7d5ee432e453625bbf05bd9d55031c54648b094a Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Mon, 14 Jul 2025 11:00:47 +0200 Subject: [PATCH 39/42] Adding debug module to cloudDevEnv. --- Templates/AppSource App/.AL-Go/cloudDevEnv.ps1 | 2 ++ Templates/Per Tenant Extension/.AL-Go/cloudDevEnv.ps1 | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Templates/AppSource App/.AL-Go/cloudDevEnv.ps1 b/Templates/AppSource App/.AL-Go/cloudDevEnv.ps1 index a07cdb19a..e4f79e668 100644 --- a/Templates/AppSource App/.AL-Go/cloudDevEnv.ps1 +++ b/Templates/AppSource App/.AL-Go/cloudDevEnv.ps1 @@ -53,12 +53,14 @@ $tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().To New-Item -Path $tmpFolder -ItemType Directory -Force | Out-Null $GitHubHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Github-Helper.psm1' -folder $tmpFolder -notifyAuthenticatedAttempt $ReadSettingsModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/ReadSettings.psm1' -folder $tmpFolder +$debugLoggingModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/DebugLogHelper.psm1' -folder $tmpFolder $ALGoHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/AL-Go-Helper.ps1' -folder $tmpFolder DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/settings.schema.json' -folder $tmpFolder | Out-Null DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Packages.json' -folder $tmpFolder | Out-Null Import-Module $GitHubHelperPath Import-Module $ReadSettingsModule +Import-Module $debugLoggingModule . $ALGoHelperPath -local $baseFolder = GetBaseFolder -folder $PSScriptRoot diff --git a/Templates/Per Tenant Extension/.AL-Go/cloudDevEnv.ps1 b/Templates/Per Tenant Extension/.AL-Go/cloudDevEnv.ps1 index a07cdb19a..e4f79e668 100644 --- a/Templates/Per Tenant Extension/.AL-Go/cloudDevEnv.ps1 +++ b/Templates/Per Tenant Extension/.AL-Go/cloudDevEnv.ps1 @@ -53,12 +53,14 @@ $tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().To New-Item -Path $tmpFolder -ItemType Directory -Force | Out-Null $GitHubHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Github-Helper.psm1' -folder $tmpFolder -notifyAuthenticatedAttempt $ReadSettingsModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/ReadSettings.psm1' -folder $tmpFolder +$debugLoggingModule = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/.Modules/DebugLogHelper.psm1' -folder $tmpFolder $ALGoHelperPath = DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/AL-Go-Helper.ps1' -folder $tmpFolder DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/settings.schema.json' -folder $tmpFolder | Out-Null DownloadHelperFile -url 'https://raw.githubusercontent.com/microsoft/AL-Go-Actions/main/Packages.json' -folder $tmpFolder | Out-Null Import-Module $GitHubHelperPath Import-Module $ReadSettingsModule +Import-Module $debugLoggingModule . $ALGoHelperPath -local $baseFolder = GetBaseFolder -folder $PSScriptRoot From 0048d745e54dcdd968e7cdee0a4f2afc0586472e Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Tue, 15 Jul 2025 12:03:56 +0200 Subject: [PATCH 40/42] Using Write-Warning when running locally and removed manual check on debug mode, as we automatically handle that now. --- Actions/.Modules/DebugLogHelper.psm1 | 44 ++++++++++------------------ 1 file changed, 15 insertions(+), 29 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index cff07f08c..67585aa37 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -5,18 +5,6 @@ if ($env:GITHUB_ACTIONS -eq "true") { $runningLocal = $true } -$debugLoggingEnabled = $false -try { - if ($env:RUNNER_DEBUG -eq 1) { - $debugLoggingEnabled = $true - Write-Host "AL-Go extended debug logging is enabled." - } else { - Write-Host "AL-Go extended debug logging is disabled." - } -} catch { - Write-Host "Failed to parse RUNNER_DEBUG environment variable. Defaulting to false." -} - # Colors $colorCodeRed = '31' $colorCodeGreen = '32' @@ -33,23 +21,21 @@ $colorCodeCyan = '36' Automatically retrieves the caller's name and arguments from the call stack. #> function OutputDebugFunctionCall { - if ($debugLoggingEnabled -or $runningLocal) { - try { - $caller = (Get-PSCallStack)[1] - $callerName = $caller.Command - $callerParameters = $caller.InvocationInfo.BoundParameters - - OutputDebug "Function '$callerName' called with parameters:" - if ($callerParameters.Count -eq 0) { - OutputDebug "None" - } - foreach ($key in $callerParameters.Keys) { - $val = $callerParameters[$key] - OutputDebug "-$($key): $val" - } - } catch { - OutputDebug "Unable to parse arguments." + try { + $caller = (Get-PSCallStack)[1] + $callerName = $caller.Command + $callerParameters = $caller.InvocationInfo.BoundParameters + + OutputDebug "Function '$callerName' called with parameters:" + if ($callerParameters.Count -eq 0) { + OutputDebug "None" + } + foreach ($key in $callerParameters.Keys) { + $val = $callerParameters[$key] + OutputDebug "-$($key): $val" } + } catch { + OutputDebug "Unable to parse arguments." } } @@ -161,7 +147,7 @@ function OutputWarning { ) if ($runningLocal) { - Write-Host -ForegroundColor Yellow "WARNING: $message" + Write-Warning $message } else { Write-Host "::Warning::$message" From b6c38768f0559f586af45512aacce0f5a9d680ab Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Tue, 15 Jul 2025 15:28:52 +0200 Subject: [PATCH 41/42] Improved function documentation. --- Actions/.Modules/DebugLogHelper.psm1 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Actions/.Modules/DebugLogHelper.psm1 b/Actions/.Modules/DebugLogHelper.psm1 index 67585aa37..335ac82d0 100644 --- a/Actions/.Modules/DebugLogHelper.psm1 +++ b/Actions/.Modules/DebugLogHelper.psm1 @@ -15,9 +15,9 @@ $colorCodeCyan = '36' <# .SYNOPSIS - Writes debug information about the function call and its parameters if extended debug logging is enabled. + Writes debug information about the function call and its parameters if extended debug logging is enabled or running locally. .DESCRIPTION - Writes debug information about the function call and its parameters to the console if extended debug logging is enabled. + Writes debug information about the function call and its parameters to the console if extended debug logging is enabled or running locally. Automatically retrieves the caller's name and arguments from the call stack. #> function OutputDebugFunctionCall { @@ -35,7 +35,7 @@ function OutputDebugFunctionCall { OutputDebug "-$($key): $val" } } catch { - OutputDebug "Unable to parse arguments." + OutputDebug "Unable to retrieve function information from call stack." } } @@ -43,7 +43,8 @@ function OutputDebugFunctionCall { .SYNOPSIS Starts a console log group. .DESCRIPTION - Starts a console log group. All subsequent log messages will be grouped under this message until Write-GroupEnd is called. + Starts a console log group. All subsequent log messages will be grouped under this message until OutputGroupEnd is called. + If running locally, it writes a simple message to the console. If running in GitHub Actions, it uses the `::group::` command to create a collapsible group in the log. .PARAMETER Message Name/Title of the group. #> @@ -64,9 +65,7 @@ function OutputGroupStart { .SYNOPSIS Ends a console log group. .DESCRIPTION - Ends a console log group started with Write-GroupStart. All subsequent log messages will be outside of this group. - .PARAMETER Message - Name/Title of the group. + Ends a console log group started with OutputGroupStart. All subsequent log messages will be outside of this group. #> function OutputGroupEnd { if ($runningLocal) { @@ -105,6 +104,7 @@ function OutputColor { 'Magenta' { $colorCode = $colorCodeMagenta } 'Cyan' { $colorCode = $colorCodeCyan } } + # char 27 is the escape character for ANSI codes which works in both PS 5 and 7. Write-Host "$([char] 27)[${colorCode}m$Message$([char] 27)[0m" } else { Write-Host $Message @@ -115,7 +115,7 @@ function OutputColor { .SYNOPSIS Write an error message to the console. .DESCRIPTION - Writes an error message to the console. If running locally, it throws an exception with the message. + Writes an error message to the console. Throws an exception if running locally, otherwise formats the message for GitHub Actions. .PARAMETER Message Message to be written to console. #> @@ -137,7 +137,7 @@ function OutputError { .SYNOPSIS Write a warning message to the console. .DESCRIPTION - Writes a warning message to the console. If running locally, it writes the message in yellow. + Writes a warning message to the console. Uses Write-Warning if running locally, otherwise formats the message for GitHub Actions. .PARAMETER Message Message to be written to console. #> @@ -158,7 +158,7 @@ function OutputWarning { .SYNOPSIS Write a notice message to the console. .DESCRIPTION - Writes a notice message to the console. If running locally, it writes the message in blue. + Writes a notice message to the console. Uses regular Write-Host if running locally, otherwise formats the message for GitHub Actions. .PARAMETER Message Message to be written to console. #> @@ -197,7 +197,7 @@ function MaskValueInLog { .SYNOPSIS Write a debug message to the console. .DESCRIPTION - Writes a debug message to the console. If running locally, it writes the message in magenta. + Writes a debug message to the console. Uses Write-Debug if running locally, otherwise formats the message for GitHub Actions. .PARAMETER Message Message to be written to console. #> From c639a366fdc283940b7ada201a1e74beb5ca05c7 Mon Sep 17 00:00:00 2001 From: Sebastian Petersen Date: Tue, 15 Jul 2025 15:28:59 +0200 Subject: [PATCH 42/42] Added release notes. --- RELEASENOTES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 77d47b039..3a72d9985 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -9,6 +9,10 @@ AL-Go now offers a dataexplorer dashboard to get started with AL-Go telemetry. A - Issue 1722 Check if apps are already installed on a higher version before deploying - Issue 1774 Increment Version Number with +0.1 can increment some version numbers twice +### Additional debug logging functionality + +We have improved how logging is handled in AL-Go, and now make better use of GitHub built-in extended debug logging functionality. Extended debug logging can be enabled when re-running actions by clicking the 'Enable debug logging' checkbox in the pop-up window. This can be done both for jobs that failed and jobs that succeeded, but did not produce the correct result. + ### Add custom jobs to AL-Go workflows It is now possible to add custom jobs to AL-Go workflows. The Custom Job needs to be named `CustomJob` and should be placed after all other jobs in the .yaml file. The order of which jobs are executed is determined by the Needs statements. Your custom job will be executed after all jobs specified in the Needs clause in your job and if you need the job to be executed before other jobs, you should add the job name in the Needs clause of that job. See [https://aka.ms/algosettings#customjobs](https://aka.ms/algosettings#customjobs) for details.