Skip to content

Commit 4caa554

Browse files
Add Set-GitHubLogGroup function for logging in GitHub Actions
1 parent 938a96c commit 4caa554

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

scripts/Helpers/Helpers.psm1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,3 +1108,58 @@ function Add-PSModulePath {
11081108
Write-Verbose " - [$_]"
11091109
}
11101110
}
1111+
1112+
function Set-GitHubLogGroup {
1113+
<#
1114+
.SYNOPSIS
1115+
Encapsulates commands with a log group in GitHub Actions
1116+
1117+
.DESCRIPTION
1118+
DSL approach for GitHub Action commands.
1119+
Allows for colapsing of code in IDE for code that belong together.
1120+
1121+
.EXAMPLE
1122+
Set-GitHubLogGroup -Name 'MyGroup' -ScriptBlock {
1123+
Write-Host 'Hello, World!'
1124+
}
1125+
1126+
Creates a new log group named 'MyGroup' and writes 'Hello, World!' to the output.
1127+
1128+
.EXAMPLE
1129+
LogGroup 'MyGroup' {
1130+
Write-Host 'Hello, World!'
1131+
}
1132+
1133+
Uses the alias 'LogGroup' to create a new log group named 'MyGroup' and writes 'Hello, World!' to the output.
1134+
1135+
.NOTES
1136+
[GitHub - Grouping log lines](https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines)
1137+
1138+
.LINK
1139+
https://psmodule.io/GitHub/Functions/Commands/Set-GitHubLogGroup
1140+
#>
1141+
[Alias('LogGroup')]
1142+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1143+
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
1144+
Justification = 'Does not change state'
1145+
)]
1146+
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
1147+
'PSAvoidUsingWriteHost', '', Scope = 'Function',
1148+
Justification = 'Intended for logging in Github Runners which does support Write-Host'
1149+
)]
1150+
[CmdletBinding()]
1151+
param(
1152+
# The name of the log group
1153+
[Parameter(Mandatory)]
1154+
[string] $Name,
1155+
1156+
# The script block to execute
1157+
[Parameter(Mandatory)]
1158+
[scriptblock] $ScriptBlock
1159+
)
1160+
1161+
Write-Host "::group::$Name"
1162+
. $ScriptBlock
1163+
Write-Host '::endgroup::'
1164+
}
1165+

0 commit comments

Comments
 (0)