@@ -33,29 +33,31 @@ Function Export-Artifact {
33
33
}, ErrorMessage = ' `{0}` is not a valid GitHub Actions artifact name!' )][String ]$Name ,
34
34
[Parameter (Mandatory = $True , ParameterSetName = ' Path' , Position = 1 , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )][SupportsWildcards ()][Alias (' File' , ' Files' , ' Paths' )][String []]$Path ,
35
35
[Parameter (Mandatory = $True , ParameterSetName = ' LiteralPath' , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )][Alias (' LiteralFile' , ' LiteralFiles' , ' LiteralPaths' , ' LP' , ' PSPath' , ' PSPaths' )][String []]$LiteralPath ,
36
- [Alias (' Root' )][String ]$BaseRoot = $Env: GITHUB_WORKSPACE ,
36
+ [ValidateScript ({
37
+ Return ([System.IO.Path ]::IsPathRooted($_ ) -and (Test-Path - LiteralPath $_ - PathType ' Container' ))
38
+ }, ErrorMessage = ' `{0}` is not an exist and valid GitHub Actions artifact base root!' )][Alias (' Root' )][String ]$BaseRoot = $Env: GITHUB_WORKSPACE ,
37
39
[Alias (' ContinueOnError' , ' ContinueOnIssue' , ' ContinueOnIssues' , ' IgnoreIssuePath' )][Switch ]$IgnoreIssuePaths ,
38
40
[ValidateRange (1 , 90 )][AllowNull ()][Alias (' RetentionDay' )][Byte ]$RetentionTime = $Null
39
41
)
40
42
Begin {
41
- If (
42
- $Null -ieq $BaseRoot -or
43
- ! [System.IO.Path ]::IsPathRooted($BaseRoot ) -or
44
- ! (Test-Path - LiteralPath $BaseRoot - PathType ' Container' )
45
- ) {
46
- Return (Write-Error - Message " `` $BaseRoot `` is not an exist and valid GitHub Actions artifact base root!" - Category ' SyntaxError' )
43
+ If (! (Test-GitHubActionsEnvironment - Artifact)) {
44
+ Return (Write-Error - Message ' Unable to get GitHub Actions artifact resources!' - Category ' ResourceUnavailable' )
47
45
Break # This is the best way to early terminate this function without terminate caller/invoker process.
48
46
}
47
+ <# Disable, not a good method.
49
48
[String]$BaseRootRegularExpression = "^$([RegEx]::Escape((Resolve-Path -LiteralPath $BaseRoot)))"
50
49
[String[]]$PathsValid = @()
51
50
[String[]]$PathsInvalid = @()
51
+ #>
52
+ [String []]$PathsProceed = @ ()
52
53
}
53
54
Process {
54
55
Switch ($PSCmdlet.ParameterSetName ) {
55
56
' Path' {
57
+ <# Disable, not a good method.
56
58
ForEach ($ItemPath In $Path) {
57
59
Try {
58
- ForEach ($ItemResolve In [String []](Resolve-Path - Path ([System.IO.Path ]::IsPathRooted($ItemPath ) ? $ItemPath : (Join-Path - Path $BaseRoot - ChildPath $ItemPath )))) {
60
+ ForEach ($ItemResolve In [String[]](Resolve-Path -Path ([System.IO.Path]::IsPathRooted($ItemPath) ? $ItemPath : (Join-Path -Path $BaseRoot -ChildPath $ItemPath)) -ErrorAction 'SilentlyContinue' )) {
59
61
If (!(Test-Path -LiteralPath $ItemResolve -PathType 'Leaf')) {
60
62
Continue
61
63
}
@@ -72,11 +74,14 @@ Function Export-Artifact {
72
74
$PathsInvalid += $ItemPath
73
75
}
74
76
}
77
+ #>
78
+ $PathsProceed += $Path
75
79
}
76
80
' LiteralPath' {
81
+ <# Disable, not a good method
77
82
ForEach ($ItemLiteralPath In $LiteralPath) {
78
83
Try {
79
- ForEach ($ItemResolve In [String []](Resolve-Path - LiteralPath ([System.IO.Path ]::IsPathRooted($ItemLiteralPath ) ? $ItemLiteralPath : (Join-Path - Path $BaseRoot - ChildPath $ItemLiteralPath )))) {
84
+ ForEach ($ItemResolve In [String[]](Resolve-Path -LiteralPath ([System.IO.Path]::IsPathRooted($ItemLiteralPath) ? $ItemLiteralPath : (Join-Path -Path $BaseRoot -ChildPath $ItemLiteralPath)) -ErrorAction 'SilentlyContinue' )) {
80
85
If (!(Test-Path -LiteralPath $ItemResolve -PathType 'Leaf')) {
81
86
Continue
82
87
}
@@ -93,26 +98,35 @@ Function Export-Artifact {
93
98
$PathsInvalid += $ItemLiteralPath
94
99
}
95
100
}
101
+ #>
102
+ $PathsProceed += ($LiteralPath | ForEach-Object - Process {
103
+ Return [WildcardPattern ]::Escape($_ )
104
+ })
96
105
}
97
106
}
98
107
}
99
108
End {
100
- If (! (Test-GitHubActionsEnvironment - Artifact)) {
101
- Return (Write-Error - Message ' Unable to get GitHub Actions artifact resources!' - Category ' ResourceUnavailable' )
102
- }
109
+ <# Disable, not a good method.
103
110
If ($PathsInvalid.Count -igt 0 -and !$IgnoreIssuePaths.IsPresent) {
104
111
Return ($PathsInvalid | ForEach-Object -Process {
105
112
Return (Write-Error -Message "``$_`` is not an exist and valid file path!" -Category 'SyntaxError')
106
113
})
107
114
}
108
115
If ($PathsValid.Count -ieq 0) {
109
- Return (Write-Error - Message ' No valid path is defined!' - Category ' NotSpecified' )
116
+ Return (Write-Error -Message 'No valid file path is defined!' -Category 'NotSpecified')
117
+ }
118
+ #>
119
+ If ($PathsProceed.Count -ieq 0 ) {
120
+ Return (Write-Error - Message ' No path is defined!' - Category ' NotSpecified' )
110
121
}
111
122
[Hashtable ]$InputObject = @ {
112
123
Name = $Name
124
+ <# Disable, not a good method.
113
125
Path = ($PathsValid | ForEach-Object -Process {
114
126
Return ($_ -ireplace $BaseRootRegularExpression, '' -ireplace '\\', '/')
115
127
})
128
+ #>
129
+ Path = $PathsProceed
116
130
BaseRoot = $BaseRoot
117
131
IgnoreIssuePaths = $IgnoreIssuePaths.IsPresent
118
132
}
@@ -123,10 +137,13 @@ Function Export-Artifact {
123
137
If ($ResultRaw -ieq $False ) {
124
138
Return
125
139
}
140
+ <# Disable, not a good method.
126
141
[Hashtable]$Result = ($ResultRaw | ConvertFrom-Json -AsHashtable -Depth 100)
127
142
$Result.FailedItem += $PathsInvalid
128
143
$Result.FailedItems += $PathsInvalid
129
144
Return [PSCustomObject]$Result
145
+ #>
146
+ Return ($ResultRaw | ConvertFrom-Json - Depth 100 )
130
147
}
131
148
}
132
149
Set-Alias - Name ' Save-Artifact' - Value ' Export-Artifact' - Option ' ReadOnly' - Scope ' Local'
@@ -150,7 +167,9 @@ Function Import-Artifact {
150
167
[CmdletBinding (DefaultParameterSetName = ' Select' , HelpUri = ' https://github.com/hugoalh-studio/ghactions-toolkit-powershell/wiki/api_function_import-githubactionsartifact#Import-GitHubActionsArtifact' )]
151
168
[OutputType ([PSCustomObject []])]
152
169
Param (
153
- [Parameter (Mandatory = $True , ParameterSetName = ' Select' , Position = 0 , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )][String []]$Name ,
170
+ [Parameter (Mandatory = $True , ParameterSetName = ' Select' , Position = 0 , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )][ValidateScript ({
171
+ Return (Test-ArtifactName - InputObject $_ )
172
+ }, ErrorMessage = ' `{0}` is not a valid GitHub Actions artifact name!' )][String []]$Name ,
154
173
[Parameter (ParameterSetName = ' Select' )][Switch ]$CreateSubfolder ,
155
174
[Parameter (Mandatory = $True , ParameterSetName = ' All' )][Switch ]$All ,
156
175
[String ]$Destination = $Env: GITHUB_WORKSPACE
0 commit comments