Skip to content

Commit 9f36bc6

Browse files
committed
20220619A
1 parent c0d2cde commit 9f36bc6

12 files changed

+325
-325
lines changed

hugoalh.GitHubActionsToolkit/_get-package-commands.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ This script is use for debug, and help to copy commands to hugoalh.GitHubActions
55
#>
66
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath 'hugoalh.GitHubActionsToolkit.psm1') -Scope 'Local'
77
[PSCustomObject[]]$PackageCommands = Get-Command -Module 'hugoalh.GitHubActionsToolkit' -ListImported
8-
foreach ($CommandType in @('Function', 'Alias')) {
8+
ForEach ($CommandType In @('Function', 'Alias')) {
99
Set-Clipboard -Value "'$(($PackageCommands | Where-Object -FilterScript {
10-
return ($_.CommandType -ieq $CommandType)
10+
Return ($_.CommandType -ieq $CommandType)
1111
} | Sort-Object -Property 'Name').Name -join "',`n'")'" -Confirm
1212
}

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
# Prerelease = ''
218218

219219
# Flag to indicate whether the module requires explicit user acceptance for install/update/save
220-
RequireLicenseAcceptance = $false
220+
RequireLicenseAcceptance = $False
221221

222222
# External dependent modules of this module
223223
# ExternalModuleDependencies = @()

hugoalh.GitHubActionsToolkit/hugoalh.GitHubActionsToolkit.psm1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
'utility'
1414
)
1515
Import-Module -Name ($ModulesNames | ForEach-Object -Process {
16-
return Join-Path -Path $ModuleRoot -ChildPath "$_.psm1"
16+
Return (Join-Path -Path $ModuleRoot -ChildPath "$_.psm1")
1717
}) -Scope 'Local'
1818
[PSCustomObject[]]$PackageCommands = Get-Command -Module $ModulesNames -ListImported
1919
[String[]]$PackageCommandsFunctions = ($PackageCommands | Where-Object -FilterScript {
20-
return ($_.CommandType -ieq 'Function')
20+
Return ($_.CommandType -ieq 'Function')
2121
}).Name
2222
[String[]]$PackageCommandsAliases = ($PackageCommands | Where-Object -FilterScript {
23-
return ($_.CommandType -ieq 'Alias')
23+
Return ($_.CommandType -ieq 'Alias')
2424
}).Name
2525
Export-ModuleMember -Function $PackageCommandsFunctions -Alias $PackageCommandsAliases

hugoalh.GitHubActionsToolkit/module/command-base.psm1

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ String that need to format command parameter characters.
1010
.OUTPUTS
1111
String
1212
#>
13-
function Format-CommandParameter {
13+
Function Format-CommandParameter {
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)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
1818
)
19-
return (Format-CommandValue -InputObject $InputObject) -ireplace ',', '%2C' -ireplace ':', '%3A'
19+
Return ((Format-CommandValue -InputObject $InputObject) -ireplace ',', '%2C' -ireplace ':', '%3A')
2020
}
2121
Set-Alias -Name 'Format-CommandProperty' -Value 'Format-CommandParameter' -Option 'ReadOnly' -Scope 'Local'
2222
<#
@@ -29,13 +29,13 @@ String that need to format command value characters.
2929
.OUTPUTS
3030
String
3131
#>
32-
function Format-CommandValue {
32+
Function Format-CommandValue {
3333
[CmdletBinding()]
3434
[OutputType([String])]
3535
Param (
36-
[Parameter(Mandatory = $true, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
36+
[Parameter(Mandatory = $True, Position = 0)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
3737
)
38-
return $InputObject -ireplace '%', '%25' -ireplace '\n', '%0A' -ireplace '\r', '%0D'
38+
Return ($InputObject -ireplace '%', '%25' -ireplace '\n', '%0A' -ireplace '\r', '%0D')
3939
}
4040
Set-Alias -Name 'Format-CommandContent' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
4141
Set-Alias -Name 'Format-CommandMessage' -Value 'Format-CommandValue' -Option 'ReadOnly' -Scope 'Local'
@@ -53,22 +53,22 @@ Command parameter.
5353
.OUTPUTS
5454
Void
5555
#>
56-
function Write-Command {
56+
Function Write-Command {
5757
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_write-githubactionscommand#Write-GitHubActionsCommand')]
5858
[OutputType([Void])]
5959
Param (
60-
[Parameter(Mandatory = $true, Position = 0, ValueFromPipelineByPropertyName = $true)][ValidatePattern('^(?:[\da-z][\da-z_-]*)?[\da-z]$', ErrorMessage = '`{0}` is not a valid command!')][String]$Command,
61-
[Parameter(Position = 1, ValueFromPipelineByPropertyName = $true)][Alias('Content', 'Message')][String]$Value = '',
62-
[Parameter(Position = 2, ValueFromPipelineByPropertyName = $true)][Alias('Parameters', 'Property', 'Properties')][Hashtable]$Parameter = @{}
60+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^(?:[\da-z][\da-z_-]*)?[\da-z]$', ErrorMessage = '`{0}` is not a valid command!')][String]$Command,
61+
[Parameter(Position = 1, ValueFromPipelineByPropertyName = $True)][Alias('Content', 'Message')][String]$Value = '',
62+
[Parameter(Position = 2, ValueFromPipelineByPropertyName = $True)][Alias('Parameters', 'Property', 'Properties')][Hashtable]$Parameter = @{}
6363
)
64-
begin {}
65-
process {
64+
Begin {}
65+
Process {
6666
Write-Host -Object "::$Command$(($Parameter.Count -igt 0) ? " $(($Parameter.GetEnumerator() | Sort-Object -Property 'Name' | ForEach-Object -Process {
67-
return "$($_.Name)=$(Format-CommandParameter -InputObject $_.Value)"
67+
Return "$($_.Name)=$(Format-CommandParameter -InputObject $_.Value)"
6868
}) -join ',')" : '')::$(Format-CommandValue -InputObject $Value)"
6969
}
70-
end {
71-
return
70+
End {
71+
Return
7272
}
7373
}
7474
Export-ModuleMember -Function @(

hugoalh.GitHubActionsToolkit/module/command-control.psm1

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ Disable echoing most of the commands, the log will not show the command itself;
2828
.OUTPUTS
2929
Void
3030
#>
31-
function Disable-EchoingCommands {
31+
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+
Return (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'
@@ -59,16 +59,16 @@ An end token for function `Enable-GitHubActionsProcessingCommands`.
5959
.OUTPUTS
6060
String
6161
#>
62-
function Disable-ProcessingCommands {
62+
Function Disable-ProcessingCommands {
6363
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_disable-githubactionsprocessingcommands#Disable-GitHubActionsProcessingCommands')]
6464
[OutputType([String])]
6565
Param (
6666
[Parameter(Position = 0)][ValidateScript({
67-
return (Test-ProcessingCommandsEndToken -InputObject $_)
67+
Return (Test-ProcessingCommandsEndToken -InputObject $_)
6868
}, 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-Guid).Guid -ireplace '-', '')
6969
)
7070
Write-GitHubActionsCommand -Command 'stop-commands' -Value $EndToken
71-
return $EndToken
71+
Return $EndToken
7272
}
7373
Set-Alias -Name 'Disable-CommandProcess' -Value 'Disable-ProcessingCommands' -Option 'ReadOnly' -Scope 'Local'
7474
Set-Alias -Name 'Disable-CommandProcessing' -Value 'Disable-ProcessingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -93,11 +93,11 @@ Enable echoing most of the commands, the log will show the command itself; Secre
9393
.OUTPUTS
9494
Void
9595
#>
96-
function Enable-EchoingCommands {
96+
Function Enable-EchoingCommands {
9797
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_enable-githubactionsechoingcommands#Enable-GitHubActionsEchoingCommands')]
9898
[OutputType([Void])]
9999
Param ()
100-
return Write-GitHubActionsCommand -Command 'echo' -Value 'on'
100+
Return (Write-GitHubActionsCommand -Command 'echo' -Value 'on')
101101
}
102102
Set-Alias -Name 'Enable-CommandEcho' -Value 'Enable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
103103
Set-Alias -Name 'Enable-CommandEchoing' -Value 'Enable-EchoingCommands' -Option 'ReadOnly' -Scope 'Local'
@@ -124,15 +124,15 @@ An end token from function `Disable-GitHubActionsProcessingCommands`.
124124
.OUTPUTS
125125
Void
126126
#>
127-
function Enable-ProcessingCommands {
127+
Function Enable-ProcessingCommands {
128128
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_enable-githubactionsprocessingcommands#Enable-GitHubActionsProcessingCommands')]
129129
[OutputType([Void])]
130130
Param (
131-
[Parameter(Mandatory = $true, Position = 0)][ValidateScript({
132-
return (Test-ProcessingCommandsEndToken -InputObject $_)
131+
[Parameter(Mandatory = $True, Position = 0)][ValidateScript({
132+
Return (Test-ProcessingCommandsEndToken -InputObject $_)
133133
}, 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-
return Write-GitHubActionsCommand -Command $EndToken
135+
Return (Write-GitHubActionsCommand -Command $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'
@@ -159,13 +159,13 @@ Processing commands end token that need to test.
159159
.OUTPUTS
160160
Boolean
161161
#>
162-
function Test-ProcessingCommandsEndToken {
162+
Function Test-ProcessingCommandsEndToken {
163163
[CmdletBinding()]
164164
[OutputType([Boolean])]
165165
Param (
166-
[Parameter(Mandatory = $true, Position = 0)][Alias('Input', 'Object')][String]$InputObject
166+
[Parameter(Mandatory = $True, Position = 0)][Alias('Input', 'Object')][String]$InputObject
167167
)
168-
return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject.Length -ige 4 -and $InputObject -inotin $GitHubActionsCommands)
168+
Return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject.Length -ige 4 -and $InputObject -inotin $GitHubActionsCommands)
169169
}
170170
Export-ModuleMember -Function @(
171171
'Disable-EchoingCommands',

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Import-Module -Name @(
44
(Join-Path -Path $PSScriptRoot -ChildPath 'command-base.psm1')
55
) -Prefix 'GitHubActions' -Scope 'Local'
6-
[Flags()] enum GitHubActionsEnvironmentVariableScopes {
6+
[Flags()] Enum GitHubActionsEnvironmentVariableScopes {
77
Current = 1
88
Subsequent = 2
99
}
@@ -21,46 +21,46 @@ Scope of PATH.
2121
.OUTPUTS
2222
Void
2323
#>
24-
function Add-PATH {
24+
Function Add-PATH {
2525
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_add-githubactionspath#Add-GitHubActionsPATH')]
2626
[OutputType([Void])]
2727
Param (
28-
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)][ValidatePattern('^.+$', ErrorMessage = 'Parameter `Path` must be in single line string!')][Alias('Paths')][String[]]$Path,
28+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Parameter `Path` must be in single line string!')][Alias('Paths')][String[]]$Path,
2929
[Alias('NoValidate', 'SkipValidate', 'SkipValidator')][Switch]$NoValidator,
3030
[GitHubActionsEnvironmentVariableScopes]$Scope = [GitHubActionsEnvironmentVariableScopes]3
3131
)
32-
begin {
32+
Begin {
3333
[String[]]$Result = @()
3434
}
35-
process {
36-
foreach ($Item in $Path) {
37-
if (!$NoValidator -and !(Test-Path -Path $Item -PathType 'Container' -IsValid)) {
35+
Process {
36+
ForEach ($Item In $Path) {
37+
If (!$NoValidator -and !(Test-Path -Path $Item -PathType 'Container' -IsValid)) {
3838
Write-Error -Message "``$Item`` is not a valid PATH!" -Category 'SyntaxError'
39-
continue
39+
Continue
4040
}
4141
$Result += $Item
4242
}
4343
}
44-
end {
45-
if ($Result.Count -igt 0) {
46-
switch ($Scope -isplit ', ') {
44+
End {
45+
If ($Result.Count -igt 0) {
46+
Switch ($Scope -isplit ', ') {
4747
{ $_ -icontains 'Current' } {
4848
[String[]]$PATHRaw = [System.Environment]::GetEnvironmentVariable('PATH') -isplit [System.IO.Path]::PathSeparator
4949
$PATHRaw += $Result
5050
[System.Environment]::SetEnvironmentVariable('PATH', ($PATHRaw -join [System.IO.Path]::PathSeparator))
5151
}
5252
{ $_ -icontains 'Subsequent' } {
53-
if ($null -ieq $env:GITHUB_PATH) {
54-
foreach ($Item in $Result) {
53+
If ($null -ieq $env:GITHUB_PATH) {
54+
ForEach ($Item In $Result) {
5555
Write-GitHubActionsCommand -Command 'add-path' -Value $Item
5656
}
57-
} else {
58-
Add-Content -LiteralPath $env:GITHUB_PATH -Value ($Result -join "`n") -Confirm:$false -Encoding 'UTF8NoBOM'
57+
} Else {
58+
Add-Content -LiteralPath $env:GITHUB_PATH -Value ($Result -join "`n") -Confirm:$False -Encoding 'UTF8NoBOM'
5959
}
6060
}
6161
}
6262
}
63-
return
63+
Return
6464
}
6565
}
6666
<#
@@ -81,40 +81,40 @@ Scope of environment variable.
8181
.OUTPUTS
8282
Void
8383
#>
84-
function Set-EnvironmentVariable {
84+
Function Set-EnvironmentVariable {
8585
[CmdletBinding(DefaultParameterSetName = 'Multiple', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_set-githubactionsenvironmentvariable#Set-GitHubActionsEnvironmentVariable')]
8686
[OutputType([Void])]
8787
Param (
88-
[Parameter(Mandatory = $true, ParameterSetName = 'Multiple', Position = 0, ValueFromPipeline = $true)][Alias('Input', 'Object')][Hashtable]$InputObject,
89-
[Parameter(Mandatory = $true, ParameterSetName = 'Single', Position = 0, ValueFromPipelineByPropertyName = $true)][ValidateScript({
90-
return Test-EnvironmentVariableName -InputObject $_
88+
[Parameter(Mandatory = $True, ParameterSetName = 'Multiple', Position = 0, ValueFromPipeline = $True)][Alias('Input', 'Object')][Hashtable]$InputObject,
89+
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 0, ValueFromPipelineByPropertyName = $True)][ValidateScript({
90+
Return (Test-EnvironmentVariableName -InputObject $_)
9191
}, ErrorMessage = '`{0}` is not a valid environment variable name!')][Alias('Key')][String]$Name,
92-
[Parameter(Mandatory = $true, ParameterSetName = 'Single', Position = 1, ValueFromPipelineByPropertyName = $true)][ValidatePattern('^.+$', ErrorMessage = 'Parameter `Value` must be in single line string!')][String]$Value,
92+
[Parameter(Mandatory = $True, ParameterSetName = 'Single', Position = 1, ValueFromPipelineByPropertyName = $True)][ValidatePattern('^.+$', ErrorMessage = 'Parameter `Value` must be in single line string!')][String]$Value,
9393
[Alias('NoToUppercase')][Switch]$NoToUpper,
9494
[GitHubActionsEnvironmentVariableScopes]$Scope = [GitHubActionsEnvironmentVariableScopes]3
9595
)
96-
begin {
96+
Begin {
9797
[Hashtable]$Result = @{}
9898
}
99-
process {
100-
switch ($PSCmdlet.ParameterSetName) {
99+
Process {
100+
Switch ($PSCmdlet.ParameterSetName) {
101101
'Multiple' {
102-
foreach ($Item in $InputObject.GetEnumerator()) {
103-
if ($Item.Name.GetType().Name -ine 'String') {
102+
ForEach ($Item In $InputObject.GetEnumerator()) {
103+
If ($Item.Name.GetType().Name -ine 'String') {
104104
Write-Error -Message 'Parameter `Name` must be type of string!' -Category 'InvalidType'
105-
continue
105+
Continue
106106
}
107-
if (!(Test-EnvironmentVariableName -InputObject $Item.Name)) {
107+
If (!(Test-EnvironmentVariableName -InputObject $Item.Name)) {
108108
Write-Error -Message "``$($Item.Name)`` is not a valid environment variable name!" -Category 'SyntaxError'
109-
continue
109+
Continue
110110
}
111-
if ($Item.Value.GetType().Name -ine 'String') {
111+
If ($Item.Value.GetType().Name -ine 'String') {
112112
Write-Error -Message 'Parameter `Value` must be type of string!' -Category 'InvalidType'
113-
continue
113+
Continue
114114
}
115-
if ($Item.Value -inotmatch '^.+$') {
115+
If ($Item.Value -inotmatch '^.+$') {
116116
Write-Error -Message 'Parameter `Value` must be in single line string!' -Category 'SyntaxError'
117-
continue
117+
Continue
118118
}
119119
$Result[$NoToUpper ? $Item.Name : $Item.Name.ToUpper()] = $Item.Value
120120
}
@@ -124,29 +124,29 @@ function Set-EnvironmentVariable {
124124
}
125125
}
126126
}
127-
end {
128-
if ($Result.Count -igt 0) {
127+
End {
128+
If ($Result.Count -igt 0) {
129129
[PSCustomObject[]]$ResultEnumerator = $Result.GetEnumerator()
130-
switch ($Scope -isplit ', ') {
130+
Switch ($Scope -isplit ', ') {
131131
{ $_ -icontains 'Current' } {
132-
foreach ($Item in $ResultEnumerator) {
132+
ForEach ($Item In $ResultEnumerator) {
133133
[System.Environment]::SetEnvironmentVariable($Item.Name, $Item.Value)
134134
}
135135
}
136136
{ $_ -icontains 'Subsequent' } {
137-
if ($null -ieq $env:GITHUB_ENV) {
138-
foreach ($Item in $ResultEnumerator) {
137+
If ($null -ieq $env:GITHUB_ENV) {
138+
ForEach ($Item In $ResultEnumerator) {
139139
Write-GitHubActionsCommand -Command 'set-env' -Value $Item.Value -Parameter @{ 'name' = $Item.Name }
140140
}
141-
} else {
141+
} Else {
142142
Add-Content -LiteralPath $env:GITHUB_ENV -Value (($ResultEnumerator | ForEach-Object -Process {
143-
return "$($_.Name)=$($_.Value)"
144-
}) -join "`n") -Confirm:$false -Encoding 'UTF8NoBOM'
143+
Return "$($_.Name)=$($_.Value)"
144+
}) -join "`n") -Confirm:$False -Encoding 'UTF8NoBOM'
145145
}
146146
}
147147
}
148148
}
149-
return
149+
Return
150150
}
151151
}
152152
Set-Alias -Name 'Set-Env' -Value 'Set-EnvironmentVariable' -Option 'ReadOnly' -Scope 'Local'
@@ -161,13 +161,13 @@ Environment variable name that need to test.
161161
.OUTPUTS
162162
Boolean
163163
#>
164-
function Test-EnvironmentVariableName {
164+
Function Test-EnvironmentVariableName {
165165
[CmdletBinding()]
166166
[OutputType([Boolean])]
167167
Param (
168-
[Parameter(Mandatory = $true, Position = 0)][Alias('Input', 'Object')][String]$InputObject
168+
[Parameter(Mandatory = $True, Position = 0)][Alias('Input', 'Object')][String]$InputObject
169169
)
170-
return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject -inotmatch '^(?:CI|PATH)$' -and $InputObject -inotmatch '^(?:ACTIONS|GITHUB|RUNNER)_')
170+
Return ($InputObject -imatch '^(?:[\da-z][\da-z_-]*)?[\da-z]$' -and $InputObject -inotmatch '^(?:CI|PATH)$' -and $InputObject -inotmatch '^(?:ACTIONS|GITHUB|RUNNER)_')
171171
}
172172
Export-ModuleMember -Function @(
173173
'Add-PATH',

0 commit comments

Comments
 (0)