ci: upload release artifacts concurrently [CI SKIP]

This commit is contained in:
justme committed 2026-10-04 13:05:17 -07:00
1 parent a9ee4ec34c
commit 3bf12ec73d
2 files changed
+47 -32

No files matched your search

+22 -20
View File
@@ -33,24 +33,6 @@ function New-TarGzArchive([string]$SourceDirectory, [string]$ArchivePath, [strin
} }
} }
function Upload-Package([string]$File) {
$name = Split-Path -Leaf $File
$url = "$giteaBase/api/packages/justme/generic/monitor-node/$version/$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."
}
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 {
throw "Gitea package upload failed for $name (HTTP $status)."
}
}
try { try {
$targets = @( $targets = @(
@{ Rid = 'linux-x64'; Os = 'linux'; Arch = 'amd64'; Windows = $false }, @{ Rid = 'linux-x64'; Os = 'linux'; Arch = 'amd64'; Windows = $false },
@@ -64,6 +46,7 @@ try {
) )
$packageRoot = Join-Path $root '.release\packages' $packageRoot = Join-Path $root '.release\packages'
$null = New-Item -ItemType Directory -Force -Path $packageRoot $null = New-Item -ItemType Directory -Force -Path $packageRoot
$uploadFiles = [System.Collections.Generic.List[string]]::new()
foreach ($target in $targets) { foreach ($target in $targets) {
$agentDirectory = Join-Path $root ".release\publish\$($target.Rid)\agent" $agentDirectory = Join-Path $root ".release\publish\$($target.Rid)\agent"
$probeDirectory = Join-Path $root ".release\publish\$($target.Rid)\probe" $probeDirectory = Join-Path $root ".release\publish\$($target.Rid)\probe"
@@ -123,10 +106,29 @@ consumer install.
$checksum = "$hash $archiveName`n" $checksum = "$hash $archiveName`n"
$checksumPath = "$archive.sha256" $checksumPath = "$archive.sha256"
[IO.File]::WriteAllText($checksumPath, $checksum, [Text.UTF8Encoding]::new($false)) [IO.File]::WriteAllText($checksumPath, $checksum, [Text.UTF8Encoding]::new($false))
Upload-Package $archive [void]$uploadFiles.Add($archive)
Upload-Package $checksumPath [void]$uploadFiles.Add($checksumPath)
} }
} }
$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 {
throw "Gitea package upload failed for $name (HTTP $status)."
}
} -ThrottleLimit 8
} }
finally { finally {
Remove-Item -LiteralPath $netrc -Force -ErrorAction SilentlyContinue Remove-Item -LiteralPath $netrc -Force -ErrorAction SilentlyContinue
+25 -12
View File
@@ -77,25 +77,38 @@ assets=(
"monitor-probe-v$version-windows-amd64.zip" "monitor-probe-v$version-windows-amd64.zip"
"monitor-probe-v$version-windows-arm64.zip" "monitor-probe-v$version-windows-arm64.zip"
) )
upload_release_asset() {
local name="$1" file="$tmp/$1" upload_response="$tmp/$1.upload.json" status
curl --fail-with-body --silent --show-error --retry 3 --netrc-file "$netrc" \
"$gitea_base/api/packages/justme/generic/monitor-node/$version/$name" -o "$file"
status="$(curl --silent --show-error --retry 3 --netrc-file "$netrc" \
--request POST --header 'Content-Type: application/octet-stream' --data-binary "@$file" \
--output "$upload_response" --write-out '%{http_code}' \
"$api/releases/$release_id/assets?name=$name")"
case "$status" in
2*) echo "attached $name" ;;
*) echo "Gitea Release asset upload failed for $name (HTTP $status)" >&2; cat "$upload_response" >&2; return 1 ;;
esac
}
pids=()
for archive in "${assets[@]}"; do for archive in "${assets[@]}"; do
for name in "$archive" "$archive.sha256"; do for name in "$archive" "$archive.sha256"; do
if grep -Eq "\"name\"[[:space:]]*:[[:space:]]*\"$name\"" "$assets_json"; then if grep -Eq "\"name\"[[:space:]]*:[[:space:]]*\"$name\"" "$assets_json"; then
echo "release asset $name already exists; keeping the existing asset" echo "release asset $name already exists; keeping the existing asset"
continue continue
fi fi
file="$tmp/$name" upload_release_asset "$name" &
upload_response="$tmp/upload.json" pids+=("$!")
curl --fail-with-body --silent --show-error --retry 3 --netrc-file "$netrc" \ if ((${#pids[@]} >= 8)); then
"$gitea_base/api/packages/justme/generic/monitor-node/$version/$name" -o "$file" wait "${pids[0]}"
status="$(curl --silent --show-error --retry 3 --netrc-file "$netrc" \ pids=("${pids[@]:1}")
--request POST --header 'Content-Type: application/octet-stream' --data-binary "@$file" \ fi
--output "$upload_response" --write-out '%{http_code}' \
"$api/releases/$release_id/assets?name=$name")"
case "$status" in
2*) echo "attached $name" ;;
*) echo "Gitea Release asset upload failed for $name (HTTP $status)" >&2; cat "$upload_response" >&2; exit 1 ;;
esac
done done
done done
for pid in "${pids[@]}"; do
wait "$pid"
done
echo "published Gitea Release $tag: https://git.oeo.one/justme/MyMonitor/releases/tag/$tag" echo "published Gitea Release $tag: https://git.oeo.one/justme/MyMonitor/releases/tag/$tag"