Skip to content

Commit c136725

Browse files
committed
20230608A
1 parent f991586 commit c136725

File tree

5 files changed

+54
-24
lines changed

5 files changed

+54
-24
lines changed

hugoalh.GitHubActionsToolkit/module/environment-variable.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ Function Set-EnvironmentVariable {
9090
$InputObject -is [System.Collections.Specialized.OrderedDictionary]
9191
) {
9292
$InputObject.GetEnumerator() |
93-
Set-EnvironmentVariable -NoToUpper:$NoToUpper.IsPresent -Scope $Scope
93+
Set-EnvironmentVariable -NoToUpper:($NoToUpper.IsPresent) -Scope $Scope
9494
Return
9595
}
9696
$InputObject |
97-
Set-EnvironmentVariable -NoToUpper:$NoToUpper.IsPresent -Scope $Scope
97+
Set-EnvironmentVariable -NoToUpper:($NoToUpper.IsPresent) -Scope $Scope
9898
Return
9999
}
100100
If (($Scope -band [GitHubActionsEnvironmentVariableScopes]::Current) -ieq [GitHubActionsEnvironmentVariableScopes]::Current) {

hugoalh.GitHubActionsToolkit/module/internal/new-random-token.psm1

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ Function New-RandomToken {
1616
Param (
1717
[Parameter(Position = 0)][ValidateRange(1, [Int32]::MaxValue)][Int32]$Length = 32
1818
)
19-
[Char[]]$PoolCurrent = Get-Random -InputObject $PoolMain -Shuffle
19+
[Char[]]$PoolCurrent = $PoolMain |
20+
Get-Random -Shuffle
2021
@(1..$Length) |
21-
ForEach-Object -Process { Get-Random -InputObject $PoolCurrent -Count 1 } |
22+
ForEach-Object -Process {
23+
$PoolCurrent |
24+
Get-Random -Count 1
25+
} |
2226
Join-String -Separator '' |
2327
Write-Output
2428
}

hugoalh.GitHubActionsToolkit/module/markup.psm1

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,61 @@
11
#Requires -PSEdition Core -Version 7.2
2+
<#
3+
.SYNOPSIS
4+
GitHub Actions - Convert From CSVM
5+
.DESCRIPTION
6+
Convert a CSVM-formatted string to a collection of custom objects or a collection of hashtables.
7+
.PARAMETER InputObject
8+
CSVM string that need to convert from.
9+
.PARAMETER AsHashtable
10+
Whether to output as a collection of hashtables instead of a collection of objects.
11+
.OUTPUTS
12+
[Hashtable[]] Result as hashtable.
13+
[PSCustomObject[]] Result as object.
14+
#>
215
Function ConvertFrom-CsvM {
3-
[CmdletBinding()]
4-
[OutputType([PSCustomObject[]])]
16+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_convertfromgithubactionscsvm')]
17+
[OutputType(([Hashtable[]], [PSCustomObject[]]))]
518
Param (
6-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
19+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject,
20+
[Alias('ToHashtable')][Switch]$AsHashtable
721
)
822
Process {
923
$InputObject -isplit '\r?\n' |
1024
ForEach-Object -Process {
1125
$Null = $_ -imatch ','
12-
[PSCustomObject](
13-
(ConvertFrom-Csv -InputObject $_ -Header @(0..($Matches.Count + 1))).PSObject.Properties.Value |
26+
[Hashtable]$Result = (ConvertFrom-Csv -InputObject $_ -Header @(0..($Matches.Count + 1))).PSObject.Properties.Value |
1427
Join-String -Separator "`n" |
1528
ConvertFrom-StringData
16-
) |
17-
Write-Output
29+
Write-Output -InputObject ($AsHashtable.IsPresent ? $Result : ([PSCustomObject]$Result))
1830
} |
1931
Write-Output
2032
}
2133
}
34+
<#
35+
.SYNOPSIS
36+
GitHub Actions - Convert From CSVS
37+
.DESCRIPTION
38+
Convert a CSVS-formatted string to a collection of custom objects or a collection of hashtables.
39+
.PARAMETER InputObject
40+
CSVS string that need to convert from.
41+
.PARAMETER AsHashtable
42+
Whether to output as a collection of hashtables instead of a collection of objects.
43+
.OUTPUTS
44+
[Hashtable[]] Result as hashtable.
45+
[PSCustomObject[]] Result as object.
46+
#>
2247
Function ConvertFrom-CsvS {
23-
[CmdletBinding()]
24-
[OutputType([PSCustomObject[]])]
48+
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_convertfromgithubactionscsvs')]
49+
[OutputType(([Hashtable[]], [PSCustomObject[]]))]
2550
Param (
26-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject
51+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyString()][Alias('Input', 'Object')][String]$InputObject,
52+
[Alias('ToHashtable')][Switch]$AsHashtable
2753
)
2854
Process {
2955
$Null = $InputObject -imatch ';'
3056
(ConvertFrom-Csv -InputObject $InputObject -Delimiter ';' -Header @(0..($Matches.Count + 1))).PSObject.Properties.Value |
3157
Join-String -Separator "`n" |
32-
ConvertFrom-CsvM |
58+
ConvertFrom-CsvM -AsHashtable:($AsHashtable.IsPresent) |
3359
Write-Output
3460
}
3561
}

hugoalh.GitHubActionsToolkit/module/step-summary.psm1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Function Add-StepSummary {
7777
Add-Content -LiteralPath $Env:GITHUB_STEP_SUMMARY -Value (
7878
$Value |
7979
Join-String -Separator "`n"
80-
) -Confirm:$False -NoNewline:$NoNewLine.IsPresent -Encoding 'UTF8NoBOM'
80+
) -Confirm:$False -NoNewline:($NoNewLine.IsPresent) -Encoding 'UTF8NoBOM'
8181
}
8282
}
8383
}
@@ -157,15 +157,15 @@ Function Add-StepSummaryImage {
157157
$ResultHtml += " height=`"$Height`""
158158
}
159159
$ResultHtml += ' />'
160-
Add-StepSummary -Value $ResultHtml -NoNewLine:$NoNewLine.IsPresent
160+
Add-StepSummary -Value $ResultHtml -NoNewLine:($NoNewLine.IsPresent)
161161
}
162162
Else {
163163
[String]$ResultMarkdown = "![$([System.Web.HttpUtility]::HtmlAttributeEncode($AlternativeText))]($([Uri]::EscapeUriString($Uri))"
164164
If ($Title.Length -gt 0) {
165165
$ResultMarkdown += " `"$([System.Web.HttpUtility]::HtmlAttributeEncode($Title))`""
166166
}
167167
$ResultMarkdown += ')'
168-
Add-StepSummary -Value $ResultMarkdown -NoNewLine:$NoNewLine.IsPresent
168+
Add-StepSummary -Value $ResultMarkdown -NoNewLine:($NoNewLine.IsPresent)
169169
}
170170
}
171171
Set-Alias -Name 'Add-StepSummaryPicture' -Value 'Add-StepSummaryImage' -Option 'ReadOnly' -Scope 'Local'
@@ -201,7 +201,7 @@ Function Add-StepSummaryLink {
201201
$ResultMarkdown += " `"$([System.Web.HttpUtility]::HtmlAttributeEncode($Title))`""
202202
}
203203
$ResultMarkdown += ')'
204-
Add-StepSummary -Value $ResultMarkdown -NoNewLine:$NoNewLine.IsPresent
204+
Add-StepSummary -Value $ResultMarkdown -NoNewLine:($NoNewLine.IsPresent)
205205
}
206206
Set-Alias -Name 'Add-StepSummaryHyperlink' -Value 'Add-StepSummaryLink' -Option 'ReadOnly' -Scope 'Local'
207207
<#
@@ -223,7 +223,7 @@ Function Add-StepSummarySubscriptText {
223223
[Parameter(Mandatory = $True, Position = 0)][Alias('Input', 'InputObject', 'Object')][String]$Text,
224224
[Switch]$NoNewLine
225225
)
226-
Add-StepSummary -Value "<sub>$([System.Web.HttpUtility]::HtmlEncode($Text))</sub>" -NoNewLine:$NoNewLine.IsPresent
226+
Add-StepSummary -Value "<sub>$([System.Web.HttpUtility]::HtmlEncode($Text))</sub>" -NoNewLine:($NoNewLine.IsPresent)
227227
}
228228
Set-Alias -Name 'Add-StepSummarySubscript' -Value 'Add-StepSummarySubscriptText' -Option 'ReadOnly' -Scope 'Local'
229229
<#
@@ -245,7 +245,7 @@ Function Add-StepSummarySuperscriptText {
245245
[Parameter(Mandatory = $True, Position = 0)][Alias('Input', 'InputObject', 'Object')][String]$Text,
246246
[Switch]$NoNewLine
247247
)
248-
Add-StepSummary -Value "<sup>$([System.Web.HttpUtility]::HtmlEncode($Text))</sup>" -NoNewLine:$NoNewLine.IsPresent
248+
Add-StepSummary -Value "<sup>$([System.Web.HttpUtility]::HtmlEncode($Text))</sup>" -NoNewLine:($NoNewLine.IsPresent)
249249
}
250250
Set-Alias -Name 'Add-StepSummarySuperscript' -Value 'Add-StepSummarySuperscriptText' -Option 'ReadOnly' -Scope 'Local'
251251
<#
@@ -276,7 +276,7 @@ Function Get-StepSummary {
276276
}
277277
Switch ($PSCmdlet.ParameterSetName) {
278278
'Content' {
279-
(Get-Content -LiteralPath $Env:GITHUB_STEP_SUMMARY -Raw:$Raw.IsPresent -Encoding 'UTF8NoBOM' -ErrorAction 'Continue') ?? '' |
279+
(Get-Content -LiteralPath $Env:GITHUB_STEP_SUMMARY -Raw:($Raw.IsPresent) -Encoding 'UTF8NoBOM' -ErrorAction 'Continue') ?? '' |
280280
Write-Output
281281
}
282282
'Sizes' {
@@ -347,7 +347,7 @@ Function Set-StepSummary {
347347
Set-Content -LiteralPath $Env:GITHUB_STEP_SUMMARY -Value (
348348
$Result |
349349
Join-String -Separator "`n"
350-
) -Confirm:$False -NoNewline:$NoNewLine.IsPresent -Encoding 'UTF8NoBOM'
350+
) -Confirm:$False -NoNewline:($NoNewLine.IsPresent) -Encoding 'UTF8NoBOM'
351351
}
352352
}
353353
}

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Function Get-WebhookEventPayload {
7676
Return
7777
}
7878
Get-Content -LiteralPath $Env:GITHUB_EVENT_PATH -Raw -Encoding 'UTF8NoBOM' |
79-
ConvertFrom-Json -AsHashtable:$AsHashtable.IsPresent -Depth 100 -NoEnumerate |
79+
ConvertFrom-Json -AsHashtable:($AsHashtable.IsPresent) -Depth 100 -NoEnumerate |
8080
Write-Output
8181
}
8282
Set-Alias -Name 'Get-Event' -Value 'Get-WebhookEventPayload' -Option 'ReadOnly' -Scope 'Local'

0 commit comments

Comments
 (0)