Skip to content

Commit 4e5bb46

Browse files
committed
20220511A
1 parent d2bd614 commit 4e5bb46

File tree

3 files changed

+61
-17
lines changed

3 files changed

+61
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Import-Module -Name 'hugoalh.GitHubActionsToolkit' -Scope 'Local'
5656
- `Get-GitHubActionsInput`
5757
- `Get-GitHubActionsIsDebug`
5858
- `Get-GitHubActionsState`
59+
- `Get-GitHubActionsStepSummary`
5960
- `Get-GitHubActionsWebhookEventPayload`
6061
- `Remove-GitHubActionsProblemMatcher`
6162
- `Remove-GitHubActionsStepSummary`

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
'Get-GitHubActionsInput',
7676
'Get-GitHubActionsIsDebug',
7777
'Get-GitHubActionsState',
78+
'Get-GitHubActionsStepSummary',
7879
'Get-GitHubActionsWebhookEventPayload',
7980
'Remove-GitHubActionsProblemMatcher',
8081
'Remove-GitHubActionsStepSummary',
@@ -182,6 +183,7 @@
182183
'Get-GHActionsIsDebug',
183184
'Get-GHActionsPayload',
184185
'Get-GHActionsState',
186+
'Get-GHActionsStepSummary',
185187
'Get-GHActionsWebhookEvent',
186188
'Get-GHActionsWebhookEventPayload',
187189
'Get-GHActionsWebhookPayload',

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psm1

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ function Add-GitHubActionsEnvironmentVariable {
125125
}
126126
end {
127127
if ($Result.Count -gt 0) {
128-
Add-Content -Path $env:GITHUB_ENV -Value (($Result.GetEnumerator() | ForEach-Object -Process {
128+
Add-Content -LiteralPath $env:GITHUB_ENV -Value (($Result.GetEnumerator() | ForEach-Object -Process {
129129
return "$($_.Name)=$($_.Value)"
130-
}) -join "`n") -Encoding 'UTF8NoBOM'
130+
}) -join "`n") -Confirm:$false -Encoding 'UTF8NoBOM'
131131
}
132132
return
133133
}
@@ -173,7 +173,7 @@ function Add-GitHubActionsPATH {
173173
}
174174
end {
175175
if ($Result.Count -gt 0) {
176-
Add-Content -Path $env:GITHUB_PATH -Value ($Result -join "`n") -Encoding 'UTF8NoBOM'
176+
Add-Content -LiteralPath $env:GITHUB_PATH -Value ($Result -join "`n") -Confirm:$false -Encoding 'UTF8NoBOM'
177177
}
178178
return
179179
}
@@ -186,23 +186,37 @@ GitHub Actions - Add Problem Matcher
186186
Problem matchers are a way to scan the output of actions for a specified regular expression pattern and automatically surface that information prominently in the user interface, both annotations and log file decorations are created when a match is detected. For more information, please visit https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md.
187187
.PARAMETER Path
188188
Relative path to the JSON file problem matcher.
189+
.PARAMETER LiteralPath
190+
Relative literal path to the JSON file problem matcher.
189191
.OUTPUTS
190192
Void
191193
#>
192194
function Add-GitHubActionsProblemMatcher {
193-
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_add-githubactionsproblemmatcher#Add-GitHubActionsProblemMatcher')]
195+
[CmdletBinding(DefaultParameterSetName = 'path', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_add-githubactionsproblemmatcher#Add-GitHubActionsProblemMatcher')]
194196
[OutputType([void])]
195197
param (
196-
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)][SupportsWildcards()][ValidatePattern('^.+$')][Alias('File', 'Files', 'Paths', 'PSPath', 'PSPaths')][string[]]$Path
198+
[Parameter(Mandatory = $true, ParameterSetName = 'path', Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)][SupportsWildcards()][ValidatePattern('^.+$')][Alias('File', 'Files', 'Paths')][string[]]$Path,
199+
[Parameter(Mandatory = $true, ParameterSetName = 'literal-path', ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)][ValidatePattern('^.+$')][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][string[]]$LiteralPath
197200
)
198201
begin {}
199202
process {
200-
$Path | ForEach-Object -Process {
201-
return ([string[]](Resolve-Path -Path $_ -Relative) | Where-Object -FilterScript {
202-
return (($null -ne $_) -and ($_.Length -gt 0))
203-
} | ForEach-Object -Process {
204-
return Write-GitHubActionsCommand -Command 'add-matcher' -Message ($_ -replace '^\.[\\\/]', '' -replace '\\', '/')
205-
})
203+
switch ($PSCmdlet.ParameterSetName) {
204+
'path' {
205+
$Path | ForEach-Object -Process {
206+
return ([string[]](Resolve-Path -Path $_ -Relative) | Where-Object -FilterScript {
207+
return (($null -ne $_) -and ($_.Length -gt 0))
208+
} | ForEach-Object -Process {
209+
return Write-GitHubActionsCommand -Command 'add-matcher' -Message ($_ -replace '^\.[\\\/]', '' -replace '\\', '/')
210+
})
211+
}
212+
break
213+
}
214+
'literal-path' {
215+
$LiteralPath | ForEach-Object -Process {
216+
return Write-GitHubActionsCommand -Command 'add-matcher' -Message ($_ -replace '^\.[\\\/]', '' -replace '\\', '/')
217+
}
218+
break
219+
}
206220
}
207221
}
208222
end {
@@ -257,14 +271,17 @@ GitHub Actions - Add Step Summary
257271
Add some GitHub flavored Markdown for step so that it will be displayed on the summary page of a run; Can use to display and group unique content, such as test result summaries, so that viewing the result of a run does not need to go into the logs to see important information related to the run, such as failures. When a run's job finishes, the summaries for all steps in a job are grouped together into a single job summary and are shown on the run summary page. If multiple jobs generate summaries, the job summaries are ordered by job completion time.
258272
.PARAMETER Value
259273
Content.
274+
.PARAMETER NoNewLine
275+
Do not add a new line or carriage return to the content, the string representations of the input objects are concatenated to form the output, no spaces or newlines are inserted between the output strings, no newline is added after the last output string.
260276
.OUTPUTS
261277
Void
262278
#>
263279
function Add-GitHubActionsStepSummary {
264280
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_add-githubactionsstepsummary#Add-GitHubActionsStepSummary')]
265281
[OutputType([void])]
266282
param (
267-
[Parameter(Position = 0, ValueFromPipeline = $true)][Alias('Content')][string[]]$Value = @('')
283+
[Parameter(Position = 0, ValueFromPipeline = $true)][Alias('Content')][string[]]$Value = @(''),
284+
[switch]$NoNewLine
268285
)
269286
begin {
270287
[string[]]$Result = @()
@@ -274,7 +291,7 @@ function Add-GitHubActionsStepSummary {
274291
}
275292
end {
276293
if ($Result.Count -gt 0) {
277-
Add-Content -Path $env:GITHUB_STEP_SUMMARY -Value ($Result -join "`n") -Encoding 'UTF8NoBOM'
294+
Add-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Value ($Result -join "`n") -Confirm:$false -NoNewline:$NoNewLine -Encoding 'UTF8NoBOM'
278295
}
279296
return
280297
}
@@ -749,6 +766,25 @@ Set-Alias -Name 'Restore-GHActionsState' -Value 'Get-GitHubActionsState' -Option
749766
Set-Alias -Name 'Restore-GitHubActionsState' -Value 'Get-GitHubActionsState' -Option 'ReadOnly' -Scope 'Local'
750767
<#
751768
.SYNOPSIS
769+
GitHub Actions - Get Step Summary
770+
.DESCRIPTION
771+
Get step summary that added/setted from functions `Add-GitHubActionsStepSummary` and `Set-GitHubActionsStepSummary`.
772+
.PARAMETER Raw
773+
Ignore newline characters and return the entire contents of a file in one string with the newlines preserved. By default, newline characters in a file are used as delimiters to separate the input into an array of strings.
774+
.OUTPUTS
775+
String | String[]
776+
#>
777+
function Get-GitHubActionsStepSummary {
778+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_get-githubactionsstepsummary#Get-GitHubActionsStepSummary')]
779+
[OutputType(([string], [string[]]))]
780+
param (
781+
[switch]$Raw
782+
)
783+
return Get-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Raw:$Raw -Encoding 'UTF8NoBOM'
784+
}
785+
Set-Alias -Name 'Get-GHActionsStepSummary' -Value 'Get-GitHubActionsStepSummary' -Option 'ReadOnly' -Scope 'Local'
786+
<#
787+
.SYNOPSIS
752788
GitHub Actions - Get Webhook Event Payload
753789
.DESCRIPTION
754790
Get the complete webhook event payload.
@@ -769,7 +805,7 @@ function Get-GitHubActionsWebhookEventPayload {
769805
[int]$Depth = 1024,
770806
[switch]$NoEnumerate
771807
)
772-
return (Get-Content -Path $env:GITHUB_EVENT_PATH -Raw -Encoding 'UTF8NoBOM' | ConvertFrom-Json -AsHashtable:$AsHashtable -Depth $Depth -NoEnumerate:$NoEnumerate)
808+
return (Get-Content -LiteralPath $env:GITHUB_EVENT_PATH -Raw -Encoding 'UTF8NoBOM' | ConvertFrom-Json -AsHashtable:$AsHashtable -Depth $Depth -NoEnumerate:$NoEnumerate)
773809
}
774810
Set-Alias -Name 'Get-GHActionsEvent' -Value 'Get-GitHubActionsWebhookEventPayload' -Option 'ReadOnly' -Scope 'Local'
775811
Set-Alias -Name 'Get-GHActionsPayload' -Value 'Get-GitHubActionsWebhookEventPayload' -Option 'ReadOnly' -Scope 'Local'
@@ -819,7 +855,7 @@ function Remove-GitHubActionsStepSummary {
819855
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_remove-githubactionsstepsummary#Remove-GitHubActionsStepSummary')]
820856
[OutputType([void])]
821857
param ()
822-
return Remove-Item -Path $env:GITHUB_STEP_SUMMARY
858+
return Remove-Item -LiteralPath $env:GITHUB_STEP_SUMMARY -Confirm:$false
823859
}
824860
Set-Alias -Name 'Remove-GHActionsStepSummary' -Value 'Remove-GitHubActionsStepSummary' -Option 'ReadOnly' -Scope 'Local'
825861
<#
@@ -931,14 +967,17 @@ GitHub Actions - Set Step Summary
931967
Set some GitHub flavored Markdown for step so that it will be displayed on the summary page of a run; Can use to display and group unique content, such as test result summaries, so that viewing the result of a run does not need to go into the logs to see important information related to the run, such as failures. When a run's job finishes, the summaries for all steps in a job are grouped together into a single job summary and are shown on the run summary page. If multiple jobs generate summaries, the job summaries are ordered by job completion time.
932968
.PARAMETER Value
933969
Content.
970+
.PARAMETER NoNewLine
971+
Do not add a new line or carriage return to the content, the string representations of the input objects are concatenated to form the output, no spaces or newlines are inserted between the output strings, no newline is added after the last output string.
934972
.OUTPUTS
935973
Void
936974
#>
937975
function Set-GitHubActionsStepSummary {
938976
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_set-githubactionsstepsummary#Set-GitHubActionsStepSummary')]
939977
[OutputType([void])]
940978
param (
941-
[Parameter(Position = 0, ValueFromPipeline = $true)][Alias('Content')][string[]]$Value = @('')
979+
[Parameter(Position = 0, ValueFromPipeline = $true)][Alias('Content')][string[]]$Value = @(''),
980+
[switch]$NoNewLine
942981
)
943982
begin {
944983
[string[]]$Result = @()
@@ -948,7 +987,7 @@ function Set-GitHubActionsStepSummary {
948987
}
949988
end {
950989
if ($Result.Count -gt 0) {
951-
Set-Content -Path $env:GITHUB_STEP_SUMMARY -Value ($Result -join "`n") -Encoding 'UTF8NoBOM'
990+
Set-Content -LiteralPath $env:GITHUB_STEP_SUMMARY -Value ($Result -join "`n") -Confirm:$false -NoNewline:$NoNewLine -Encoding 'UTF8NoBOM'
952991
}
953992
return
954993
}
@@ -1300,6 +1339,7 @@ Export-ModuleMember -Function @(
13001339
'Get-GitHubActionsInput',
13011340
'Get-GitHubActionsIsDebug',
13021341
'Get-GitHubActionsState',
1342+
'Get-GitHubActionsStepSummary',
13031343
'Get-GitHubActionsWebhookEventPayload',
13041344
'Remove-GitHubActionsProblemMatcher',
13051345
'Remove-GitHubActionsStepSummary',
@@ -1398,6 +1438,7 @@ Export-ModuleMember -Function @(
13981438
'Get-GHActionsIsDebug',
13991439
'Get-GHActionsPayload',
14001440
'Get-GHActionsState',
1441+
'Get-GHActionsStepSummary',
14011442
'Get-GHActionsWebhookEvent',
14021443
'Get-GHActionsWebhookEventPayload',
14031444
'Get-GHActionsWebhookPayload',

0 commit comments

Comments
 (0)