Skip to content

Commit 8979f5b

Browse files
committed
20230322B
1 parent 3750876 commit 8979f5b

16 files changed

+169
-119
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ body:
1818
description: "What versions are affected? Versions must be listed as supported in the Security Policy (file: `SECURITY.md`)."
1919
multiple: true
2020
options:
21-
- "v1.4.0"
21+
- "v1.4.0-beta.1"
2222
- "v1.3.2"
2323
- "v1.3.1"
2424
- "v1.3.0"

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@
101101
'Test-Environment',
102102
'Test-NodeJsEnvironment',
103103
'Write-Annotation',
104-
'Write-Command',
105104
'Write-Debug',
106105
'Write-Error',
107106
'Write-Fail',
108107
'Write-FileCommand',
109108
'Write-Notice',
110109
'Write-Raw',
110+
'Write-StdOutCommand',
111111
'Write-Warning'
112112
)
113113

@@ -205,6 +205,7 @@
205205
'Stop-ProcessCommands',
206206
'Stop-ProcessingCommand',
207207
'Stop-ProcessingCommands',
208+
'Write-Command',
208209
'Write-Note',
209210
'Write-Warn'
210211
)
@@ -249,7 +250,7 @@
249250
ReleaseNotes = '(Please visit https://github.com/hugoalh-studio/ghactions-toolkit-powershell/releases.)'
250251

251252
# Prerelease string of this module
252-
# Prerelease = ''
253+
Prerelease = 'beta1'
253254

254255
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
255256
RequireLicenseAcceptance = $False
Lines changed: 77 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,46 @@
11
#Requires -PSEdition Core -Version 7.2
22
Import-Module -Name (
33
@(
4-
'internal\new-random-token'
4+
'internal\new-random-token',
5+
'internal\test-environment-path'
56
) |
67
ForEach-Object -Process { Join-Path -Path $PSScriptRoot -ChildPath "$_.psm1" }
78
) -Prefix 'GitHubActions' -Scope 'Local'
89
<#
910
.SYNOPSIS
10-
GitHub Actions - Format Command Parameter Value
11+
GitHub Actions - Format StdOut Command Parameter Value
1112
.DESCRIPTION
12-
Format the command parameter value characters that can cause issues.
13+
Format the stdout command parameter value characters that can cause issues.
1314
.PARAMETER InputObject
14-
String that need to format the command parameter value characters.
15+
String that need to format the stdout command parameter value characters.
1516
.OUTPUTS
16-
[String] A string that formatted the command parameter value characters.
17+
[String] A string that formatted the stdout command parameter value characters.
1718
#>
18-
Function Format-CommandParameterValue {
19+
Function Format-StdOutCommandParameterValue {
1920
[CmdletBinding()]
2021
[OutputType([String])]
2122
Param (
2223
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
2324
)
2425
Process {
25-
(Format-CommandValue -InputObject $InputObject) -ireplace ',', '%2C' -ireplace ':', '%3A' |
26+
(Format-StdOutCommandValue -InputObject $InputObject) -ireplace ',', '%2C' -ireplace ':', '%3A' |
2627
Write-Output
2728
}
2829
}
29-
Set-Alias -Name 'Format-CommandPropertyValue' -Value 'Format-CommandParameterValue' -Option 'ReadOnly' -Scope 'Local'
30+
Set-Alias -Name 'Format-CommandParameterValue' -Value 'Format-StdOutCommandParameterValue' -Option 'ReadOnly' -Scope 'Local'
31+
Set-Alias -Name 'Format-CommandPropertyValue' -Value 'Format-StdOutCommandParameterValue' -Option 'ReadOnly' -Scope 'Local'
32+
Set-Alias -Name 'Format-StdOutCommandPropertyValue' -Value 'Format-StdOutCommandParameterValue' -Option 'ReadOnly' -Scope 'Local'
3033
<#
3134
.SYNOPSIS
32-
GitHub Actions - Format Command Value
35+
GitHub Actions - Format StdOut Command Value
3336
.DESCRIPTION
34-
Format the command value characters that can cause issues.
37+
Format the stdout command value characters that can cause issues.
3538
.PARAMETER InputObject
36-
String that need to format the command value characters.
39+
String that need to format the stdout command value characters.
3740
.OUTPUTS
38-
[String] A string that formatted the command value characters.
41+
[String] A string that formatted the stdout command value characters.
3942
#>
40-
Function Format-CommandValue {
43+
Function Format-StdOutCommandValue {
4144
[CmdletBinding()]
4245
[OutputType([String])]
4346
Param (
@@ -48,46 +51,18 @@ Function Format-CommandValue {
4851
Write-Output
4952
}
5053
}
51-
Set-Alias -Name 'Format-CommandContent' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
52-
Set-Alias -Name 'Format-CommandMessage' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
53-
<#
54-
.SYNOPSIS
55-
GitHub Actions - Write Command
56-
.DESCRIPTION
57-
Write command to communicate with the runner machine.
58-
.PARAMETER Command
59-
Command.
60-
.PARAMETER Parameter
61-
Parameters of the command.
62-
.PARAMETER Value
63-
Value of the command.
64-
.OUTPUTS
65-
[Void]
66-
#>
67-
Function Write-Command {
68-
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionscommand')]
69-
[OutputType([Void])]
70-
Param (
71-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^(?:[\da-z][\da-z_-]*)?[\da-z]$', ErrorMessage = '`{0}` is not a valid GitHub Actions command!')][String]$Command,
72-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Parameters', 'Properties', 'Property')][Hashtable]$Parameter,
73-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Value
74-
)
75-
Process {
76-
Write-Host -Object "::$Command$(($Parameter.Count -igt 0) ? " $(
77-
$Parameter.GetEnumerator() |
78-
Sort-Object -Property 'Name' |
79-
ForEach-Object -Process { "$($_.Name)=$(Format-CommandParameterValue -InputObject $_.Value)" } |
80-
Join-String -Separator ','
81-
)" : '')::$(Format-CommandValue -InputObject $Value)"
82-
}
83-
}
54+
Set-Alias -Name 'Format-CommandContent' -Value 'Format-StdOutCommandValue' -Option 'ReadOnly' -Scope 'Local'
55+
Set-Alias -Name 'Format-CommandMessage' -Value 'Format-StdOutCommandValue' -Option 'ReadOnly' -Scope 'Local'
56+
Set-Alias -Name 'Format-CommandValue' -Value 'Format-StdOutCommandValue' -Option 'ReadOnly' -Scope 'Local'
57+
Set-Alias -Name 'Format-StdOutCommandContent' -Value 'Format-StdOutCommandValue' -Option 'ReadOnly' -Scope 'Local'
58+
Set-Alias -Name 'Format-StdOutCommandMessage' -Value 'Format-StdOutCommandValue' -Option 'ReadOnly' -Scope 'Local'
8459
<#
8560
.SYNOPSIS
8661
GitHub Actions - Write File Command
8762
.DESCRIPTION
8863
Write file command to communicate with the runner machine.
89-
.PARAMETER LiteralPath
90-
Literal path of the file command.
64+
.PARAMETER FileCommand
65+
File command. (LEGACY: Literal path of the file command.)
9166
.PARAMETER Name
9267
Name.
9368
.PARAMETER Value
@@ -99,13 +74,28 @@ Function Write-FileCommand {
9974
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionsfilecommand')]
10075
[OutputType([Void])]
10176
Param (
102-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][String]$LiteralPath,
77+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][Alias('Command', 'LiteralPath'<# LEGACY #>, 'Path'<# LEGACY #>)][String]$FileCommand,
10378
[Parameter(Mandatory = $True, Position = 1, ValueFromPipelineByPropertyName = $True)][String]$Name,
10479
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][String]$Value
10580
)
10681
Process {
82+
If (<# LEGACY #>Test-GitHubActionsEnvironmentPath -InputObject $FileCommand) {
83+
[String]$FileCommandPath = $FileCommand
84+
}
85+
Else {
86+
Try {
87+
[String]$FileCommandPath = Get-Content -LiteralPath "Env:\$([WildcardPattern]::Escape($FileCommand.ToUpper()))" -ErrorAction 'Stop'
88+
If (!(Test-GitHubActionsEnvironmentPath -InputObject $FileCommandPath)) {
89+
Throw
90+
}
91+
}
92+
Catch {
93+
Write-Error -Message "Unable to write the GitHub Actions file command: Environment path ``$($FileCommand.ToUpper())`` is undefined!" -Category 'ResourceUnavailable'
94+
Return
95+
}
96+
}
10797
If ($Value -imatch '^.+$') {
108-
Add-Content -LiteralPath $LiteralPath -Value "$Name=$Value" -Confirm:$False -Encoding 'UTF8NoBOM'
98+
Add-Content -LiteralPath $FileCommandPath -Value "$Name=$Value" -Confirm:$False -Encoding 'UTF8NoBOM'
10999
}
110100
Else {
111101
[String]$ItemRaw = "$Name=$Value" -ireplace '\r?\n', ''
@@ -118,11 +108,45 @@ Function Write-FileCommand {
118108
($Value -ireplace '\r?\n', "`n"),
119109
$Token
120110
) |
121-
Add-Content -LiteralPath $LiteralPath -Confirm:$False -Encoding 'UTF8NoBOM'
111+
Add-Content -LiteralPath $FileCommandPath -Confirm:$False -Encoding 'UTF8NoBOM'
122112
}
123113
}
124114
}
115+
<#
116+
.SYNOPSIS
117+
GitHub Actions - Write StdOut Command
118+
.DESCRIPTION
119+
Write stdout command to communicate with the runner machine.
120+
.PARAMETER StdOutCommand
121+
Stdout command.
122+
.PARAMETER Parameter
123+
Parameters of the stdout command.
124+
.PARAMETER Value
125+
Value of the stdout command.
126+
.OUTPUTS
127+
[Void]
128+
#>
129+
Function Write-StdOutCommand {
130+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_writegithubactionsstdoutcommand')]
131+
[OutputType([Void])]
132+
Param (
133+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^(?:[\da-z][\da-z_-]*)?[\da-z]$', ErrorMessage = '`{0}` is not a valid GitHub Actions stdout command!')][Alias('Command')][String]$StdOutCommand,
134+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Parameters', 'Properties', 'Property')][Hashtable]$Parameter,
135+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Value
136+
)
137+
Process {
138+
Write-Host -Object "::$StdOutCommand$(($Parameter.Count -igt 0) ? " $(
139+
$Parameter.GetEnumerator() |
140+
Sort-Object -Property 'Name' |
141+
ForEach-Object -Process { "$($_.Name)=$(Format-StdOutCommandParameterValue -InputObject $_.Value)" } |
142+
Join-String -Separator ','
143+
)" : '')::$(Format-StdOutCommandValue -InputObject $Value)"
144+
}
145+
}
146+
Set-Alias -Name 'Write-Command' -Value 'Write-StdOutCommand' -Option 'ReadOnly' -Scope 'Local'
125147
Export-ModuleMember -Function @(
126-
'Write-Command',
127-
'Write-FileCommand'
148+
'Write-FileCommand',
149+
'Write-StdOutCommand'
150+
) -Alias @(
151+
'Write-Command'
128152
)

hugoalh.GitHubActionsToolkit/module/command-control.psm1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Function Disable-EchoingCommands {
3636
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_disablegithubactionsechoingcommands')]
3737
[OutputType([Void])]
3838
Param ()
39-
Write-GitHubActionsCommand -Command 'echo' -Value 'off'
39+
Write-GitHubActionsStdOutCommand -StdOutCommand 'echo' -Value 'off'
4040
}
4141
Set-Alias -Name 'Disable-CommandEcho' -Value 'Disable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
4242
Set-Alias -Name 'Disable-CommandEchoing' -Value 'Disable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -69,7 +69,7 @@ Function Disable-ProcessingCommands {
6969
Param (
7070
[Parameter(Position = 0)][ValidateScript({ Test-ProcessingCommandsEndToken -InputObject $_ }, ErrorMessage = 'Parameter `EndToken` must be in single line string, more than or equal to 4 characters, not match any GitHub Actions commands, and unique!')][Alias('EndKey', 'EndValue', 'Key', 'Token', 'Value')][String]$EndToken = (New-CommandsEndToken)
7171
)
72-
Write-GitHubActionsCommand -Command 'stop-commands' -Value $EndToken
72+
Write-GitHubActionsStdOutCommand -StdOutCommand 'stop-commands' -Value $EndToken
7373
Write-Output -InputObject $EndToken
7474
}
7575
Set-Alias -Name 'Disable-CommandProcess' -Value 'Disable-ProcessingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -99,7 +99,7 @@ Function Enable-EchoingCommands {
9999
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_enablegithubactionsechoingcommands')]
100100
[OutputType([Void])]
101101
Param ()
102-
Write-GitHubActionsCommand -Command 'echo' -Value 'on'
102+
Write-GitHubActionsStdOutCommand -StdOutCommand 'echo' -Value 'on'
103103
}
104104
Set-Alias -Name 'Enable-CommandEcho' -Value 'Enable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
105105
Set-Alias -Name 'Enable-CommandEchoing' -Value 'Enable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -132,7 +132,7 @@ Function Enable-ProcessingCommands {
132132
Param (
133133
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({ Test-ProcessingCommandsEndToken -InputObject $_ }, ErrorMessage = 'Parameter `EndToken` must be in single line string, more than or equal to 4 characters, and not match any GitHub Actions commands!')][Alias('EndKey', 'EndValue', 'Key', 'Token', 'Value')][String]$EndToken
134134
)
135-
Write-GitHubActionsCommand -Command $EndToken
135+
Write-GitHubActionsStdOutCommand -StdOutCommand $EndToken
136136
}
137137
Set-Alias -Name 'Enable-CommandProcess' -Value 'Enable-ProcessingCommands' -Option 'ReadOnly' -Scope 'Local'
138138
Set-Alias -Name 'Enable-CommandProcessing' -Value 'Enable-ProcessingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -164,7 +164,7 @@ Function New-CommandsEndToken {
164164
Do {
165165
[String]$Result = New-GitHubActionsRandomToken
166166
}
167-
While ( $Result -iin $GitHubActionsCommandsEndTokensUsed )
167+
While ($Result -iin $GitHubActionsCommandsEndTokensUsed)
168168
$Script:GitHubActionsCommandsEndTokensUsed += $Result
169169
Write-Output -InputObject $Result
170170
}
@@ -185,7 +185,7 @@ Function Test-ProcessingCommandsEndToken {
185185
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][Alias('Input', 'Object')][String]$InputObject
186186
)
187187
Process {
188-
$InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject.Length -ige 4 -and $InputObject -inotin $GitHubActionsCommands |
188+
($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$') -and ($InputObject.Length -ige 4) -and ($InputObject -inotin $GitHubActionsCommands) |
189189
Write-Output
190190
}
191191
}

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ Function Set-EnvironmentVariable {
8181
Process {
8282
If ($PSCmdlet.ParameterSetName -ieq 'Multiple') {
8383
If (
84-
$InputObject -is [Hashtable] -or
85-
$InputObject -is [System.Collections.Specialized.OrderedDictionary]
84+
($InputObject -is [Hashtable]) -or
85+
($InputObject -is [System.Collections.Specialized.OrderedDictionary])
8686
) {
8787
$InputObject.GetEnumerator() |
8888
Set-EnvironmentVariable -NoToUpper:$NoToUpper.IsPresent -Scope $Scope
@@ -96,7 +96,7 @@ Function Set-EnvironmentVariable {
9696
$Null = [System.Environment]::SetEnvironmentVariable($Name, $Value)
9797
}
9898
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Subsequent) -ieq [GitHubActionsEnvironmentVariableScopes]::Subsequent) {
99-
Write-GitHubActionsFileCommand -LiteralPath $Env:GITHUB_ENV -Name $Name -Value $Value
99+
Write-GitHubActionsFileCommand -FileCommand 'GITHUB_ENV' -Name $Name -Value $Value
100100
}
101101
}
102102
}
@@ -119,7 +119,7 @@ Function Test-EnvironmentVariableName {
119119
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][Alias('Input', 'Object')][String]$InputObject
120120
)
121121
Process {
122-
$InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject -inotmatch '^(?:CI|PATH)$|^(?:ACTIONS|GITHUB|RUNNER)_' |
122+
($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$') -and ($InputObject -inotmatch '^(?:CI|PATH)$|^(?:ACTIONS|GITHUB|RUNNER)_') |
123123
Write-Output
124124
}
125125
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#Requires -PSEdition Core -Version 7.2
2+
<#
3+
.SYNOPSIS
4+
GitHub Actions - Internal - Test Environment Path
5+
.DESCRIPTION
6+
Test the environment path whether is valid.
7+
.PARAMETER InputObject
8+
Environment path that need to test.
9+
.OUTPUTS
10+
[Boolean] Test result.
11+
#>
12+
Function Test-EnvironmentPath {
13+
[CmdletBinding()]
14+
[OutputType([Boolean])]
15+
Param (
16+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][Alias('Input', 'Object')][AllowEmptyString()][AllowNull()][String]$InputObject
17+
)
18+
Process {
19+
![String]::IsNullOrEmpty($InputObject) -and [System.IO.Path]::IsPathFullyQualified($InputObject) |
20+
Write-Output
21+
}
22+
}
23+
Export-ModuleMember -Function @(
24+
'Test-EnvironmentPath'
25+
)

hugoalh.GitHubActionsToolkit/module/internal/test-parameter-input-object.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ Function Test-ParameterInputObject {
1717
)
1818
Process {
1919
(
20-
$InputObject -is [Hashtable] -or
21-
$InputObject -is [Object[]] -or
22-
$InputObject -is [System.Collections.Specialized.OrderedDictionary]
20+
($InputObject -is [Hashtable]) -or
21+
($InputObject -is [Object[]]) -or
22+
($InputObject -is [System.Collections.Specialized.OrderedDictionary])
2323
) |
2424
Write-Output
2525
}

hugoalh.GitHubActionsToolkit/module/log.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Function Enter-LogGroup {
3232
Param (
3333
[Parameter(Mandatory = $True, Position = 0)][ValidatePattern('^.+$', ErrorMessage = 'Parameter `Title` must be in single line string!')][Alias('Header', 'Summary')][String]$Title
3434
)
35-
Write-GitHubActionsCommand -Command 'group' -Value $Title
35+
Write-GitHubActionsStdOutCommand -StdOutCommand 'group' -Value $Title
3636
}
3737
Set-Alias -Name 'Enter-Group' -Value 'Enter-LogGroup' -Option 'ReadOnly' -Scope 'Local'
3838
<#
@@ -47,7 +47,7 @@ Function Exit-LogGroup {
4747
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_exitgithubactionsloggroup')]
4848
[OutputType([Void])]
4949
Param ()
50-
Write-GitHubActionsCommand -Command 'endgroup'
50+
Write-GitHubActionsStdOutCommand -StdOutCommand 'endgroup'
5151
}
5252
Set-Alias -Name 'Exit-Group' -Value 'Exit-LogGroup' -Option 'ReadOnly' -Scope 'Local'
5353
<#
@@ -121,7 +121,7 @@ Function Write-Annotation {
121121
If ($Title.Length -igt 0) {
122122
$Property['title'] = $Title
123123
}
124-
Write-GitHubActionsCommand -Command $TypeRaw -Parameter $Property -Value $Message
124+
Write-GitHubActionsStdOutCommand -StdOutCommand $TypeRaw -Parameter $Property -Value $Message
125125
}
126126
}
127127
<#
@@ -141,7 +141,7 @@ Function Write-Debug {
141141
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Content')][String]$Message
142142
)
143143
Process {
144-
Write-GitHubActionsCommand -Command 'debug' -Value $Message
144+
Write-GitHubActionsStdOutCommand -StdOutCommand 'debug' -Value $Message
145145
}
146146
}
147147
<#

0 commit comments

Comments
 (0)