Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions scripts/Helpers/Helpers.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1108,3 +1108,58 @@ function Add-PSModulePath {
Write-Verbose " - [$_]"
}
}

function Set-GitHubLogGroup {
<#
.SYNOPSIS
Encapsulates commands with a log group in GitHub Actions

.DESCRIPTION
DSL approach for GitHub Action commands.
Allows for colapsing of code in IDE for code that belong together.

.EXAMPLE
Set-GitHubLogGroup -Name 'MyGroup' -ScriptBlock {
Write-Host 'Hello, World!'
}

Creates a new log group named 'MyGroup' and writes 'Hello, World!' to the output.

.EXAMPLE
LogGroup 'MyGroup' {
Write-Host 'Hello, World!'
}

Uses the alias 'LogGroup' to create a new log group named 'MyGroup' and writes 'Hello, World!' to the output.

.NOTES
[GitHub - Grouping log lines](https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines)

.LINK
https://psmodule.io/GitHub/Functions/Commands/Set-GitHubLogGroup
#>
[Alias('LogGroup')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
Justification = 'Does not change state'
)]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSAvoidUsingWriteHost', '', Scope = 'Function',
Justification = 'Intended for logging in Github Runners which does support Write-Host'
)]
[CmdletBinding()]
param(
# The name of the log group
[Parameter(Mandatory)]
[string] $Name,

# The script block to execute
[Parameter(Mandatory)]
[scriptblock] $ScriptBlock
)

Write-Host "::group::$Name"
. $ScriptBlock
Write-Host '::endgroup::'
}

Loading