Skip to content

Commit b473b5b

Browse files
committed
20220630F
1 parent b79db72 commit b473b5b

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ Function Export-Artifact {
6767
}
6868
[Hashtable]$InputObject = @{
6969
Name = $Name
70-
Path = ($PathsProceed | ForEach-Object -Process {
71-
Return ($_ -ireplace $BaseRootRegularExpression, '' -ireplace '\\', '/')
72-
})
70+
Path = $PathsProceed
7371
BaseRoot = $BaseRoot
7472
ContinueOnIssue = $ContinueOnIssue.IsPresent
7573
}
@@ -92,20 +90,22 @@ Import artifact that shared data from previous job in the same workflow.
9290
.PARAMETER Name
9391
Artifact name.
9492
.PARAMETER CreateSubfolder
95-
Create a subfolder with artifact name and put data into here; When parameter `Name` has multiple values, this parameter will ignore.
93+
Create a subfolder with artifact name and put data into here.
9694
.PARAMETER All
9795
Import all artifacts that shared data from previous job in the same workflow; Always create subfolder.
9896
.PARAMETER Destination
9997
Artifact destination.
10098
.OUTPUTS
99+
[PSCustomObject] Imported artifact's metadata.
101100
[PSCustomObject[]] Imported artifacts' metadata.
102101
#>
103102
Function Import-Artifact {
104-
[CmdletBinding(DefaultParameterSetName = 'Select', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_import-githubactionsartifact#Import-GitHubActionsArtifact')]
105-
[OutputType([PSCustomObject[]])]
103+
[CmdletBinding(DefaultParameterSetName = 'Single', HelpUri = 'https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_import-githubactionsartifact#Import-GitHubActionsArtifact')]
104+
[OutputType([PSCustomObject[]], ParameterSetName = 'All')]
105+
[OutputType([PSCustomObject], ParameterSetName = 'Single')]
106106
Param (
107-
[Parameter(Mandatory = $True, ParameterSetName = 'Select', 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 = 'Select')][Switch]$CreateSubfolder,
107+
[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,
109109
[Parameter(Mandatory = $True, ParameterSetName = 'All')][Switch]$All,
110110
[Alias('Dest', 'Target')][String]$Destination = $Env:GITHUB_WORKSPACE
111111
)
@@ -114,7 +114,6 @@ Function Import-Artifact {
114114
Return (Write-Error -Message 'Unable to get GitHub Actions artifact resources!' -Category 'ResourceUnavailable')
115115
Break# This is the best way to early terminate this function without terminate caller/invoker process.
116116
}
117-
[PSCustomObject[]]$OutputObject = @()
118117
}
119118
Process {
120119
Switch ($PSCmdlet.ParameterSetName) {
@@ -125,26 +124,22 @@ Function Import-Artifact {
125124
If ($ResultRaw -ieq $False) {
126125
Continue
127126
}
128-
$OutputObject = ($ResultRaw | ConvertFrom-Json -Depth 100)
127+
Return ($ResultRaw | ConvertFrom-Json -Depth 100)
129128
}
130-
'Select' {
131-
ForEach ($Item In $Name) {
132-
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\download.js' -InputObject ([PSCustomObject]@{
133-
Name = $Item
134-
Destination = $Destination
135-
CreateSubfolder = ($Name.Count -igt 1) ? $True : $CreateSubfolder.IsPresent
136-
} | ConvertTo-Json -Depth 100 -Compress)
137-
If ($ResultRaw -ieq $False) {
138-
Continue
139-
}
140-
$OutputObject += ($ResultRaw | ConvertFrom-Json -Depth 100)
129+
'Single' {
130+
$ResultRaw = Invoke-GitHubActionsNodeJsWrapper -Path 'artifact\download.js' -InputObject ([PSCustomObject]@{
131+
Name = $Name
132+
Destination = $Destination
133+
CreateSubfolder = $CreateSubfolder.IsPresent
134+
} | ConvertTo-Json -Depth 100 -Compress)
135+
If ($ResultRaw -ieq $False) {
136+
Return
141137
}
138+
Return ($ResultRaw | ConvertFrom-Json -Depth 100)
142139
}
143140
}
144141
}
145-
End {
146-
Return $OutputObject
147-
}
142+
End {}
148143
}
149144
Set-Alias -Name 'Restore-Artifact' -Value 'Import-Artifact' -Option 'ReadOnly' -Scope 'Local'
150145
<#

0 commit comments

Comments
 (0)