Skip to content

Commit 53622fc

Browse files
committed
20220629D
1 parent 42a5eec commit 53622fc

File tree

1 file changed

+3
-66
lines changed

1 file changed

+3
-66
lines changed

hugoalh.GitHubActionsToolkit/module/artifact.psm1

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -44,89 +44,32 @@ Function Export-Artifact {
4444
Return (Write-Error -Message 'Unable to get GitHub Actions artifact resources!' -Category 'ResourceUnavailable')
4545
Break# This is the best way to early terminate this function without terminate caller/invoker process.
4646
}
47-
<# Disable, not a good method.
4847
[String]$BaseRootRegularExpression = "^$([RegEx]::Escape((Resolve-Path -LiteralPath $BaseRoot)))"
49-
[String[]]$PathsValid = @()
50-
[String[]]$PathsInvalid = @()
51-
#>
5248
[String[]]$PathsProceed = @()
5349
}
5450
Process {
5551
Switch ($PSCmdlet.ParameterSetName) {
5652
'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-
#>
7853
$PathsProceed += ($LiteralPath | ForEach-Object -Process {
79-
Return [WildcardPattern]::Escape($_)
54+
Return ([System.IO.Path]::IsPathRooted($_) ? $_ : (Join-Path -Path $BaseRoot -ChildPath $_))
8055
})
8156
}
8257
'Path' {
83-
<# Disable, not a good method.
8458
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')
10260
}
103-
#>
104-
$PathsProceed += $Path
10561
}
10662
}
10763
}
10864
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-
#>
11965
If ($PathsProceed.Count -ieq 0) {
12066
Return (Write-Error -Message 'No path is defined!' -Category 'NotSpecified')
12167
}
12268
[Hashtable]$InputObject = @{
12369
Name = $Name
124-
<# Disable, not a good method.
125-
Path = ($PathsValid | ForEach-Object -Process {
70+
Path = ($PathsProceed | ForEach-Object -Process {
12671
Return ($_ -ireplace $BaseRootRegularExpression, '' -ireplace '\\', '/')
12772
})
128-
#>
129-
Path = $PathsProceed
13073
BaseRoot = $BaseRoot
13174
IgnoreIssuePaths = $IgnoreIssuePaths.IsPresent
13275
}
@@ -137,12 +80,6 @@ Function Export-Artifact {
13780
If ($ResultRaw -ieq $False) {
13881
Return
13982
}
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-
#>
14683
Return ($ResultRaw | ConvertFrom-Json -Depth 100)
14784
}
14885
}

0 commit comments

Comments
 (0)