Skip to content

Extended debug logging #1729

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

Merged
merged 54 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
c3309d5
Importing debug helper.
spetersenms May 12, 2025
68b9759
First draft of debug helper
spetersenms May 12, 2025
3fd68e6
Testing new debug helper functions.
spetersenms May 12, 2025
934bf8f
Changing type for param
spetersenms May 12, 2025
4520382
Log info on debug log variable.
spetersenms May 12, 2025
90e03b1
Add debug context var to env variable.
spetersenms May 12, 2025
fd9969d
Removed runner context from top level env statement as it's not avail…
spetersenms May 12, 2025
fe23a7a
Testing injecting runner context in action environment var section.
spetersenms May 12, 2025
db7531a
Added [Debug] tag to debug logs.
spetersenms May 13, 2025
c3d4a4d
Merge branch 'main' into ExtendedDebugLogging
spetersenms May 15, 2025
9f05255
Testing RUNNER_DEBUG variable.
spetersenms May 19, 2025
70fdfb2
Switching to use RUNNER_DEBUG env var instead of passing github context.
spetersenms May 19, 2025
44ae296
Improved formatting of debug messages.
spetersenms May 19, 2025
c268aa8
Coloring debug output
spetersenms May 19, 2025
9e83be6
Using escape char that works in both Pwsh 5 and 7
spetersenms May 19, 2025
d3b265f
Importing debug log helper in tests.
spetersenms May 21, 2025
72ec7b2
Importing logging module globally to make it useable by tests.
spetersenms May 21, 2025
da61332
pre-commit
spetersenms May 21, 2025
28d548b
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jun 16, 2025
47b7f68
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jun 16, 2025
e1c006b
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jun 17, 2025
6dae42f
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jun 18, 2025
0875483
Fixed inconsistent log.
spetersenms Jun 23, 2025
6ea22d4
Made parameters param of function debug optional, added helper functi…
spetersenms Jun 23, 2025
17224be
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jun 23, 2025
868b910
pre-commit
spetersenms Jul 7, 2025
8d571fc
Merge branch 'ExtendedDebugLogging' of github.com:spetersenms/AL-Go i…
spetersenms Jul 7, 2025
b00a679
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jul 7, 2025
2168fb1
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jul 10, 2025
5f11ac6
Moving debug module to module folder, and including OutPut* functions…
spetersenms Jul 10, 2025
6c8aaa5
Testing stuff.
spetersenms Jul 10, 2025
fb8d73d
Added detailed documentation to module.
spetersenms Jul 10, 2025
96fa8ed
Removed debug log.
spetersenms Jul 10, 2025
ad0e519
Loading debug module in AL-Go helper.
spetersenms Jul 10, 2025
eef9886
Fixing path to debug module in test helper.
spetersenms Jul 10, 2025
7b0389c
pre-commit
spetersenms Jul 10, 2025
6030d7a
Comment explaining Char27
spetersenms Jul 11, 2025
5f60c7f
Loading debug module in local dev env.
spetersenms Jul 11, 2025
f851b03
pre-commit
spetersenms Jul 11, 2025
e549385
Using GitHub ::debug:: functionality.
spetersenms Jul 11, 2025
89778f4
Using updated debug function names.
spetersenms Jul 11, 2025
d7e1ec3
Corrected exported names.
spetersenms Jul 11, 2025
1f90d93
Corrected regex and added AL-Go prefix to debug messages.
spetersenms Jul 11, 2025
9108ca2
Documentation correction
spetersenms Jul 11, 2025
7bee984
Pre-commit + changing variable name.
spetersenms Jul 11, 2025
0dc0d57
Using .InvocationInfo.BoundParamters to fetch function parameters.
spetersenms Jul 14, 2025
b7557c7
Using Write-Debug instead of Write-Host for running locally.
spetersenms Jul 14, 2025
7d5ee43
Adding debug module to cloudDevEnv.
spetersenms Jul 14, 2025
13eebc5
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jul 14, 2025
96baa72
Merge branch 'main' into ExtendedDebugLogging
spetersenms Jul 15, 2025
0048d74
Using Write-Warning when running locally and removed manual check on …
spetersenms Jul 15, 2025
999b33f
Merge branch 'ExtendedDebugLogging' of github.com:spetersenms/AL-Go i…
spetersenms Jul 15, 2025
b6c3876
Improved function documentation.
spetersenms Jul 15, 2025
c639a36
Added release notes.
spetersenms Jul 15, 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
218 changes: 218 additions & 0 deletions Actions/.Modules/DebugLogHelper.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@

if ($env:GITHUB_ACTIONS -eq "true") {
$runningLocal = $false
} else {
$runningLocal = $true
}

# Colors
$colorCodeRed = '31'
$colorCodeGreen = '32'
$colorCodeYellow = '33'
$colorCodeBlue = '34'
$colorCodeMagenta = '35'
$colorCodeCyan = '36'

<#
.SYNOPSIS
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 or running locally.
Automatically retrieves the caller's name and arguments from the call stack.
#>
function OutputDebugFunctionCall {
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 retrieve function information from call stack."
}
}

<#
.SYNOPSIS
Starts a console log group.
.DESCRIPTION
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.
#>
function OutputGroupStart {
param (
[Parameter(Mandatory = $true)]
[string] $Message
)

if ($runningLocal) {
Write-Host "==== Group start: $Message ===="
} else {
Write-Host "::group::$Message"
}
}

<#
.SYNOPSIS
Ends a console log group.
.DESCRIPTION
Ends a console log group started with OutputGroupStart. All subsequent log messages will be outside of this group.
#>
function OutputGroupEnd {
if ($runningLocal) {
Write-Host "==== Group end ===="
} else {
Write-Host "::endgroup::"
}
}

<#
.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 OutputColor {
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 }
}
# 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
}
}

<#
.SYNOPSIS
Write an error message to the console.
.DESCRIPTION
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.
#>
function OutputError {
Param(
[string] $message
)

if ($runningLocal) {
throw $message
}
else {
Write-Host "::Error::$($message.Replace("`r",'').Replace("`n",' '))"
$host.SetShouldExit(1)
}
}

<#
.SYNOPSIS
Write a warning message to the console.
.DESCRIPTION
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.
#>
function OutputWarning {
Param(
[string] $message
)

if ($runningLocal) {
Write-Warning $message
}
else {
Write-Host "::Warning::$message"
}
}

<#
.SYNOPSIS
Write a notice message to the console.
.DESCRIPTION
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.
#>
function OutputNotice {
Param(
[string] $message
)

if ($runningLocal) {
Write-Host $message
}
else {
Write-Host "::Notice::$message"
}
}

<#
.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
)

if (!$runningLocal) {
Write-Host "`r::add-mask::$value"
}
}

<#
.SYNOPSIS
Write a debug message to the console.
.DESCRIPTION
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.
#>
function OutputDebug {
Param(
[string] $message
)

if ($runningLocal) {
Write-Debug $message
}
else {
Write-Host "::Debug::[AL-Go]$message"
}
}

Export-ModuleMember -Function OutputColor, OutputDebugFunctionCall, OutputGroupStart, OutputGroupEnd, OutputError, OutputWarning, OutputNotice, MaskValueInLog, OutputDebug
Export-ModuleMember -Variable debugLoggingEnabled
69 changes: 5 additions & 64 deletions Actions/AL-Go-Helper.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand All @@ -22,7 +27,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")

Expand Down Expand Up @@ -183,69 +187,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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
[ValidateSet('CD','Publish','All')]
[string] $type
)
OutputDebugFunctionCall

function IsGitHubPagesAvailable() {
OutputDebugFunctionCall
$headers = GetHeaders -token $env:GITHUB_TOKEN
$url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/pages"
OutputDebug "Url: $url"
try {
Write-Host "Requesting GitHub Pages settings from GitHub"
$ghPages = (InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json
Expand All @@ -20,8 +23,10 @@ function IsGitHubPagesAvailable() {
}

function GetGitHubEnvironments() {
OutputDebugFunctionCall
$headers = GetHeaders -token $env:GITHUB_TOKEN
$url = "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/environments"
OutputDebug "Url: $url"
try {
Write-Host "Requesting environments from GitHub"
$ghEnvironments = @(((InvokeWebRequest -Headers $headers -Uri $url).Content | ConvertFrom-Json).environments)
Expand All @@ -34,6 +39,7 @@ function GetGitHubEnvironments() {
}

function Get-BranchesFromPolicy($ghEnvironment) {
OutputDebugFunctionCall
if ($ghEnvironment) {
# Environment is defined in GitHub - check protection rules
$headers = GetHeaders -token $env:GITHUB_TOKEN
Expand Down
1 change: 1 addition & 0 deletions Actions/Invoke-AlGoAction.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +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 ".Modules/DebugLogHelper.psm1" -Resolve)

try {
$startTime = Get-Date
Expand Down
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<something>` 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.
Expand Down
2 changes: 2 additions & 0 deletions Templates/AppSource App/.AL-Go/cloudDevEnv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Templates/AppSource App/.AL-Go/localDevEnv.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading