Skip to content

Commit 824f044

Browse files
committed
Simplify some syntax
1 parent 496ffd3 commit 824f044

File tree

4 files changed

+41
-45
lines changed

4 files changed

+41
-45
lines changed

hugoalh.GitHubActionsToolkit/module/command-file.psm1

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ Function Clear-FileCommand {
4747
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_cleargithubactionsfilecommand')]
4848
[OutputType([Void])]
4949
Param (
50-
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('Command', 'Commands', 'FileCommands')][String[]]$FileCommand
50+
[Parameter(Mandatory = $True, Position = 0)][Alias('Command', 'Commands', 'FileCommands')][String[]]$FileCommand
5151
)
5252
ForEach ($FC In $FileCommand) {
5353
Try {
54-
[String]$FileCommandPath = Resolve-FileCommandPath -FileCommand $FC
55-
Set-Content -LiteralPath $FileCommandPath -Value '' -Confirm:$False -Encoding 'UTF8NoBOM'
54+
Set-Content -LiteralPath (Resolve-FileCommandPath -FileCommand $FC) -Value '' -Confirm:$False -Encoding 'UTF8NoBOM'
5655
}
5756
Catch {
5857
Write-Error -Message "Unable to clear the GitHub Actions file command: $_" -Category (($_)?.CategoryInfo.Category ?? 'OperationStopped')
@@ -73,7 +72,7 @@ File command path.
7372
Function Get-FileCommand {
7473
[OutputType([PSCustomObject[]])]
7574
Param (
76-
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('CommandPath')][String]$FileCommandPath
75+
[Parameter(Mandatory = $True, Position = 0)][Alias('CommandPath')][String]$FileCommandPath
7776
)
7877
[String[]]$FileCommandRaw = Get-Content -LiteralPath $FileCommandPath -Encoding 'UTF8NoBOM'
7978
[PSCustomObject[]]$Result = @()
@@ -144,7 +143,7 @@ Raw.
144143
Function Remove-FileCommand {
145144
[OutputType([Void])]
146145
Param (
147-
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('CommandPath')][String]$FileCommandPath,
146+
[Parameter(Mandatory = $True, Position = 0)][Alias('CommandPath')][String]$FileCommandPath,
148147
[Parameter(Mandatory = $True, Position = 1)][String[]]$Raw
149148
)
150149
[String]$FileCommandRaw = Get-Content -LiteralPath $FileCommandPath -Raw -Encoding 'UTF8NoBOM'
@@ -166,7 +165,7 @@ File command.
166165
Function Resolve-FileCommandPath {
167166
[OutputType([String])]
168167
Param (
169-
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('Command')][String]$FileCommand
168+
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^(?:[\da-z][\da-z_-]*)?[\da-z]$', ErrorMessage = '`{0}` is not a valid GitHub Actions file command!')][Alias('Command')][String]$FileCommand
170169
)
171170
[String]$FileCommandToUpper = $FileCommand.ToUpper()
172171
[AllowEmptyString()][AllowNull()][String]$FileCommandPath = [System.Environment]::GetEnvironmentVariable($FileCommandToUpper)
@@ -201,7 +200,7 @@ Function Write-FileCommand {
201200
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionsfilecommand')]
202201
[OutputType([Void])]
203202
Param (
204-
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][Alias('Command')][String]$FileCommand,
203+
[Parameter(Mandatory = $True, Position = 0)][Alias('Command')][String]$FileCommand,
205204
[Parameter(Mandatory = $True, Position = 1, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Value is not a single line string!')][String]$Name,
206205
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][String]$Value,
207206
[Switch]$Optimize

hugoalh.GitHubActionsToolkit/module/command-stdout.psm1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ Function Disable-StdOutCommandProcess {
5353
$EndToken = (New-Guid).Guid.ToLower() -ireplace '-', ''
5454
}
5555
Write-GitHubActionsStdOutCommand -StdOutCommand 'stop-commands' -Value $EndToken
56-
$EndToken |
57-
Write-Output
56+
Write-Output -InputObject $EndToken
5857
}
5958
Set-Alias -Name 'Disable-CommandProcess' -Value 'Disable-StdOutCommandProcess' -Option 'ReadOnly' -Scope 'Local'
6059
Set-Alias -Name 'Stop-CommandProcess' -Value 'Disable-StdOutCommandProcess' -Option 'ReadOnly' -Scope 'Local'
@@ -116,7 +115,7 @@ Function Format-StdOutCommandValue {
116115
Param (
117116
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][AllowNull()][Alias('Input', 'Object', 'Value')][String]$InputObject
118117
)
119-
Return (($InputObject ?? '') -ireplace '%', '%25' -ireplace '\n', '%0A' -ireplace '\r', '%0D')
118+
Return ($InputObject -ireplace '%', '%25' -ireplace '\n', '%0A' -ireplace '\r', '%0D')
120119
}
121120
<#
122121
.SYNOPSIS
@@ -133,7 +132,7 @@ Function Format-StdOutCommandParameterValue {
133132
Param (
134133
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][AllowNull()][Alias('Input', 'Object', 'Value')][String]$InputObject
135134
)
136-
Return ((Format-StdOutCommandValue ($InputObject ?? '')) -ireplace ',', '%2C' -ireplace ':', '%3A')
135+
Return ((Format-StdOutCommandValue -InputObject $InputObject) -ireplace ',', '%2C' -ireplace ':', '%3A')
137136
}
138137
<#
139138
.SYNOPSIS

hugoalh.GitHubActionsToolkit/module/log.psm1

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Import-Module -Name @(
33
(Join-Path -Path $PSScriptRoot -ChildPath 'command-stdout.psm1')
44
) -Prefix 'GitHubActions' -Scope 'Local'
5-
[UInt64]$AnnotationMessageLengthMaximum = 4096
5+
[UInt64]$AnnotationDataLengthMaximum = 4096
66
<#
77
.SYNOPSIS
88
GitHub Actions - Enter Log Group
@@ -44,8 +44,8 @@ GitHub Actions - Internal - Write Annotation
4444
Print an annotation message to the log.
4545
.PARAMETER Type
4646
Type of the annotation.
47-
.PARAMETER Message
48-
Message of the annotation.
47+
.PARAMETER Data
48+
Data of the annotation.
4949
.PARAMETER File
5050
Path of the issue file of the annotation.
5151
.PARAMETER Line
@@ -68,7 +68,7 @@ Function Write-Annotation {
6868
[OutputType([Void])]
6969
Param (
7070
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidateSet('error', 'notice', 'warning')][String]$Type,
71-
[Parameter(Mandatory = $True, Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content')][String]$Message,
71+
[Parameter(Mandatory = $True, Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Data,
7272
[Parameter(ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][ValidatePattern('^.*$', ErrorMessage = 'Value is not a single line string!')][Alias('Path')][String]$File,
7373
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('LineStart', 'StartLine')][UInt32]$Line,
7474
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Col', 'ColStart', 'ColumnStart', 'StartCol', 'StartColumn')][UInt32]$Column,
@@ -97,19 +97,19 @@ Function Write-Annotation {
9797
If ($Title.Length -gt 0) {
9898
$Parameter.('title') = $Title
9999
}
100-
If ($Message.Length -gt $AnnotationMessageLengthMaximum -and $Summary.Length -gt 0) {
101-
If ($Message -imatch '^::') {
100+
If ($Data.Length -gt $AnnotationDataLengthMaximum -and $Summary.Length -gt 0) {
101+
If ($Data -imatch '^::') {
102102
[String]$EndToken = Disable-GitHubActionsStdOutCommandProcess
103-
Write-Host -Object $Message
103+
Write-Host -Object $Data
104104
Enable-GitHubActionsStdOutCommandProcess -EndToken $EndToken
105105
}
106106
Else {
107-
Write-Host -Object $Message
107+
Write-Host -Object $Data
108108
}
109109
Write-GitHubActionsStdOutCommand -StdOutCommand $Type -Parameter $Parameter -Value $Summary
110110
}
111111
Else {
112-
Write-GitHubActionsStdOutCommand -StdOutCommand $Type -Parameter $Parameter -Value $Message
112+
Write-GitHubActionsStdOutCommand -StdOutCommand $Type -Parameter $Parameter -Value $Data
113113
}
114114
}
115115
}
@@ -133,20 +133,19 @@ Function Write-Debug {
133133
[OutputType([String], ParameterSetName = 'PassThru')]
134134
[OutputType([Void], ParameterSetName = 'Void')]
135135
Param (
136-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][Alias('Content')][String]$Message,
137-
[Alias('SkipEmpty')][Switch]$SkipEmptyMessage,
136+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][Alias('Content', 'Message')][String]$Data,
137+
[Alias('SkipEmptyMessage')][Switch]$SkipEmpty,
138138
[Parameter(Mandatory = $True, ParameterSetName = 'PassThru')][Switch]$PassThru
139139
)
140140
Process {
141141
If (
142-
!$SkipEmptyMessage.IsPresent -or
143-
($SkipEmptyMessage.IsPresent -and $Message.Length -gt 0)
142+
!$SkipEmpty.IsPresent -or
143+
($SkipEmpty.IsPresent -and $Data.Length -gt 0)
144144
) {
145-
Write-GitHubActionsStdOutCommand -StdOutCommand 'debug' -Value $Message
145+
Write-GitHubActionsStdOutCommand -StdOutCommand 'debug' -Value $Data
146146
}
147147
If ($PSCmdlet.ParameterSetName -ieq 'PassThru') {
148-
$Message |
149-
Write-Output
148+
Write-Output -InputObject $Data
150149
}
151150
}
152151
}
@@ -155,8 +154,8 @@ Function Write-Debug {
155154
GitHub Actions - Write Error
156155
.DESCRIPTION
157156
Print an error message to the log.
158-
.PARAMETER Message
159-
Message that need to log at error level.
157+
.PARAMETER Data
158+
Data that need to log at error level.
160159
.PARAMETER File
161160
Path of the issue file of the annotation.
162161
.PARAMETER Line
@@ -178,7 +177,7 @@ Function Write-Error {
178177
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionserror')]
179178
[OutputType([Void])]
180179
Param (
181-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content')][String]$Message,
180+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Data,
182181
[Parameter(ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][ValidatePattern('^.*$', ErrorMessage = 'Value is not a single line string!')][Alias('Path')][String]$File,
183182
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('LineStart', 'StartLine')][UInt32]$Line,
184183
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Col', 'ColStart', 'ColumnStart', 'StartCol', 'StartColumn')][UInt32]$Column,
@@ -188,16 +187,16 @@ Function Write-Error {
188187
[Parameter(ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][String]$Summary
189188
)
190189
Process {
191-
Write-Annotation -Type 'error' -Message $Message -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
190+
Write-Annotation -Type 'error' -Data $Data -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
192191
}
193192
}
194193
<#
195194
.SYNOPSIS
196195
GitHub Actions - Write Fail
197196
.DESCRIPTION
198197
Print an error message to the log and end the process.
199-
.PARAMETER Message
200-
Message that need to log at error level.
198+
.PARAMETER Data
199+
Data that need to log at error level.
201200
.PARAMETER File
202201
Path of the issue file of the annotation.
203202
.PARAMETER Line
@@ -223,7 +222,7 @@ Function Write-Fail {
223222
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionsfail')]
224223
[OutputType([Void])]
225224
Param (
226-
[Parameter(Mandatory = $True, Position = 0)][Alias('Content')][String]$Message,
225+
[Parameter(Mandatory = $True, Position = 0)][Alias('Content', 'Message')][String]$Data,
227226
[AllowEmptyString()][AllowNull()][ValidatePattern('^.*$', ErrorMessage = 'Value is not a single line string!')][Alias('Path')][String]$File,
228227
[Alias('LineStart', 'StartLine')][UInt32]$Line,
229228
[Alias('Col', 'ColStart', 'ColumnStart', 'StartCol', 'StartColumn')][UInt32]$Column,
@@ -234,7 +233,7 @@ Function Write-Fail {
234233
[ScriptBlock]$Finally = {},
235234
[ValidateScript({ $_ -ine 0 }, ErrorMessage = 'Value is not a valid non-success exit code!')][Int16]$ExitCode = 1
236235
)
237-
Write-Annotation -Type 'error' -Message $Message -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
236+
Write-Annotation -Type 'error' -Data $Data -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
238237
Invoke-Command -ScriptBlock $Finally -ErrorAction 'Continue'
239238
Exit $ExitCode
240239
Exit 1# Fallback exit for safety.
@@ -244,8 +243,8 @@ Function Write-Fail {
244243
GitHub Actions - Write Notice
245244
.DESCRIPTION
246245
Print a notice message to the log.
247-
.PARAMETER Message
248-
Message that need to log at notice level.
246+
.PARAMETER Data
247+
Data that need to log at notice level.
249248
.PARAMETER File
250249
Path of the issue file of the annotation.
251250
.PARAMETER Line
@@ -267,7 +266,7 @@ Function Write-Notice {
267266
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionsnotice')]
268267
[OutputType([Void])]
269268
Param (
270-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content')][String]$Message,
269+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Data,
271270
[Parameter(ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][ValidatePattern('^.*$', ErrorMessage = 'Value is not a single line string!')][Alias('Path')][String]$File,
272271
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('LineStart', 'StartLine')][UInt32]$Line,
273272
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Col', 'ColStart', 'ColumnStart', 'StartCol', 'StartColumn')][UInt32]$Column,
@@ -277,7 +276,7 @@ Function Write-Notice {
277276
[Parameter(ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][String]$Summary
278277
)
279278
Process {
280-
Write-Annotation -Type 'notice' -Message $Message -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
279+
Write-Annotation -Type 'notice' -Data $Data -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
281280
}
282281
}
283282
Set-Alias -Name 'Write-Note' -Value 'Write-Notice' -Option 'ReadOnly' -Scope 'Local'
@@ -286,8 +285,8 @@ Set-Alias -Name 'Write-Note' -Value 'Write-Notice' -Option 'ReadOnly' -Scope 'Lo
286285
GitHub Actions - Write Warning
287286
.DESCRIPTION
288287
Print a warning message to the log.
289-
.PARAMETER Message
290-
Message that need to log at warning level.
288+
.PARAMETER Data
289+
Data that need to log at warning level.
291290
.PARAMETER File
292291
Path of the issue file of the annotation.
293292
.PARAMETER Line
@@ -309,7 +308,7 @@ Function Write-Warning {
309308
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionswarning')]
310309
[OutputType([Void])]
311310
Param (
312-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content')][String]$Message,
311+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Data,
313312
[Parameter(ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][ValidatePattern('^.*$', ErrorMessage = 'Value is not a single line string!')][Alias('Path')][String]$File,
314313
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('LineStart', 'StartLine')][UInt32]$Line,
315314
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Col', 'ColStart', 'ColumnStart', 'StartCol', 'StartColumn')][UInt32]$Column,
@@ -319,7 +318,7 @@ Function Write-Warning {
319318
[Parameter(ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][String]$Summary
320319
)
321320
Process {
322-
Write-Annotation -Type 'warning' -Message $Message -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
321+
Write-Annotation -Type 'warning' -Data $Data -File $File -Line $Line -Column $Column -EndLine $EndLine -EndColumn $EndColumn -Title $Title -Summary $Summary
323322
}
324323
}
325324
Set-Alias -Name 'Write-Warn' -Value 'Write-Warning' -Option 'ReadOnly' -Scope 'Local'

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ Function Get-DebugStatus {
7676
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_getgithubactionsdebugstatus')]
7777
[OutputType([Boolean])]
7878
Param ()
79-
$Env:RUNNER_DEBUG -ieq '1' |
80-
Write-Output
79+
Write-Output -InputObject ($Env:RUNNER_DEBUG -ieq '1')
8180
}
8281
Set-Alias -Name 'Get-IsDebug' -Value 'Get-DebugStatus' -Option 'ReadOnly' -Scope 'Local'
8382
<#

0 commit comments

Comments
 (0)