Skip to content

Commit d48613a

Browse files
committed
20220631A
1 parent b473b5b commit d48613a

File tree

6 files changed

+132
-90
lines changed

6 files changed

+132
-90
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ Import-Module -Name 'hugoalh.GitHubActionsToolkit' -Prefix 'GitHubActions' -Scop
9898
- `Write-GitHubActionsError`
9999
- `Write-GitHubActionsFail`
100100
- `Write-GitHubActionsNotice`
101+
- `Write-GitHubActionsRaw`
101102
- `Write-GitHubActionsWarning`
102103

103104
### Example (Excerpt)

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
'Write-Error',
107107
'Write-Fail',
108108
'Write-Notice',
109+
'Write-Raw',
109110
'Write-Warning'
110111
)
111112

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@
22
#Requires -Version 7.2
33
<#
44
.SYNOPSIS
5-
GitHub Actions (Internal) - Format Command Parameter
5+
GitHub Actions (Internal) - Format Command Parameter Value
66
.DESCRIPTION
7-
Format command parameter characters that can cause issues.
7+
Format command parameter value characters that can cause issues.
88
.PARAMETER InputObject
9-
String that need to format command parameter characters.
9+
String that need to format command parameter value characters.
1010
.OUTPUTS
11-
[String] A string that formatted command parameter characters.
11+
[String] A string that formatted command parameter value characters.
1212
#>
13-
Function Format-CommandParameter {
13+
Function Format-CommandParameterValue {
1414
[CmdletBinding()]
1515
[OutputType([String])]
1616
Param (
17-
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
17+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
1818
)
19-
Return ((Format-CommandValue -InputObject $InputObject) -ireplace ',', '%2C' -ireplace ':', '%3A')
19+
Begin {}
20+
Process {
21+
Return ((Format-CommandValue -InputObject $InputObject) -ireplace ',', '%2C' -ireplace ':', '%3A')
22+
}
23+
End {}
2024
}
21-
Set-Alias -Name 'Format-CommandProperty' -Value 'Format-CommandParameter' -Option 'ReadOnly' -Scope 'Local'
25+
Set-Alias -Name 'Format-CommandPropertyValue' -Value 'Format-CommandParameterValue' -Option 'ReadOnly' -Scope 'Local'
2226
<#
2327
.SYNOPSIS
2428
GitHub Actions (Internal) - Format Command Value
@@ -33,9 +37,13 @@ Function Format-CommandValue {
3337
[CmdletBinding()]
3438
[OutputType([String])]
3539
Param (
36-
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
40+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
3741
)
38-
Return ($InputObject -ireplace '%', '%25' -ireplace '\n', '%0A' -ireplace '\r', '%0D')
42+
Begin {}
43+
Process {
44+
Return ($InputObject -ireplace '%', '%25' -ireplace '\n', '%0A' -ireplace '\r', '%0D')
45+
}
46+
End {}
3947
}
4048
Set-Alias -Name 'Format-CommandContent' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
4149
Set-Alias -Name 'Format-CommandMessage' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
@@ -46,10 +54,10 @@ GitHub Actions - Write Command
4654
Write command to communicate with the runner machine.
4755
.PARAMETER Command
4856
Command.
49-
.PARAMETER Value
50-
Command value.
5157
.PARAMETER Parameter
5258
Command parameter.
59+
.PARAMETER Value
60+
Command value.
5361
.OUTPUTS
5462
[Void]
5563
#>
@@ -58,18 +66,16 @@ Function Write-Command {
5866
[OutputType([Void])]
5967
Param (
6068
[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,
61-
[Parameter(Position = 1, ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Value = '',
62-
[Parameter(Position = 2, ValueFromPipelineByPropertyName = $True)][Alias('Parameters', 'Properties', 'Property')][Hashtable]$Parameter = @{}
69+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Parameters', 'Properties', 'Property')][Hashtable]$Parameter = @{},
70+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Value = ''
6371
)
6472
Begin {}
6573
Process {
66-
Write-Host -Object "::$Command$(($Parameter.Count -igt 0) ? " $(($Parameter.GetEnumerator() | Sort-Object -Property 'Name' | ForEach-Object -Process {
67-
Return "$($_.Name)=$(Format-CommandParameter -InputObject $_.Value)"
68-
}) -join ',')" : '')::$(Format-CommandValue -InputObject $Value)"
69-
}
70-
End {
71-
Return
74+
Return (Write-Host -Object "::$Command$(($Parameter.Count -igt 0) ? " $(($Parameter.GetEnumerator() | Sort-Object -Property 'Name' | ForEach-Object -Process {
75+
Return "$($_.Name)=$(Format-CommandParameterValue -InputObject $_.Value)"
76+
}) -join ',')" : '')::$(Format-CommandValue -InputObject $Value)")
7277
}
78+
End {}
7379
}
7480
Export-ModuleMember -Function @(
7581
'Write-Command'

hugoalh.GitHubActionsToolkit/module/command-control.psm1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,13 @@ Function Test-ProcessingCommandsEndToken {
159159
[CmdletBinding()]
160160
[OutputType([Boolean])]
161161
Param (
162-
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
162+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
163163
)
164-
Return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject.Length -ige 4 -and $InputObject -inotin $GitHubActionsCommands)
164+
Begin {}
165+
Process {
166+
Return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject.Length -ige 4 -and $InputObject -inotin $GitHubActionsCommands)
167+
}
168+
End {}
165169
}
166170
Export-ModuleMember -Function @(
167171
'Disable-EchoingCommands',

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ Function Add-PATH {
4545
If ($Result.Count -igt 0) {
4646
Switch -Exact ($Scope.ToString() -isplit ', ') {
4747
'Current' {
48-
[String[]]$PATHRaw = [System.Environment]::GetEnvironmentVariable('PATH') -isplit [System.IO.Path]::PathSeparator
49-
$PATHRaw += $Result
50-
[System.Environment]::SetEnvironmentVariable('PATH', ($PATHRaw -join [System.IO.Path]::PathSeparator))
48+
[System.Environment]::SetEnvironmentVariable('PATH', (([System.Environment]::GetEnvironmentVariable('PATH') -isplit [System.IO.Path]::PathSeparator + $Result) -join [System.IO.Path]::PathSeparator)) | Out-Null
5149
}
5250
'Subsequent' {
5351
If ($Null -ieq $Env:GITHUB_PATH) {
@@ -60,7 +58,6 @@ Function Add-PATH {
6058
}
6159
}
6260
}
63-
Return
6461
}
6562
}
6663
<#
@@ -128,13 +125,13 @@ Function Set-EnvironmentVariable {
128125
Switch -Exact ($Scope.ToString() -isplit ', ') {
129126
'Current' {
130127
ForEach ($Item In $ResultEnumerator) {
131-
[System.Environment]::SetEnvironmentVariable($Item.Name, $Item.Value)
128+
[System.Environment]::SetEnvironmentVariable($Item.Name, $Item.Value) | Out-Null
132129
}
133130
}
134131
'Subsequent' {
135132
If ($Null -ieq $Env:GITHUB_ENV) {
136133
ForEach ($Item In $ResultEnumerator) {
137-
Write-GitHubActionsCommand -Command 'set-env' -Value $Item.Value -Parameter @{ 'name' = $Item.Name }
134+
Write-GitHubActionsCommand -Command 'set-env' -Parameter @{ 'name' = $Item.Name } -Value $Item.Value
138135
}
139136
} Else {
140137
Add-Content -LiteralPath $Env:GITHUB_ENV -Value (($ResultEnumerator | ForEach-Object -Process {
@@ -144,7 +141,6 @@ Function Set-EnvironmentVariable {
144141
}
145142
}
146143
}
147-
Return
148144
}
149145
}
150146
Set-Alias -Name 'Set-Env' -Value 'Set-EnvironmentVariable' -Option 'ReadOnly' -Scope 'Local'
@@ -163,9 +159,13 @@ Function Test-EnvironmentVariableName {
163159
[CmdletBinding()]
164160
[OutputType([Boolean])]
165161
Param (
166-
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
162+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
167163
)
168-
Return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject -inotmatch '^(?:CI|PATH)$' -and $InputObject -inotmatch '^(?:ACTIONS|GITHUB|RUNNER)_')
164+
Begin {}
165+
Process {
166+
Return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject -inotmatch '^(?:CI|PATH)$' -and $InputObject -inotmatch '^(?:ACTIONS|GITHUB|RUNNER)_')
167+
}
168+
End {}
169169
}
170170
Export-ModuleMember -Function @(
171171
'Add-PATH',

0 commit comments

Comments
 (0)