Skip to content

Commit 2463fea

Browse files
committed
20220804A
1 parent f8c2ccc commit 2463fea

File tree

3 files changed

+34
-34
lines changed

3 files changed

+34
-34
lines changed

hugoalh.GitHubActionsToolkit/module/step-summary.psm1

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Function Add-StepSummary {
2121
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_add-githubactionsstepsummary#Add-GitHubActionsStepSummary')]
2222
[OutputType([Void])]
2323
Param (
24-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyCollection()][Alias('Content')][String[]]$Value,
24+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True)][AllowEmptyCollection()][AllowEmptyString()][AllowNull()][Alias('Content')][String[]]$Value,
2525
[Switch]$NoNewLine
2626
)
2727
Begin {
@@ -98,8 +98,8 @@ Function Add-StepSummaryImage {
9898
[OutputType([Void])]
9999
Param (
100100
[Parameter(Mandatory = $True, Position = 0)][Alias('Url')][String]$Uri,
101-
[String]$Title = '',
102-
[Alias('AltText')][String]$AlternativeText = '',
101+
[String]$Title,
102+
[Alias('AltText')][String]$AlternativeText,
103103
[ValidateRange(0, [Int32]::MaxValue)][Int32]$Width = -1,
104104
[ValidateRange(0, [Int32]::MaxValue)][Int32]$Height = -1,
105105
[Switch]$NoNewLine
@@ -122,14 +122,15 @@ Function Add-StepSummaryImage {
122122
$ResultHtml += " height=`"$Height`""
123123
}
124124
$ResultHtml += ' />'
125-
Return (Add-StepSummary -Value $ResultHtml -NoNewLine:$NoNewLine.IsPresent)
126-
}
127-
[String]$ResultMarkdown = "![$([System.Web.HttpUtility]::HtmlAttributeEncode($AlternativeText))]($([Uri]::EscapeUriString($Uri))"
128-
If ($Title.Length -igt 0) {
129-
$ResultMarkdown += " `"$([System.Web.HttpUtility]::HtmlAttributeEncode($Title))`""
125+
Add-StepSummary -Value $ResultHtml -NoNewLine:$NoNewLine.IsPresent
126+
} Else {
127+
[String]$ResultMarkdown = "![$([System.Web.HttpUtility]::HtmlAttributeEncode($AlternativeText))]($([Uri]::EscapeUriString($Uri))"
128+
If ($Title.Length -igt 0) {
129+
$ResultMarkdown += " `"$([System.Web.HttpUtility]::HtmlAttributeEncode($Title))`""
130+
}
131+
$ResultMarkdown += ')'
132+
Add-StepSummary -Value $ResultMarkdown -NoNewLine:$NoNewLine.IsPresent
130133
}
131-
$ResultMarkdown += ')'
132-
Add-StepSummary -Value $ResultMarkdown -NoNewLine:$NoNewLine.IsPresent
133134
}
134135
Set-Alias -Name 'Add-StepSummaryPicture' -Value 'Add-StepSummaryImage' -Option 'ReadOnly' -Scope 'Local'
135136
<#
@@ -156,7 +157,7 @@ Function Add-StepSummaryLink {
156157
Param (
157158
[Parameter(Mandatory = $True, Position = 0)][String]$Text,
158159
[Parameter(Mandatory = $True, Position = 1)][Alias('Url')][String]$Uri,
159-
[String]$Title = '',
160+
[String]$Title,
160161
[Switch]$NoNewLine
161162
)
162163
[String]$ResultMarkdown = "[$([System.Web.HttpUtility]::HtmlAttributeEncode($Text))]($([Uri]::EscapeUriString($Uri))"

hugoalh.GitHubActionsToolkit/module/tool-cache.psm1

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ Function Expand-ToolCacheCompressedFile {
3131
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('Source')][String]$File,
3232
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Target')][String]$Destination,
3333
[Parameter(ValueFromPipelineByPropertyName = $True)][ValidateSet('7z', 'Auto', 'Automatic', 'Automatically', 'Tar', 'Xar', 'Zip')][String]$Method = 'Automatically',
34-
[String]$7zrPath = '',
35-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Flags')][String]$Flag = ''
34+
[String]$7zrPath,
35+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Flags')][String]$Flag
3636
)
3737
Begin {
3838
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
@@ -117,7 +117,7 @@ Function Find-ToolCache {
117117
Param (
118118
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][Alias('ToolName')][String]$Name,
119119
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Ver')][String]$Version = '*',
120-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture = ''
120+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture
121121
)
122122
Begin {
123123
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
@@ -170,10 +170,10 @@ Function Invoke-ToolCacheToolDownloader {
170170
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_invoke-githubactionstoolcachetooldownloader#Invoke-GitHubActionsToolCacheToolDownloader')]
171171
[OutputType([String])]
172172
Param (
173-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidateScript({ Return (($Null -ine $_.AbsoluteUri) -and ($_.Scheme -imatch '^https?$')) }, ErrorMessage = '`{0}` is not a valid URI!')][Alias('Url')][Uri]$Uri,
174-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Target')][String]$Destination = '',
175-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Auth')][String]$Authorization = '',
176-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Headers')][Hashtable]$Header = @{}
173+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][ValidateScript({ Return (($Null -ine $_.AbsoluteUri) -and ($_.Scheme -imatch '^https?$')) }, ErrorMessage = '`{0}` is not a valid URI!')][Alias('Source', 'Url')][Uri]$Uri,
174+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Target')][String]$Destination,
175+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Auth')][String]$Authorization,
176+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Headers')][Hashtable]$Header
177177
)
178178
Begin {
179179
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
@@ -187,7 +187,7 @@ Function Invoke-ToolCacheToolDownloader {
187187
Return
188188
}
189189
[Hashtable]$InputObject = @{
190-
Uri = $Uri
190+
Uri = $Uri.ToString()
191191
}
192192
If ($Destination.Length -igt 0) {
193193
$InputObject.Destination = $Destination
@@ -196,7 +196,7 @@ Function Invoke-ToolCacheToolDownloader {
196196
$InputObject.Authorization = $Authorization
197197
}
198198
If ($Header.Count -igt 0) {
199-
$InputObject.Header = ([PSCustomObject]$Header | ConvertTo-Json -Depth 100 -Compress)
199+
$InputObject.Header = [PSCustomObject]$Header
200200
}
201201
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'tool-cache\download-tool.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
202202
If ($Null -ieq $ResultRaw) {
@@ -229,7 +229,7 @@ Function Register-ToolCacheDirectory {
229229
[Parameter(Mandatory = $True, Position = 0, ValueFromPipelineByPropertyName = $True)][Alias('SourceDirectory')][String]$Source,
230230
[Parameter(Mandatory = $True, Position = 1, ValueFromPipelineByPropertyName = $True)][Alias('ToolName')][String]$Name,
231231
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][Alias('Ver')][String]$Version,
232-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture = ''
232+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture
233233
)
234234
Begin {
235235
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
@@ -250,7 +250,7 @@ Function Register-ToolCacheDirectory {
250250
If ($Architecture.Length -igt 0) {
251251
$InputObject.Architecture = $Architecture
252252
}
253-
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path "tool-cache\cache-directory.js" -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
253+
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'tool-cache\cache-directory.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
254254
If ($Null -ieq $ResultRaw) {
255255
Return
256256
}
@@ -284,7 +284,7 @@ Function Register-ToolCacheFile {
284284
[Parameter(Mandatory = $True, Position = 1, ValueFromPipelineByPropertyName = $True)][Alias('TargetFile')][String]$Target,
285285
[Parameter(Mandatory = $True, Position = 2, ValueFromPipelineByPropertyName = $True)][Alias('ToolName')][String]$Name,
286286
[Parameter(Mandatory = $True, Position = 3, ValueFromPipelineByPropertyName = $True)][Alias('Ver')][String]$Version,
287-
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture = ''
287+
[Parameter(ValueFromPipelineByPropertyName = $True)][Alias('Arch')][String]$Architecture
288288
)
289289
Begin {
290290
[Boolean]$NoOperation = $False# When the requirements are not fulfill, only stop this function but not others.
@@ -306,7 +306,7 @@ Function Register-ToolCacheFile {
306306
If ($Architecture.Length -igt 0) {
307307
$InputObject.Architecture = $Architecture
308308
}
309-
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path "tool-cache\cache-file.js" -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
309+
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'tool-cache\cache-file.js' -InputObject ([PSCustomObject]$InputObject | ConvertTo-Json -Depth 100 -Compress)
310310
If ($Null -ieq $ResultRaw) {
311311
Return
312312
}

hugoalh.GitHubActionsToolkit/module/utility.psm1

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ Function Add-SecretMask {
2020
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_add-githubactionssecretmask#Add-GitHubActionsSecretMask')]
2121
[OutputType([Void])]
2222
Param (
23-
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][Alias('Key', 'Secret', 'Token')][String]$Value,
23+
[Parameter(Mandatory = $True, Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)][AllowEmptyString()][AllowNull()][Alias('Key', 'Secret', 'Token')][String]$Value,
2424
[Alias('Chunk', 'Chunks', 'WithChunk')][Switch]$WithChunks
2525
)
2626
Begin {}
2727
Process {
2828
If ($Value.Length -igt 0) {
2929
Write-GitHubActionsCommand -Command 'add-mask' -Value $Value
30-
}
31-
If ($WithChunks.IsPresent) {
32-
[String[]]($Value -isplit '[\b\n\r\s\t_-]+') | ForEach-Object -Process {
33-
If ($_ -ine $Value -and $_.Length -ige 4) {
30+
If ($WithChunks.IsPresent) {
31+
[String[]]($Value -isplit '[\b\n\r\s\t_-]+') | Where-Object -FilterScript {
32+
Return ($_ -ine $Value -and $_.Length -ige 4)
33+
} | ForEach-Object -Process {
3434
Write-GitHubActionsCommand -Command 'add-mask' -Value $_
3535
}
3636
}
@@ -101,11 +101,10 @@ Function Get-WorkflowRunUri {
101101
[CmdletBinding(HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_get-githubactionsworkflowrunuri#Get-GitHubActionsWorkflowRunUri')]
102102
[OutputType([String])]
103103
Param ()
104-
If (!(Test-Environment)) {
105-
Write-Error -Message 'Unable to get GitHub Actions resources!' -Category 'ResourceUnavailable'
106-
Return
104+
If (Test-Environment) {
105+
Return "$Env:GITHUB_SERVER_URL/$Env:GITHUB_REPOSITORY/actions/runs/$Env:GITHUB_RUN_ID"
107106
}
108-
Return "$Env:GITHUB_SERVER_URL/$Env:GITHUB_REPOSITORY/actions/runs/$Env:GITHUB_RUN_ID"
107+
Write-Error -Message 'Unable to get GitHub Actions resources!' -Category 'ResourceUnavailable'
109108
}
110109
Set-Alias -Name 'Get-WorkflowRunUrl' -Value 'Get-WorkflowRunUri' -Option 'ReadOnly' -Scope 'Local'
111110
<#
@@ -185,7 +184,7 @@ Function Test-Environment {
185184
) {
186185
If ($Mandatory.IsPresent) {
187186
Write-GitHubActionsFail -Message $MandatoryMessage
188-
Return
187+
Throw
189188
}
190189
Return $False
191190
}

0 commit comments

Comments
 (0)