Skip to content

Commit e27168a

Browse files
committed
20220919B
1 parent f74ae73 commit e27168a

File tree

4 files changed

+30
-72
lines changed

4 files changed

+30
-72
lines changed

hugoalh.GitHubActionsToolkit/module/nodejs-test.psm1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,20 @@ Function Test-NodeJsEnvironment {
3535
Write-Verbose -Message 'Test NodeJS.'
3636
Get-Command -Name 'node' -CommandType 'Application' -ErrorAction 'Stop' |# `Get-Command` will throw error when nothing is found.
3737
Out-Null# No need the result.
38-
[String]$GetNodeJsVersionRawResult = node --no-deprecation --no-warnings --version |
38+
[String]$ExpressionNodeJsVersionResult = node --no-deprecation --no-warnings --version |
3939
Join-String -Separator "`n"
4040
If (
41-
$GetNodeJsVersionRawResult -inotmatch $SemVerRegEx -or
42-
$NodeJsMinimumVersion -igt [SemVer]::Parse(($GetNodeJsVersionRawResult -ireplace '^v', ''))
41+
$ExpressionNodeJsVersionResult -inotmatch $SemVerRegEx -or
42+
$NodeJsMinimumVersion -igt [SemVer]::Parse(($ExpressionNodeJsVersionResult -ireplace '^v', ''))
4343
) {
4444
Throw
4545
}
4646
Write-Verbose -Message 'Test NPM.'
4747
Get-Command -Name 'npm' -CommandType 'Application' -ErrorAction 'Stop' |# `Get-Command` will throw error when nothing is found.
4848
Out-Null# No need the result.
49-
[String[]]$GetNpmVersionRawResult = npm --version# NPM sometimes display other useless things which unable to suppress.
49+
[String[]]$ExpressionNpmVersionResult = npm --version# NPM sometimes display other useless things which unable to suppress.
5050
If (
51-
$GetNpmVersionRawResult -inotmatch $SemVerRegEx -or
51+
$ExpressionNpmVersionResult -inotmatch $SemVerRegEx -or
5252
$NpmMinimumVersion -igt [SemVer]::Parse(($Matches[0] -ireplace '^v', ''))
5353
) {
5454
Throw

hugoalh.GitHubActionsToolkit/module/parameter.psm1

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,16 @@ Function Get-Input {
5050
Switch ($PSCmdlet.ParameterSetName) {
5151
'All' {
5252
ForEach ($Item In (Get-ChildItem -Path 'Env:\INPUT_*')) {
53-
If ($Null -ieq $Item.Value) {
54-
Continue
55-
}
56-
[String]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim() : $Item.Value
57-
If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0) {
58-
Continue
59-
}
60-
$OutputObject[$Item.Name -ireplace '^INPUT_', ''] = $ItemValue
53+
$OutputObject[$Item.Name -ireplace '^INPUT_', ''] = $Item.Value
6154
}
6255
}
6356
'One' {
6457
$InputValueRaw = Get-Content -LiteralPath "Env:\INPUT_$($Name.ToUpper())" -ErrorAction 'SilentlyContinue'
65-
If ($Null -ieq $InputValueRaw) {
66-
If ($Mandatory.IsPresent) {
67-
Write-GitHubActionsFail -Message ($MandatoryMessage -f $Name)
68-
Throw
69-
}
70-
Return
71-
}
72-
[String]$InputValue = $Trim.IsPresent ? $InputValueRaw.Trim() : $InputValueRaw
73-
If ($EmptyStringAsNull.IsPresent -and $InputValue.Length -ieq 0) {
58+
[String]$InputValue = $Trim.IsPresent ? ${InputValueRaw}?.Trim() : $InputValueRaw
59+
If (
60+
$Null -ieq $InputValueRaw -or
61+
($EmptyStringAsNull.IsPresent -and [String]::IsNullOrEmpty($InputValue))
62+
) {
7463
If ($Mandatory.IsPresent) {
7564
Write-GitHubActionsFail -Message ($MandatoryMessage -f $Name)
7665
Throw
@@ -81,27 +70,15 @@ Function Get-Input {
8170
Return
8271
}
8372
'Prefix' {
73+
[RegEx]$InputNameReplaceRegEx = "^INPUT_$([RegEx]::Escape($NamePrefix))"
8474
ForEach ($Item In (Get-ChildItem -Path "Env:\INPUT_$($NamePrefix.ToUpper())*")) {
85-
If ($Null -ieq $Item.Value) {
86-
Continue
87-
}
88-
[String]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim() : $Item.Value
89-
If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0) {
90-
Continue
91-
}
92-
$OutputObject[$Item.Name -ireplace "^INPUT_$([RegEx]::Escape($NamePrefix))", ''] = $ItemValue
75+
$OutputObject[$Item.Name -ireplace $InputNameReplaceRegEx, ''] = $Item.Value
9376
}
9477
}
9578
'Suffix' {
79+
[RegEx]$InputNameReplaceRegEx = "^INPUT_|$([RegEx]::Escape($NameSuffix))$"
9680
ForEach ($Item In (Get-ChildItem -Path "Env:\INPUT_*$($NameSuffix.ToUpper())")) {
97-
If ($Null -ieq $Item.Value) {
98-
Continue
99-
}
100-
[String]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim() : $Item.Value
101-
If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0) {
102-
Continue
103-
}
104-
$OutputObject[$Item.Name -ireplace "^INPUT_|$([RegEx]::Escape($NameSuffix))$", ''] = $ItemValue
81+
$OutputObject[$Item.Name -ireplace $InputNameReplaceRegEx, ''] = $Item.Value
10582
}
10683
}
10784
}
@@ -144,50 +121,31 @@ Function Get-State {
144121
Switch ($PSCmdlet.ParameterSetName) {
145122
'All' {
146123
ForEach ($Item In (Get-ChildItem -Path 'Env:\STATE_*')) {
147-
If ($Null -ieq $Item.Value) {
148-
Continue
149-
}
150-
[String]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim() : $Item.Value
151-
If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0) {
152-
Continue
153-
}
154-
$OutputObject[$Item.Name -ireplace '^STATE_', ''] = $ItemValue
124+
$OutputObject[$Item.Name -ireplace '^STATE_', ''] = $Item.Value
155125
}
156126
}
157127
'One' {
158128
$StateValueRaw = Get-Content -LiteralPath "Env:\STATE_$($Name.ToUpper())" -ErrorAction 'SilentlyContinue'
159-
If ($Null -ieq $StateValueRaw) {
160-
Return
161-
}
162-
[String]$StateValue = $Trim.IsPresent ? $StateValueRaw.Trim() : $StateValueRaw
163-
If ($EmptyStringAsNull.IsPresent -and $StateValue.Length -ieq 0) {
129+
[String]$StateValue = $Trim.IsPresent ? ${StateValueRaw}?.Trim() : $StateValueRaw
130+
If (
131+
$Null -ieq $StateValueRaw -or
132+
($EmptyStringAsNull.IsPresent -and [String]::IsNullOrEmpty($StateValue))
133+
) {
164134
Return
165135
}
166136
Write-Output -InputObject $StateValue
167137
Return
168138
}
169139
'Prefix' {
140+
[RegEx]$StateNameReplaceRegEx = "^STATE_$([RegEx]::Escape($NamePrefix))"
170141
ForEach ($Item In (Get-ChildItem -Path "Env:\STATE_$($NamePrefix.ToUpper())*")) {
171-
If ($Null -ieq $Item.Value) {
172-
Continue
173-
}
174-
[String]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim() : $Item.Value
175-
If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0) {
176-
Continue
177-
}
178-
$OutputObject[$Item.Name -ireplace "^STATE_$([RegEx]::Escape($NamePrefix))", ''] = $ItemValue
142+
$OutputObject[$Item.Name -ireplace $StateNameReplaceRegEx, ''] = $Item.Value
179143
}
180144
}
181145
'Suffix' {
146+
[RegEx]$StateNameReplaceRegEx = "^STATE_|$([RegEx]::Escape($NameSuffix))$"
182147
ForEach ($Item In (Get-ChildItem -Path "Env:\STATE_*$($NameSuffix.ToUpper())")) {
183-
If ($Null -ieq $Item.Value) {
184-
Continue
185-
}
186-
[String]$ItemValue = $Trim.IsPresent ? $Item.Value.Trim() : $Item.Value
187-
If ($EmptyStringAsNull.IsPresent -and $ItemValue.Length -ieq 0) {
188-
Continue
189-
}
190-
$OutputObject[$Item.Name -ireplace "^STATE_|$([RegEx]::Escape($NameSuffix))$", ''] = $ItemValue
148+
$OutputObject[$Item.Name -ireplace $StateNameReplaceRegEx, ''] = $Item.Value
191149
}
192150
}
193151
}

hugoalh.GitHubActionsToolkit/module/problem-matcher.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ Function Add-ProblemMatcher {
2727
)
2828
Process {
2929
($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? $LiteralPath : (
30-
[String[]](Resolve-Path -Path $Path) |
31-
Where-Object -FilterScript { ![String]::IsNullOrEmpty($_) }
32-
) |
33-
ForEach-Object -Process { Write-GitHubActionsCommand -Command 'add-matcher' -Value ($_ -ireplace '^\.[\\/]', '' -ireplace '\\', '/') }
30+
Resolve-Path -Path $Path |
31+
Select-Object -ExpandProperty 'Path' |
32+
ForEach-Object -Process { Write-GitHubActionsCommand -Command 'add-matcher' -Value ($_ -ireplace '^\.[\\/]', '' -ireplace '\\', '/') }
33+
)
3434
}
3535
}
3636
<#

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Function Add-SecretMask {
3030
If ($Value.Length -igt 0) {
3131
Write-GitHubActionsCommand -Command 'add-mask' -Value $Value
3232
If ($WithChunks.IsPresent) {
33-
[String[]]($Value -isplit '[\b\n\r\s\t_-]+') |
33+
$Value -isplit '[\b\n\r\s\t_-]+' |
3434
Where-Object -FilterScript { $_ -ine $Value -and $_.Length -ige 4 } |
3535
ForEach-Object -Process { Write-GitHubActionsCommand -Command 'add-mask' -Value $_ }
3636
}

0 commit comments

Comments
 (0)