@@ -40,23 +40,6 @@ function Format-GHActionsCommand {
40
40
}
41
41
<#
42
42
. SYNOPSIS
43
- GitHub Actions - Internal - Get All Environment Variable
44
- . DESCRIPTION
45
- An internal function to get all environment variable.
46
- . OUTPUTS
47
- Hashtable
48
- #>
49
- function Get-AllEnvironmentVariable {
50
- [CmdletBinding ()][OutputType ([hashtable ])]
51
- param ()
52
- [hashtable ]$Result = @ {}
53
- Get-ChildItem - Path ' Env:\' | ForEach-Object - Process {
54
- $Result [$_.Name ] = $_.Value
55
- }
56
- return $Result
57
- }
58
- <#
59
- . SYNOPSIS
60
43
GitHub Actions - Internal - Write Workflow Command
61
44
. DESCRIPTION
62
45
An internal function to write workflow command.
@@ -100,31 +83,37 @@ Environment variable value.
100
83
Void
101
84
#>
102
85
function Add-GHActionsEnvironmentVariable {
103
- [CmdletBinding (DefaultParameterSetName = ' 1 ' )][OutputType ([void ])]
86
+ [CmdletBinding (DefaultParameterSetName = ' multiple ' )][OutputType ([void ])]
104
87
param (
105
- [Parameter (Mandatory = $true , ParameterSetName = ' 1 ' , Position = 0 , ValueFromPipeline = $true )][Alias (' Input' , ' Object' )][hashtable ]$InputObject ,
106
- [Parameter (Mandatory = $true , ParameterSetName = ' 2 ' , Position = 0 )][ValidatePattern (' ^[\da-z_]+$' )][Alias (' Key' )][string ]$Name ,
107
- [Parameter (Mandatory = $true , ParameterSetName = ' 2 ' , Position = 1 )][ValidatePattern (' ^.+$' )][string ]$Value
88
+ [Parameter (Mandatory = $true , ParameterSetName = ' multiple ' , Position = 0 , ValueFromPipeline = $true )][Alias (' Input' , ' Object' )][hashtable ]$InputObject ,
89
+ [Parameter (Mandatory = $true , ParameterSetName = ' single ' , Position = 0 )][ValidatePattern (' ^[\da-z_]+$' )][Alias (' Key' )][string ]$Name ,
90
+ [Parameter (Mandatory = $true , ParameterSetName = ' single ' , Position = 1 )][ValidatePattern (' ^.+$' )][string ]$Value
108
91
)
109
92
begin {
110
93
[hashtable ]$Result = @ {}
111
94
}
112
95
process {
113
96
switch ($PSCmdlet.ParameterSetName ) {
114
- ' 1' { $InputObject.GetEnumerator () | ForEach-Object - Process {
115
- if ($_.Name.GetType ().Name -ne ' string' ) {
116
- Write-Error - Message " Input name `" $ ( $_.Name ) `" must be type of string!" - Category InvalidType
117
- } elseif ($_.Name -notmatch ' ^[\da-z_]+$' ) {
118
- Write-Error - Message " Input name `" $ ( $_.Name ) `" is not match the require pattern!" - Category SyntaxError
119
- } elseif ($_.Value.GetType ().Name -ne ' string' ) {
120
- Write-Error - Message " Input value `" $ ( $_.Value ) `" must be type of string!" - Category InvalidType
121
- } elseif ($_.Value -notmatch ' ^.+$' ) {
122
- Write-Error - Message " Input value `" $ ( $_.Value ) `" is not match the require pattern!" - Category SyntaxError
123
- } else {
124
- $Result [$_.Name ] = $_.Value
97
+ ' multiple' {
98
+ $InputObject.GetEnumerator () | ForEach-Object - Process {
99
+ if ($_.Name.GetType ().Name -ne ' string' ) {
100
+ Write-Error - Message " Input name `" $ ( $_.Name ) `" must be type of string!" - Category InvalidType
101
+ } elseif ($_.Name -notmatch ' ^[\da-z_]+$' ) {
102
+ Write-Error - Message " Input name `" $ ( $_.Name ) `" is not match the require pattern!" - Category SyntaxError
103
+ } elseif ($_.Value.GetType ().Name -ne ' string' ) {
104
+ Write-Error - Message " Input value `" $ ( $_.Value ) `" must be type of string!" - Category InvalidType
105
+ } elseif ($_.Value -notmatch ' ^.+$' ) {
106
+ Write-Error - Message " Input value `" $ ( $_.Value ) `" is not match the require pattern!" - Category SyntaxError
107
+ } else {
108
+ $Result [$_.Name ] = $_.Value
109
+ }
125
110
}
126
- }; break }
127
- ' 2' { $Result [$Name ] = $Value ; break }
111
+ break
112
+ }
113
+ ' single' {
114
+ $Result [$Name ] = $Value
115
+ break
116
+ }
128
117
}
129
118
}
130
119
end {
@@ -182,7 +171,8 @@ function Add-GHActionsProblemMatcher {
182
171
)
183
172
begin {}
184
173
process {
185
- Resolve-Path - Path $Path - Relative | ForEach-Object - Process {
174
+ [string []]$PathResolve = Resolve-Path - Path $Path - Relative
175
+ $PathResolve | ForEach-Object - Process {
186
176
if ((Test-Path - Path $_ - PathType Leaf) -and ((Split-Path - Path $_ - Extension) -eq ' .json' )) {
187
177
Write-GHActionsCommand - Command ' add-matcher' - Message ($_ -replace ' ^\.\\' , ' ' -replace ' \\' , ' /' )
188
178
} else {
@@ -332,40 +322,75 @@ Get input.
332
322
Name of the input.
333
323
. PARAMETER Require
334
324
Whether the input is require. If required and not present, will throw an error.
325
+ . PARAMETER All
326
+ Get all of the input.
335
327
. PARAMETER Trim
336
328
Trim the input's value.
337
329
. OUTPUTS
338
330
Hashtable | String
339
331
#>
340
332
function Get-GHActionsInput {
341
- [CmdletBinding ()][OutputType ([hashtable ], [string ])]
333
+ [CmdletBinding (DefaultParameterSetName = ' select ' )][OutputType ([hashtable ], [string ])]
342
334
param (
343
- [Parameter (Mandatory = $true , Position = 0 , ValueFromPipeline = $true )][Alias (' Key' , ' Keys' , ' Names' )][string []]$Name ,
344
- [Alias (' Required' )][switch ]$Require ,
335
+ [Parameter (Mandatory = $true , ParameterSetName = ' select' , Position = 0 , ValueFromPipeline = $true )][SupportsWildcards ()][ValidatePattern (' ^.+$' )][Alias (' Key' , ' Keys' , ' Names' )][string []]$Name ,
336
+ [Parameter (ParameterSetName = ' select' )][Alias (' Required' )][switch ]$Require ,
337
+ [Parameter (ParameterSetName = ' all' )][switch ]$All ,
345
338
[switch ]$Trim
346
339
)
347
340
begin {
348
341
[hashtable ]$Result = @ {}
342
+ [bool ]$ResultIsHashtable = $false
349
343
}
350
344
process {
351
- $Name | ForEach-Object - Process {
352
- $InputValue = Get-ChildItem - Path " Env:\INPUT_$ ( $_.ToUpper () -replace ' [ \n\r\s\t]+' , ' _' ) " - ErrorAction SilentlyContinue
353
- if ($null -eq $InputValue ) {
354
- if ($Require ) {
355
- throw " Input `` $_ `` is not defined!"
345
+ switch ($PSCmdlet.ParameterSetName ) {
346
+ ' all' {
347
+ $ResultIsHashtable = $true
348
+ [string []]$NameResolve = Get-ChildItem - Path ' Env:\' - Include ' INPUT_*'
349
+ $NameResolve | ForEach-Object - Process {
350
+ $InputValue = Get-ChildItem - Path " Env:\INPUT_$_ "
351
+ if ($Trim ) {
352
+ $Result [$_ ] = $InputValue.Value.Trim ()
353
+ } else {
354
+ $Result [$_ ] = $InputValue.Value
355
+ }
356
356
}
357
- $Result [$_ ] = $InputValue
358
- } else {
359
- if ($Trim ) {
360
- $Result [$_ ] = $InputValue.Value.Trim ()
361
- } else {
362
- $Result [$_ ] = $InputValue.Value
357
+ break
358
+ }
359
+ ' select' {
360
+ $Name | ForEach-Object - Process {
361
+ if ([WildcardPattern ]::ContainsWildcardCharacters($Name )) {
362
+ $Function: ResultIsHashtable = $true
363
+ [string []]$NameResolve = Get-ChildItem - Path ' Env:\' - Include " INPUT_$Name "
364
+ $NameResolve | ForEach-Object - Process {
365
+ $InputValue = Get-ChildItem - Path " Env:\INPUT_$_ "
366
+ if ($Trim ) {
367
+ $Result [$_ ] = $InputValue.Value.Trim ()
368
+ } else {
369
+ $Result [$_ ] = $InputValue.Value
370
+ }
371
+ }
372
+ } else {
373
+ $InputValue = Get-ChildItem - Path " Env:\INPUT_$_ " - ErrorAction SilentlyContinue
374
+ if ($null -eq $InputValue ) {
375
+ if ($Require ) {
376
+ throw " Input `` $_ `` is not defined!"
377
+ }
378
+ $Result [$_ ] = $InputValue
379
+ } else {
380
+ if ($Trim ) {
381
+ $Result [$_ ] = $InputValue.Value.Trim ()
382
+ } else {
383
+ $Result [$_ ] = $InputValue.Value
384
+ }
385
+ }
386
+ }
363
387
}
388
+ break
364
389
}
365
390
}
366
391
}
367
392
end {
368
- if ($ Result.Count -eq 1 ) {
393
+ if (( $ResultIsHashtable -eq $false ) -and ( $ Result.Count -eq 1 ) ) {
369
394
return $Result.Values [0 ]
370
395
}
371
396
return $Result
0 commit comments