Skip to content
Merged
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions src/public/Commands/Set-LogGroup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
function Set-LogGroup {
<#
.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-LogGroup -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/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines)
#>
[Alias('LogGroup')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute(
'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function',
Justification = 'Does not change state'
)]
[CmdletBinding()]
param(
# The name of the log group
[Parameter(Mandatory)]
[string] $Name,

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

Start-LogGroup -Name $Name
. $ScriptBlock
Stop-LogGroup
}
31 changes: 31 additions & 0 deletions src/public/Commands/Start-LogGroup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
function Start-LogGroup {
<#
.SYNOPSIS
Starts a log group in GitHub Actions

.EXAMPLE
New-LogGroup 'MyGroup'

Starts a new log group named 'MyGroup'

.NOTES
[GitHub - Grouping log lines](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines)
#>
[Alias('New-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
)

Write-Host "::group::$Name"
}
27 changes: 27 additions & 0 deletions src/public/Commands/Stop-LogGroup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
function Stop-LogGroup {
<#
.SYNOPSIS
Stops the current log group in GitHub Actions

.EXAMPLE
Stop-LogGroup

Starts a new log group named 'MyGroup'

.NOTES
[GitHub - Grouping log lines](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#grouping-log-lines)
#>
[Alias('End-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'
)]
[CmdletBinding()]
param()

Write-Host '::endgroup::'
}
33 changes: 33 additions & 0 deletions tests/Commands.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[CmdletBinding()]
Param(
# Path to the module to test.
[Parameter()]
[string] $Path
)

Write-Verbose "Path to the module: [$Path]" -Verbose

Describe 'Commands' {
It "Start-LogGroup 'MyGroup' should not throw" {
{
Start-LogGroup 'MyGroup'
} | Should -Not -Throw
}

It 'Stop-LogGroup should not throw' {
{
Stop-LogGroup
} | Should -Not -Throw
}

It "LogGroup 'MyGroup' should not throw" {
{
LogGroup 'MyGroup' {
Get-ChildItem env: | Select-Object Name, Value | Format-Table -AutoSize
}
} | Should -Not -Throw
}
}