ci: use bounded runspaces for artifact uploads [CI SKIP]
This commit is contained in:
1 parent
3bf12ec73d
commit
fae8c45c90
1 file changed
+51
-14
@@ -111,24 +111,61 @@ consumer install.
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$uploadFiles.ToArray() | ForEach-Object -Parallel {
|
$uploadScript = @'
|
||||||
$file = $_
|
param([string]$File, [string]$Base, [string]$PackageVersion, [string]$Netrc)
|
||||||
$name = Split-Path -Leaf $file
|
$ErrorActionPreference = 'Stop'
|
||||||
$url = "$using:giteaBase/api/packages/justme/generic/monitor-node/$using:version/$name"
|
$name = [IO.Path]::GetFileName($File)
|
||||||
$status = & curl.exe --silent --show-error --retry 3 --netrc-file $using:netrc --upload-file $file --output NUL --write-out '%{http_code}' $url
|
$url = "$Base/api/packages/justme/generic/monitor-node/$PackageVersion/$name"
|
||||||
if ($LASTEXITCODE -ne 0) {
|
$status = & curl.exe --silent --show-error --retry 3 --netrc-file $Netrc --upload-file $File --output NUL --write-out '%{http_code}' $url
|
||||||
throw "Gitea package upload failed for $name."
|
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() })
|
||||||
}
|
}
|
||||||
if ($status -match '^2') {
|
|
||||||
Write-Output "uploaded Gitea package $name"
|
$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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elseif ($status -eq '409') {
|
if ($uploadErrors.Count -gt 0) {
|
||||||
Write-Output "Gitea package $name already exists; reusing the existing release file"
|
throw "One or more Gitea package uploads failed:`n$($uploadErrors -join "`n")"
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
throw "Gitea package upload failed for $name (HTTP $status)."
|
finally {
|
||||||
|
foreach ($pending in $pendingUploads) {
|
||||||
|
$pending.PowerShell.Dispose()
|
||||||
}
|
}
|
||||||
} -ThrottleLimit 8
|
$runspacePool.Close()
|
||||||
|
$runspacePool.Dispose()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
Remove-Item -LiteralPath $netrc -Force -ErrorAction SilentlyContinue
|
Remove-Item -LiteralPath $netrc -Force -ErrorAction SilentlyContinue
|
||||||
|
|||||||
Reference in new issue
Block a user