Skip to content

Commit 33fe31e

Browse files
🩹 [Patch]: Add Set-GitHubLogGroup function for logging in GitHub Actions (#4)
## Description This pull request introduces a new PowerShell function, `Set-GitHubLogGroup`, in the `scripts/Helpers/Helpers.psm1` file. The function provides a DSL approach for grouping log lines in GitHub Actions workflows, improving log organization and readability. ### New functionality for GitHub Actions: * [`scripts/Helpers/Helpers.psm1`](diffhunk://#diff-4e1a856788c23834d4b062715a48c6a81d985b1f7843a8a7f14fc767e561552fR1111-R1165): Added the `Set-GitHubLogGroup` function, which encapsulates commands within a log group for GitHub Actions. It includes support for creating named log groups using the `-Name` parameter and executing a provided `ScriptBlock`. An alias `LogGroup` is also defined for convenience. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 938a96c commit 33fe31e

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)