@@ -44,89 +44,32 @@ Function Export-Artifact {
44
44
Return (Write-Error - Message ' Unable to get GitHub Actions artifact resources!' - Category ' ResourceUnavailable' )
45
45
Break # This is the best way to early terminate this function without terminate caller/invoker process.
46
46
}
47
- <# Disable, not a good method.
48
47
[String ]$BaseRootRegularExpression = " ^$ ( [RegEx ]::Escape((Resolve-Path - LiteralPath $BaseRoot ))) "
49
- [String[]]$PathsValid = @()
50
- [String[]]$PathsInvalid = @()
51
- #>
52
48
[String []]$PathsProceed = @ ()
53
49
}
54
50
Process {
55
51
Switch ($PSCmdlet.ParameterSetName ) {
56
52
' LiteralPath' {
57
- <# Disable, not a good method
58
- ForEach ($ItemLiteralPath In $LiteralPath) {
59
- Try {
60
- ForEach ($ItemResolve In [String[]](Resolve-Path -LiteralPath ([System.IO.Path]::IsPathRooted($ItemLiteralPath) ? $ItemLiteralPath : (Join-Path -Path $BaseRoot -ChildPath $ItemLiteralPath)) -ErrorAction 'SilentlyContinue')) {
61
- If (!(Test-Path -LiteralPath $ItemResolve -PathType 'Leaf')) {
62
- Continue
63
- }
64
- If (
65
- $ItemResolve -inotmatch $BaseRootRegularExpression -or
66
- !(Test-ArtifactPath -InputObject $ItemResolve)
67
- ) {
68
- $PathsInvalid += $ItemResolve
69
- Continue
70
- }
71
- $PathsValid += $ItemResolve
72
- }
73
- } Catch {
74
- $PathsInvalid += $ItemLiteralPath
75
- }
76
- }
77
- #>
78
53
$PathsProceed += ($LiteralPath | ForEach-Object - Process {
79
- Return [ WildcardPattern ]::Escape ($_ )
54
+ Return ([ System.IO.Path ]::IsPathRooted ($_ ) ? $_ : ( Join-Path - Path $BaseRoot - ChildPath $_ ) )
80
55
})
81
56
}
82
57
' Path' {
83
- <# Disable, not a good method.
84
58
ForEach ($ItemPath In $Path ) {
85
- Try {
86
- ForEach ($ItemResolve In [String[]](Resolve-Path -Path ([System.IO.Path]::IsPathRooted($ItemPath) ? $ItemPath : (Join-Path -Path $BaseRoot -ChildPath $ItemPath)) -ErrorAction 'SilentlyContinue')) {
87
- If (!(Test-Path -LiteralPath $ItemResolve -PathType 'Leaf')) {
88
- Continue
89
- }
90
- If (
91
- $ItemResolve -inotmatch $BaseRootRegularExpression -or
92
- !(Test-ArtifactPath -InputObject $ItemResolve)
93
- ) {
94
- $PathsInvalid += $ItemResolve
95
- Continue
96
- }
97
- $PathsValid += $ItemResolve
98
- }
99
- } Catch {
100
- $PathsInvalid += $ItemPath
101
- }
59
+ $PathsProceed += [String []](Resolve-Path - Path ([System.IO.Path ]::IsPathRooted($ItemPath ) ? $ItemPath : (Join-Path - Path $BaseRoot - ChildPath $ItemPath )) - ErrorAction ' SilentlyContinue' )
102
60
}
103
- #>
104
- $PathsProceed += $Path
105
61
}
106
62
}
107
63
}
108
64
End {
109
- <# Disable, not a good method.
110
- If ($PathsInvalid.Count -igt 0 -and !$IgnoreIssuePaths.IsPresent) {
111
- Return ($PathsInvalid | ForEach-Object -Process {
112
- Return (Write-Error -Message "``$_`` is not an exist and valid file path!" -Category 'SyntaxError')
113
- })
114
- }
115
- If ($PathsValid.Count -ieq 0) {
116
- Return (Write-Error -Message 'No valid file path is defined!' -Category 'NotSpecified')
117
- }
118
- #>
119
65
If ($PathsProceed.Count -ieq 0 ) {
120
66
Return (Write-Error - Message ' No path is defined!' - Category ' NotSpecified' )
121
67
}
122
68
[Hashtable ]$InputObject = @ {
123
69
Name = $Name
124
- <# Disable, not a good method.
125
- Path = ($PathsValid | ForEach-Object -Process {
70
+ Path = ($PathsProceed | ForEach-Object - Process {
126
71
Return ($_ -ireplace $BaseRootRegularExpression , ' ' -ireplace ' \\' , ' /' )
127
72
})
128
- #>
129
- Path = $PathsProceed
130
73
BaseRoot = $BaseRoot
131
74
IgnoreIssuePaths = $IgnoreIssuePaths.IsPresent
132
75
}
@@ -137,12 +80,6 @@ Function Export-Artifact {
137
80
If ($ResultRaw -ieq $False ) {
138
81
Return
139
82
}
140
- <# Disable, not a good method.
141
- [Hashtable]$Result = ($ResultRaw | ConvertFrom-Json -AsHashtable -Depth 100)
142
- $Result.FailedItem += $PathsInvalid
143
- $Result.FailedItems += $PathsInvalid
144
- Return [PSCustomObject]$Result
145
- #>
146
83
Return ($ResultRaw | ConvertFrom-Json - Depth 100 )
147
84
}
148
85
}
0 commit comments