ci: use bounded runspaces for artifact uploads [CI SKIP]
This commit is contained in:
1 parent
3bf12ec73d
commit
fae8c45c90
1 file changed
+53
-16
@@ -111,24 +111,61 @@ consumer install.
|
||||
}
|
||||
}
|
||||
|
||||
$uploadFiles.ToArray() | ForEach-Object -Parallel {
|
||||
$file = $_
|
||||
$name = Split-Path -Leaf $file
|
||||
$url = "$using:giteaBase/api/packages/justme/generic/monitor-node/$using:version/$name"
|
||||
$status = & curl.exe --silent --show-error --retry 3 --netrc-file $using:netrc --upload-file $file --output NUL --write-out '%{http_code}' $url
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Gitea package upload failed for $name."
|
||||
}
|
||||
if ($status -match '^2') {
|
||||
Write-Output "uploaded Gitea package $name"
|
||||
}
|
||||
elseif ($status -eq '409') {
|
||||
Write-Output "Gitea package $name already exists; reusing the existing release file"
|
||||
}
|
||||
else {
|
||||
$uploadScript = @'
|
||||
param([string]$File, [string]$Base, [string]$PackageVersion, [string]$Netrc)
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$name = [IO.Path]::GetFileName($File)
|
||||
$url = "$Base/api/packages/justme/generic/monitor-node/$PackageVersion/$name"
|
||||
$status = & curl.exe --silent --show-error --retry 3 --netrc-file $Netrc --upload-file $File --output NUL --write-out '%{http_code}' $url
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Gitea package upload failed for $name (curl exit $LASTEXITCODE)."
|
||||
}
|
||||
if ($status -match '^2') {
|
||||
"uploaded Gitea package $name"
|
||||
}
|
||||
elseif ($status -eq '409') {
|
||||
"Gitea package $name already exists; reusing the existing release file"
|
||||
}
|
||||
else {
|
||||
throw "Gitea package upload failed for $name (HTTP $status)."
|
||||
}
|
||||
'@
|
||||
$runspacePool = [RunspaceFactory]::CreateRunspacePool(1, 8)
|
||||
$runspacePool.Open()
|
||||
$pendingUploads = [System.Collections.Generic.List[object]]::new()
|
||||
try {
|
||||
foreach ($file in $uploadFiles) {
|
||||
$powerShell = [PowerShell]::Create()
|
||||
$powerShell.RunspacePool = $runspacePool
|
||||
[void]$powerShell.AddScript($uploadScript).AddArgument($file).AddArgument($giteaBase).AddArgument($version).AddArgument($netrc)
|
||||
$pendingUploads.Add([pscustomobject]@{ PowerShell = $powerShell; Handle = $powerShell.BeginInvoke() })
|
||||
}
|
||||
|
||||
$uploadErrors = [System.Collections.Generic.List[string]]::new()
|
||||
foreach ($pending in $pendingUploads) {
|
||||
try {
|
||||
foreach ($message in $pending.PowerShell.EndInvoke($pending.Handle)) {
|
||||
Write-Output $message
|
||||
}
|
||||
foreach ($errorRecord in $pending.PowerShell.Streams.Error) {
|
||||
$uploadErrors.Add($errorRecord.ToString())
|
||||
}
|
||||
}
|
||||
catch {
|
||||
$uploadErrors.Add($_.Exception.Message)
|
||||
}
|
||||
}
|
||||
if ($uploadErrors.Count -gt 0) {
|
||||
throw "One or more Gitea package uploads failed:`n$($uploadErrors -join "`n")"
|
||||
}
|
||||
}
|
||||
finally {
|
||||
foreach ($pending in $pendingUploads) {
|
||||
$pending.PowerShell.Dispose()
|
||||
}
|
||||
$runspacePool.Close()
|
||||
$runspacePool.Dispose()
|
||||
}
|
||||
} -ThrottleLimit 8
|
||||
}
|
||||
finally {
|
||||
Remove-Item -LiteralPath $netrc -Force -ErrorAction SilentlyContinue
|
||||
|
||||
Reference in new issue
Block a user