Skip to content

Commit b5f2435

Browse files
committed
Add function Write-GHActionsAnnotation; Remove function attribute ValueFromPipeline for annotations
1 parent 0440cc2 commit b5f2435

File tree

2 files changed

+72
-80
lines changed

2 files changed

+72
-80
lines changed

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
'Get-GHActionsWebhookEventPayload',
7777
'Set-GHActionsOutput',
7878
'Set-GHActionsState',
79+
'Write-GHActionsAnnotation',
7980
'Write-GHActionsDebug',
8081
'Write-GHActionsError',
8182
'Write-GHActionsFail',

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psm1

Lines changed: 71 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#Requires -PSEdition Core
22
#Requires -Version 7.2
3+
enum GHActionsAnnotationType {
4+
Notice = 0
5+
Warning = 1
6+
Warn = 1
7+
Error = 2
8+
}
39
<#
410
.SYNOPSIS
511
GitHub Actions - Internal - Escape Characters
@@ -448,6 +454,63 @@ function Set-GHActionsState {
448454
}
449455
<#
450456
.SYNOPSIS
457+
GitHub Actions - Write Annotation
458+
.DESCRIPTION
459+
Prints an annotation message to the log.
460+
.PARAMETER Type
461+
Annotation type.
462+
.PARAMETER Message
463+
Message that need to log at annotation.
464+
.PARAMETER File
465+
Issue file path.
466+
.PARAMETER Line
467+
Issue file line start.
468+
.PARAMETER Col
469+
Issue file column start.
470+
.PARAMETER EndLine
471+
Issue file line end.
472+
.PARAMETER EndColumn
473+
Issue file column end.
474+
.PARAMETER Title
475+
Issue title.
476+
.OUTPUTS
477+
Void
478+
#>
479+
function Write-GHActionsAnnotation {
480+
[CmdletBinding()][OutputType([void])]
481+
param (
482+
[Parameter(Mandatory = $true, Position = 0)][GHActionsAnnotationType]$Type,
483+
[Parameter(Mandatory = $true, Position = 1)][string]$Message,
484+
[Parameter()][string]$File,
485+
[Parameter()][uint]$Line,
486+
[Parameter()][uint]$Col,
487+
[Parameter()][uint]$EndLine,
488+
[Parameter()][uint]$EndColumn,
489+
[Parameter()][string]$Title
490+
)
491+
[hashtable]$Properties = @{}
492+
if ($File.Length -gt 0) {
493+
$Properties.'file' = $File
494+
}
495+
if ($Line -gt 0) {
496+
$Properties.'line' = $Line
497+
}
498+
if ($Col -gt 0) {
499+
$Properties.'col' = $Col
500+
}
501+
if ($EndLine -gt 0) {
502+
$Properties.'endLine' = $EndLine
503+
}
504+
if ($EndColumn -gt 0) {
505+
$Properties.'endColumn' = $EndColumn
506+
}
507+
if ($Title.Length -gt 0) {
508+
$Properties.'title' = $Title
509+
}
510+
Write-GHActionsCommand -Command $Type.ToString().ToLower() -Message $Message -Properties $Properties
511+
}
512+
<#
513+
.SYNOPSIS
451514
GitHub Actions - Write Debug
452515
.DESCRIPTION
453516
Prints a debug message to the log.
@@ -492,39 +555,15 @@ Void
492555
function Write-GHActionsError {
493556
[CmdletBinding()][OutputType([void])]
494557
param (
495-
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)][string]$Message,
558+
[Parameter(Mandatory = $true, Position = 0)][string]$Message,
496559
[Parameter()][string]$File,
497560
[Parameter()][uint]$Line,
498561
[Parameter()][uint]$Col,
499562
[Parameter()][uint]$EndLine,
500563
[Parameter()][uint]$EndColumn,
501564
[Parameter()][string]$Title
502565
)
503-
begin {
504-
[hashtable]$Properties = @{}
505-
if ($File.Length -gt 0) {
506-
$Properties.'file' = $File
507-
}
508-
if ($Line -gt 0) {
509-
$Properties.'line' = $Line
510-
}
511-
if ($Col -gt 0) {
512-
$Properties.'col' = $Col
513-
}
514-
if ($EndLine -gt 0) {
515-
$Properties.'endLine' = $EndLine
516-
}
517-
if ($EndColumn -gt 0) {
518-
$Properties.'endColumn' = $EndColumn
519-
}
520-
if ($Title.Length -gt 0) {
521-
$Properties.'title' = $Title
522-
}
523-
}
524-
process {
525-
Write-GHActionsCommand -Command 'error' -Message $Message -Properties $Properties
526-
}
527-
end {}
566+
Write-GHActionsAnnotation -Type 'Error' -Message $Message -File $File -Line $Line -Col $Col -EndLine $EndLine -EndColumn $EndColumn -Title $Title
528567
}
529568
<#
530569
.SYNOPSIS
@@ -541,7 +580,7 @@ function Write-GHActionsFail {
541580
param(
542581
[Parameter(Position = 0)][string]$Message = ''
543582
)
544-
Write-GHActionsCommand -Command 'error' -Message $Message
583+
Write-GHActionsAnnotation -Type 'Error' -Message $Message
545584
exit 1
546585
}
547586
<#
@@ -569,39 +608,15 @@ Void
569608
function Write-GHActionsNotice {
570609
[CmdletBinding()][OutputType([void])]
571610
param (
572-
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)][string]$Message,
611+
[Parameter(Mandatory = $true, Position = 0)][string]$Message,
573612
[Parameter()][string]$File,
574613
[Parameter()][uint]$Line,
575614
[Parameter()][uint]$Col,
576615
[Parameter()][uint]$EndLine,
577616
[Parameter()][uint]$EndColumn,
578617
[Parameter()][string]$Title
579618
)
580-
begin {
581-
[hashtable]$Properties = @{}
582-
if ($File.Length -gt 0) {
583-
$Properties.'file' = $File
584-
}
585-
if ($Line -gt 0) {
586-
$Properties.'line' = $Line
587-
}
588-
if ($Col -gt 0) {
589-
$Properties.'col' = $Col
590-
}
591-
if ($EndLine -gt 0) {
592-
$Properties.'endLine' = $EndLine
593-
}
594-
if ($EndColumn -gt 0) {
595-
$Properties.'endColumn' = $EndColumn
596-
}
597-
if ($Title.Length -gt 0) {
598-
$Properties.'title' = $Title
599-
}
600-
}
601-
process {
602-
Write-GHActionsCommand -Command 'notice' -Message $Message -Properties $Properties
603-
}
604-
end {}
619+
Write-GHActionsAnnotation -Type 'Notice' -Message $Message -File $File -Line $Line -Col $Col -EndLine $EndLine -EndColumn $EndColumn -Title $Title
605620
}
606621
<#
607622
.SYNOPSIS
@@ -628,38 +643,14 @@ Void
628643
function Write-GHActionsWarning {
629644
[CmdletBinding()][OutputType([void])]
630645
param (
631-
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)][string]$Message,
646+
[Parameter(Mandatory = $true, Position = 0)][string]$Message,
632647
[Parameter()][string]$File,
633648
[Parameter()][uint]$Line,
634649
[Parameter()][uint]$Col,
635650
[Parameter()][uint]$EndLine,
636651
[Parameter()][uint]$EndColumn,
637652
[Parameter()][string]$Title
638653
)
639-
begin {
640-
[hashtable]$Properties = @{}
641-
if ($File.Length -gt 0) {
642-
$Properties.'file' = $File
643-
}
644-
if ($Line -gt 0) {
645-
$Properties.'line' = $Line
646-
}
647-
if ($Col -gt 0) {
648-
$Properties.'col' = $Col
649-
}
650-
if ($EndLine -gt 0) {
651-
$Properties.'endLine' = $EndLine
652-
}
653-
if ($EndColumn -gt 0) {
654-
$Properties.'endColumn' = $EndColumn
655-
}
656-
if ($Title.Length -gt 0) {
657-
$Properties.'title' = $Title
658-
}
659-
}
660-
process {
661-
Write-GHActionsCommand -Command 'warning' -Message $Message -Properties $Properties
662-
}
663-
end {}
654+
Write-GHActionsAnnotation -Type 'Warning' -Message $Message -File $File -Line $Line -Col $Col -EndLine $EndLine -EndColumn $EndColumn -Title $Title
664655
}
665-
Export-ModuleMember -Function Add-GHActionsEnvironmentVariable, Add-GHActionsPATH, Add-GHActionsSecretMask, Disable-GHActionsCommandEcho, Disable-GHActionsProcessingCommand, Enable-GHActionsCommandEcho, Enable-GHActionsProcessingCommand, Enter-GHActionsLogGroup, Exit-GHActionsLogGroup, Get-GHActionsInput, Get-GHActionsIsDebug, Get-GHActionsState, Get-GHActionsWebhookEventPayload, Set-GHActionsOutput, Set-GHActionsState, Write-GHActionsDebug, Write-GHActionsError, Write-GHActionsFail, Write-GHActionsNotice, Write-GHActionsWarning
656+
Export-ModuleMember -Function Add-GHActionsEnvironmentVariable, Add-GHActionsPATH, Add-GHActionsSecretMask, Disable-GHActionsCommandEcho, Disable-GHActionsProcessingCommand, Enable-GHActionsCommandEcho, Enable-GHActionsProcessingCommand, Enter-GHActionsLogGroup, Exit-GHActionsLogGroup, Get-GHActionsInput, Get-GHActionsIsDebug, Get-GHActionsState, Get-GHActionsWebhookEventPayload, Set-GHActionsOutput, Set-GHActionsState, Write-GHActionsAnnotation, Write-GHActionsDebug, Write-GHActionsError, Write-GHActionsFail, Write-GHActionsNotice, Write-GHActionsWarning

0 commit comments

Comments
 (0)