Skip to content

Commit db9d341

Browse files
committed
20220702A
1 parent d48613a commit db9d341

16 files changed

+408
-345
lines changed

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -28,43 +28,41 @@ Function Export-Artifact {
2828
[CmdletBinding(DefaultParameterSetName = 'Path', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_export-githubactionsartifact#Export-GitHubActionsArtifact')]
2929
[OutputType([PSCustomObject])]
3030
Param (
31-
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({ Return (Test-ArtifactName -InputObject $_) }, ErrorMessage = '`{0}` is not a valid GitHub Actions artifact name!')][String]$Name,
31+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidateScript({ Return (Test-ArtifactName -InputObject $_) }, ErrorMessage = '`{0}` is not a valid GitHub Actions artifact name!')][String]$Name,
3232
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
3333
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
34-
[ValidateScript({ Return ([System.IO.Path]::IsPathRooted($_) -and (Test-Path -LiteralPath $_ -PathType 'Container')) }, ErrorMessage = '`{0}` is not an exist and valid GitHub Actions artifact base root!')][Alias('Root')][String]$BaseRoot = $Env:GITHUB_WORKSPACE,
35-
[Alias('ContinueOnError')][Switch]$ContinueOnIssue,
36-
[ValidateRange(1, 90)][Alias('RetentionDay')][Byte]$RetentionTime = 0
34+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateScript({ Return ([System.IO.Path]::IsPathRooted($_) -and (Test-Path -LiteralPath $_ -PathType 'Container')) }, ErrorMessage = '`{0}` is not an exist and valid GitHub Actions artifact base root!')][Alias('Root')][String]$BaseRoot = $Env:GITHUB_WORKSPACE,
35+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('ContinueOnError')][Switch]$ContinueOnIssue,
36+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 90)][Alias('RetentionDay')][Byte]$RetentionTime = 0
3737
)
3838
Begin {
39+
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
3940
If (!(Test-GitHubActionsEnvironment -Artifact)) {
40-
Return (Write-Error -Message 'Unable to get GitHub Actions artifact resources!' -Category 'ResourceUnavailable')
41-
Break# This is the best way to early terminate this function without terminate caller/invoker process.
41+
Write-Error -Message 'Unable to get GitHub Actions artifact resources!' -Category 'ResourceUnavailable'
42+
$NoOperation = $True
4243
}
43-
[String]$BaseRootRegularExpression = "^$([RegEx]::Escape((Resolve-Path -LiteralPath $BaseRoot)))"
44-
[String[]]$PathsProceed = @()
4544
}
4645
Process {
46+
If ($NoOperation) {
47+
Return
48+
}
4749
Switch ($PSCmdlet.ParameterSetName) {
4850
'LiteralPath' {
49-
$PathsProceed += ($LiteralPath | ForEach-Object -Process {
51+
[String[]]$PathsProceed = ($LiteralPath | ForEach-Object -Process {
5052
Return ([System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $BaseRoot -ChildPath $_))
5153
})
5254
}
5355
'Path' {
54-
ForEach ($ItemPath In $Path) {
56+
[String[]]$PathsProceed = @()
57+
ForEach ($Item In $Path) {
5558
Try {
56-
$PathsProceed += Resolve-Path -Path ([System.IO.Path]::IsPathRooted($ItemPath) ? $ItemPath : (Join-Path -Path $BaseRoot -ChildPath $ItemPath))
59+
$PathsProceed += Resolve-Path -Path ([System.IO.Path]::IsPathRooted($Item) ? $Item : (Join-Path -Path $BaseRoot -ChildPath $Item))
5760
} Catch {
58-
Write-Error -Message "``$ItemPath`` is not an exist and resolvable path!" -Category 'SyntaxError'
61+
$PathsProceed += $Item
5962
}
6063
}
6164
}
6265
}
63-
}
64-
End {
65-
If ($PathsProceed.Count -ieq 0) {
66-
Return (Write-Error -Message 'No path is defined!' -Category 'NotSpecified')
67-
}
6866
[Hashtable]$InputObject = @{
6967
Name = $Name
7068
Path = $PathsProceed
@@ -75,11 +73,12 @@ Function Export-Artifact {
7573
$InputObject.RetentionTIme = $RetentionTime
7674
}
7775
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\upload.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
78-
If ($ResultRaw -ieq $False) {
76+
If ($Null -ieq $ResultRaw) {
7977
Return
8078
}
8179
Return ($ResultRaw | ConvertFrom-Json -Depth 100)
8280
}
81+
End {}
8382
}
8483
Set-Alias -Name 'Save-Artifact' -Value 'Export-Artifact' -Option 'ReadOnly' -Scope 'Local'
8584
<#
@@ -105,24 +104,28 @@ Function Import-Artifact {
105104
[OutputType([PSCustomObject], ParameterSetName = 'Single')]
106105
Param (
107106
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidateScript({ Return (Test-ArtifactName -InputObject $_) }, ErrorMessage = '`{0}` is not a valid GitHub Actions artifact name!')][String]$Name,
108-
[Parameter(ParameterSetName = 'Single')][Switch]$CreateSubfolder,
107+
[Parameter(ParameterSetName = 'Single', ValueFromPipelineByPropertyName = $True)][Switch]$CreateSubfolder,
109108
[Parameter(Mandatory = $True, ParameterSetName = 'All')][Switch]$All,
110-
[Alias('Dest', 'Target')][String]$Destination = $Env:GITHUB_WORKSPACE
109+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Dest', 'Target')][String]$Destination = $Env:GITHUB_WORKSPACE
111110
)
112111
Begin {
112+
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
113113
If (!(Test-GitHubActionsEnvironment -Artifact)) {
114-
Return (Write-Error -Message 'Unable to get GitHub Actions artifact resources!' -Category 'ResourceUnavailable')
115-
Break# This is the best way to early terminate this function without terminate caller/invoker process.
114+
Write-Error -Message 'Unable to get GitHub Actions artifact resources!' -Category 'ResourceUnavailable'
115+
$NoOperation = $True
116116
}
117117
}
118118
Process {
119+
If ($NoOperation) {
120+
Return
121+
}
119122
Switch ($PSCmdlet.ParameterSetName) {
120123
'All' {
121124
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\download-all.js' -InputObject ([PSCustomObject]@{
122125
Destination = $Destination
123126
} | ConvertTo-Json -Depth 100 -Compress)
124-
If ($ResultRaw -ieq $False) {
125-
Continue
127+
If ($Null -ieq $ResultRaw) {
128+
Return
126129
}
127130
Return ($ResultRaw | ConvertFrom-Json -Depth 100)
128131
}
@@ -132,7 +135,7 @@ Function Import-Artifact {
132135
Destination = $Destination
133136
CreateSubfolder = $CreateSubfolder.IsPresent
134137
} | ConvertTo-Json -Depth 100 -Compress)
135-
If ($ResultRaw -ieq $False) {
138+
If ($Null -ieq $ResultRaw) {
136139
Return
137140
}
138141
Return ($ResultRaw | ConvertFrom-Json -Depth 100)
@@ -156,9 +159,13 @@ Function Test-ArtifactName {
156159
[CmdletBinding()]
157160
[OutputType([Boolean])]
158161
Param (
159-
[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
160163
)
161-
Return ((Test-ArtifactPath -InputObject $InputObject) -and $InputObject -imatch '^[^\\/]+$')
164+
Begin {}
165+
Process {
166+
Return ((Test-ArtifactPath -InputObject $InputObject) -and $InputObject -imatch '^[^\\/]+$')
167+
}
168+
End {}
162169
}
163170
<#
164171
.SYNOPSIS
@@ -174,9 +181,13 @@ Function Test-ArtifactPath {
174181
[CmdletBinding()]
175182
[OutputType([Boolean])]
176183
Param (
177-
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
184+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
178185
)
179-
Return ($InputObject -imatch '^[^":<>|*?\n\r\t]+$')
186+
Begin {}
187+
Process {
188+
Return ($InputObject -imatch '^[^":<>|*?\n\r\t]+$')
189+
}
190+
End {}
180191
}
181192
Export-ModuleMember -Function @(
182193
'Export-Artifact',

hugoalh.GitHubActionsToolkit/module/cache.psm1

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -28,47 +28,37 @@ Function Restore-Cache {
2828
[CmdletBinding(DefaultParameterSetName = 'Path', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_restore-githubactionscache#Restore-GitHubActionsCache')]
2929
[OutputType([String])]
3030
Param (
31-
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({ Return (Test-CacheKey -InputObject $_) }, ErrorMessage = '`{0}` is not a valid GitHub Actions cache key, and/or more than 512 characters!')][Alias('Keys', 'Name', 'Names')][String[]]$Key,
31+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidateScript({ Return (Test-CacheKey -InputObject $_) }, ErrorMessage = '`{0}` is not a valid GitHub Actions cache key, and/or more than 512 characters!')][Alias('Keys', 'Name', 'Names')][String[]]$Key,
3232
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
3333
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
34-
[Alias('NoAzureSdk')][Switch]$NotUseAzureSdk,
35-
[ValidateRange(1, 16)][Byte]$DownloadConcurrency = 0,
36-
[ValidateRange(5, 900)][UInt16]$Timeout = 0
34+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('NoAzureSdk')][Switch]$NotUseAzureSdk,
35+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 16)][Byte]$DownloadConcurrency = 0,
36+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(5, 900)][UInt16]$Timeout = 0
3737
)
3838
Begin {
39+
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
3940
If (!(Test-GitHubActionsEnvironment -Cache)) {
40-
Return (Write-Error -Message 'Unable to get GitHub Actions cache resources!' -Category 'ResourceUnavailable')
41-
Break# This is the best way to early terminate this function without terminate caller/invoker process.
41+
Write-Error -Message 'Unable to get GitHub Actions cache resources!' -Category 'ResourceUnavailable'
42+
$NoOperation = $True
4243
}
43-
[String[]]$PathsProceed = @()
4444
}
4545
Process {
46-
Switch ($PSCmdlet.ParameterSetName) {
47-
'LiteralPath' {
48-
$PathsProceed += ($LiteralPath | ForEach-Object -Process {
49-
Return [WildcardPattern]::Escape($_)
50-
})
51-
}
52-
'Path' {
53-
$PathsProceed += $Path
54-
}
46+
If ($NoOperation) {
47+
Return
5548
}
56-
}
57-
End {
5849
[String[]]$KeysProceed = @()
5950
If ($Key.Count -igt 10) {
6051
Write-Warning -Message "Keys are limit to maximum count of 10! Only first 10 keys will use."
6152
$KeysProceed += ($Key | Select-Object -First 10)
6253
} Else {
6354
$KeysProceed += $Key
6455
}
65-
If ($PathsProceed.Count -ieq 0) {
66-
Return (Write-Error -Message 'No valid path is defined!' -Category 'NotSpecified')
67-
}
6856
[Hashtable]$InputObject = @{
69-
Path = $PathsProceed
7057
PrimaryKey = $KeysProceed[0]
7158
RestoreKey = ($KeysProceed | Select-Object -SkipIndex 0)
59+
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? ($LiteralPath | ForEach-Object -Process {
60+
Return [WildcardPattern]::Escape($_)
61+
}) : $Path
7262
UseAzureSdk = !$NotUseAzureSdk.IsPresent
7363
}
7464
If (!$NotUseAzureSdk.IsPresent) {
@@ -80,11 +70,12 @@ Function Restore-Cache {
8070
}
8171
}
8272
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'cache\restore.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
83-
If ($ResultRaw -ieq $False) {
73+
If ($Null -ieq $ResultRaw) {
8474
Return
8575
}
8676
Return ($ResultRaw | ConvertFrom-Json -Depth 100).CacheKey
8777
}
78+
End {}
8879
}
8980
Set-Alias -Name 'Import-Cache' -Value 'Restore-Cache' -Option 'ReadOnly' -Scope 'Local'
9081
<#
@@ -109,38 +100,28 @@ Function Save-Cache {
109100
[CmdletBinding(DefaultParameterSetName = 'Path', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_save-githubactionscache#Save-GitHubActionsCache')]
110101
[OutputType([String])]
111102
Param (
112-
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({ Return (Test-CacheKey -InputObject $_) }, ErrorMessage = '`{0}` is not a valid GitHub Actions cache key, and/or more than 512 characters!')][Alias('Name')][String]$Key,
103+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidateScript({ Return (Test-CacheKey -InputObject $_) }, ErrorMessage = '`{0}` is not a valid GitHub Actions cache key, and/or more than 512 characters!')][Alias('Name')][String]$Key,
113104
[Parameter(Mandatory = $True, ParameterSetName = 'Path', Position = 1, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][SupportsWildcards()][Alias('File', 'Files', 'Paths')][String[]]$Path,
114105
[Parameter(Mandatory = $True, ParameterSetName = 'LiteralPath', ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('LiteralFile', 'LiteralFiles', 'LiteralPaths', 'LP', 'PSPath', 'PSPaths')][String[]]$LiteralPath,
115-
[ValidateRange(1KB, 1GB)][UInt32]$UploadChunkSizes = 0,
116-
[ValidateRange(1, 16)][Byte]$UploadConcurrency = 0
106+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1KB, 1GB)][UInt32]$UploadChunkSizes = 0,
107+
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateRange(1, 16)][Byte]$UploadConcurrency = 0
117108
)
118109
Begin {
110+
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
119111
If (!(Test-GitHubActionsEnvironment -Cache)) {
120-
Return (Write-Error -Message 'Unable to get GitHub Actions cache resources!' -Category 'ResourceUnavailable')
121-
Break# This is the best way to early terminate this function without terminate caller/invoker process.
112+
Write-Error -Message 'Unable to get GitHub Actions cache resources!' -Category 'ResourceUnavailable'
113+
$NoOperation = $True
122114
}
123-
[String[]]$PathsProceed = @()
124115
}
125116
Process {
126-
Switch ($PSCmdlet.ParameterSetName) {
127-
'LiteralPath' {
128-
$PathsProceed += ($LiteralPath | ForEach-Object -Process {
129-
Return [WildcardPattern]::Escape($_)
130-
})
131-
}
132-
'Path' {
133-
$PathsProceed += $Path
134-
}
135-
}
136-
}
137-
End {
138-
If ($PathsProceed.Count -ieq 0) {
139-
Return (Write-Error -Message 'No valid path is defined!' -Category 'NotSpecified')
117+
If ($NoOperation) {
118+
Return
140119
}
141120
[Hashtable]$InputObject = @{
142121
Key = $Key
143-
Path = $PathsProceed
122+
Path = ($PSCmdlet.ParameterSetName -ieq 'LiteralPath') ? ($LiteralPath | ForEach-Object -Process {
123+
Return [WildcardPattern]::Escape($_)
124+
}) : $Path
144125
}
145126
If ($UploadChunkSizes -igt 0) {
146127
$InputObject.UploadChunkSizes = $UploadChunkSizes
@@ -149,11 +130,12 @@ Function Save-Cache {
149130
$InputObject.UploadConcurrency = $UploadConcurrency
150131
}
151132
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'cache\save.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
152-
If ($ResultRaw -ieq $False) {
133+
If ($Null -ieq $ResultRaw) {
153134
Return
154135
}
155136
Return ($ResultRaw | ConvertFrom-Json -Depth 100).CacheId
156137
}
138+
End {}
157139
}
158140
Set-Alias -Name 'Export-Cache' -Value 'Save-Cache' -Option 'ReadOnly' -Scope 'Local'
159141
<#
@@ -170,9 +152,13 @@ Function Test-CacheKey {
170152
[CmdletBinding()]
171153
[OutputType([Boolean])]
172154
Param (
173-
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
155+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
174156
)
175-
Return ($InputObject.Length -ile 512 -and $InputObject -imatch '^[^,\n\r]+$')
157+
Begin {}
158+
Process {
159+
Return ($InputObject.Length -ile 512 -and $InputObject -imatch '^[^,\n\r]+$')
160+
}
161+
End {}
176162
}
177163
Export-ModuleMember -Function @(
178164
'Restore-Cache',

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ Function Write-Command {
7171
)
7272
Begin {}
7373
Process {
74-
Return (Write-Host -Object "::$Command$(($Parameter.Count -igt 0) ? " $(($Parameter.GetEnumerator() | Sort-Object -Property 'Name' | ForEach-Object -Process {
74+
Write-Host -Object "::$Command$(($Parameter.Count -igt 0) ? " $(($Parameter.GetEnumerator() | Sort-Object -Property 'Name' | ForEach-Object -Process {
7575
Return "$($_.Name)=$(Format-CommandParameterValue -InputObject $_.Value)"
76-
}) -join ',')" : '')::$(Format-CommandValue -InputObject $Value)")
76+
}) -join ',')" : '')::$(Format-CommandValue -InputObject $Value)"
7777
}
7878
End {}
7979
}

hugoalh.GitHubActionsToolkit/module/command-control.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Function Disable-EchoingCommands {
3232
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_disable-githubactionsechoingcommands#Disable-GitHubActionsEchoingCommands')]
3333
[OutputType([Void])]
3434
Param ()
35-
Return (Write-GitHubActionsCommand -Command 'echo' -Value 'off')
35+
Write-GitHubActionsCommand -Command 'echo' -Value 'off'
3636
}
3737
Set-Alias -Name 'Disable-CommandEcho' -Value 'Disable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
3838
Set-Alias -Name 'Disable-CommandEchoing' -Value 'Disable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -95,7 +95,7 @@ Function Enable-EchoingCommands {
9595
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_enable-githubactionsechoingcommands#Enable-GitHubActionsEchoingCommands')]
9696
[OutputType([Void])]
9797
Param ()
98-
Return (Write-GitHubActionsCommand -Command 'echo' -Value 'on')
98+
Write-GitHubActionsCommand -Command 'echo' -Value 'on'
9999
}
100100
Set-Alias -Name 'Enable-CommandEcho' -Value 'Enable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
101101
Set-Alias -Name 'Enable-CommandEchoing' -Value 'Enable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -128,7 +128,7 @@ Function Enable-ProcessingCommands {
128128
Param (
129129
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({ Return (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
130130
)
131-
Return (Write-GitHubActionsCommand -Command $EndToken)
131+
Write-GitHubActionsCommand -Command $EndToken
132132
}
133133
Set-Alias -Name 'Enable-CommandProcess' -Value 'Enable-ProcessingCommands' -Option 'ReadOnly' -Scope 'Local'
134134
Set-Alias -Name 'Enable-CommandProcessing' -Value 'Enable-ProcessingCommands' -Option 'ReadOnly' -Scope 'Local'

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ Function Add-PATH {
4545
If ($Result.Count -igt 0) {
4646
Switch -Exact ($Scope.ToString() -isplit ', ') {
4747
'Current' {
48-
[System.Environment]::SetEnvironmentVariable('PATH', (([System.Environment]::GetEnvironmentVariable('PATH') -isplit [System.IO.Path]::PathSeparator + $Result) -join [System.IO.Path]::PathSeparator)) | Out-Null
48+
[System.Environment]::SetEnvironmentVariable('PATH', ((([System.Environment]::GetEnvironmentVariable('PATH') -isplit [System.IO.Path]::PathSeparator) + $Result) -join [System.IO.Path]::PathSeparator)) | Out-Null
4949
}
5050
'Subsequent' {
5151
If ($Null -ieq $Env:GITHUB_PATH) {
52-
ForEach ($Item In $Result) {
53-
Write-GitHubActionsCommand -Command 'add-path' -Value $Item
52+
$Result | ForEach-Object -Process {
53+
Write-GitHubActionsCommand -Command 'add-path' -Value $_
5454
}
5555
} Else {
5656
Add-Content -LiteralPath $Env:GITHUB_PATH -Value ($Result -join "`n") -Confirm:$False -Encoding 'UTF8NoBOM'
@@ -124,13 +124,13 @@ Function Set-EnvironmentVariable {
124124
[PSCustomObject[]]$ResultEnumerator = $Result.GetEnumerator()
125125
Switch -Exact ($Scope.ToString() -isplit ', ') {
126126
'Current' {
127-
ForEach ($Item In $ResultEnumerator) {
128-
[System.Environment]::SetEnvironmentVariable($Item.Name, $Item.Value) | Out-Null
127+
$ResultEnumerator | ForEach-Object -Process {
128+
[System.Environment]::SetEnvironmentVariable($_.Name, $_.Value) | Out-Null
129129
}
130130
}
131131
'Subsequent' {
132132
If ($Null -ieq $Env:GITHUB_ENV) {
133-
ForEach ($Item In $ResultEnumerator) {
133+
$ResultEnumerator | ForEach-Object -Process {
134134
Write-GitHubActionsCommand -Command 'set-env' -Parameter @{ 'name' = $Item.Name } -Value $Item.Value
135135
}
136136
} Else {

0 commit comments

Comments
 (0)