refactor(release): tier gitea uploads with archive priority, serial stability, and non-blocking error handling

This commit is contained in:
gitea committed 2026-09-02 16:05:49 +08:00
1 parent 7606cf7e31
commit b617b769ea
1 file changed
+39 -50
+39 -50
View File
@@ -74,6 +74,7 @@ jobs:
gh release upload "${TAG_NAME}" dist/bin/seal-use-* dist/bin/checksums.txt --repo "${GITHUB_REPOSITORY}" --clobber
- name: Publish Gitea Release
continue-on-error: true
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
GITEA_HOST: "https://git.ying-qing.cn"
@@ -100,33 +101,28 @@ jobs:
fi
if [ -z "$RELEASE_ID" ]; then
echo "::error::Failed to create or find the Gitea release."
exit 1
echo "::warning::Failed to create or find the Gitea release. Skipping Gitea publishing."
exit 0
fi
priority_files=(
# Tier 1: Compressed archives & checksums (Fast & high value, ~140MB total)
archive_files=(
"dist/bin/seal-use-darwin-arm64.tar.gz"
"dist/bin/seal-use-darwin-arm64"
"dist/bin/seal-use-darwin-x64.tar.gz"
"dist/bin/seal-use-darwin-x64"
)
remaining_files=(
"dist/bin/seal-use-linux-arm64.tar.gz"
"dist/bin/seal-use-linux-arm64"
"dist/bin/seal-use-linux-x64.tar.gz"
"dist/bin/seal-use-linux-x64"
"dist/bin/seal-use-windows-x64.zip"
"dist/bin/seal-use-windows-x64.exe"
"dist/bin/checksums.txt"
)
expected_files=("${priority_files[@]}" "${remaining_files[@]}")
for file in "${expected_files[@]}"; do
if [ ! -f "$file" ]; then
echo "::error::Expected release asset is missing locally: ${file}"
exit 1
fi
done
# Tier 2: Raw uncompressed executables (Large, ~360MB total)
raw_binary_files=(
"dist/bin/seal-use-darwin-arm64"
"dist/bin/seal-use-darwin-x64"
"dist/bin/seal-use-linux-arm64"
"dist/bin/seal-use-linux-x64"
"dist/bin/seal-use-windows-x64.exe"
)
release_json() {
curl -fsS \
@@ -153,7 +149,7 @@ jobs:
'[.assets[] | select(.name == $name and .size == $size) | .id][0] // empty')
if [ -n "$matching_id" ]; then
echo " [keep] ${filename} already exists with the expected size"
echo " [keep] ${filename} already exists with the expected size (${file_size} bytes)"
while IFS= read -r asset_id; do
[ -n "$asset_id" ] || continue
if [ "$asset_id" != "$matching_id" ]; then
@@ -161,7 +157,7 @@ jobs:
delete_asset "$asset_id"
fi
done < <(echo "$assets" | jq -r --arg name "$filename" '.assets[] | select(.name == $name) | .id')
return
return 0
fi
while IFS= read -r asset_id; do
@@ -171,20 +167,20 @@ jobs:
done < <(echo "$assets" | jq -r --arg name "$filename" '.assets[] | select(.name == $name) | .id')
response_file=$(mktemp)
echo " [start] uploading ${filename} (${file_size} bytes)"
echo " [start] uploading ${filename} (${file_size} bytes)..."
if ! http_code=$(curl -sS --fail-with-body \
--connect-timeout 10 \
--max-time 900 \
--connect-timeout 15 \
--max-time 600 \
--retry 3 \
--retry-delay 5 \
--retry-all-errors \
--retry-max-time 2700 \
--retry-max-time 1800 \
-o "$response_file" \
-w '%{http_code}' \
-X POST "${GITEA_HOST}/api/v1/repos/${GITEA_REPO}/releases/${RELEASE_ID}/assets?name=${filename}" \
-H "Authorization: token ${GITEA_TOKEN}" \
-F "attachment=@${file}"); then
echo "::error::Failed to upload ${filename} to Gitea."
echo "::warning::Failed to upload ${filename} to Gitea."
sed -n '1,20p' "$response_file"
rm -f "$response_file"
return 1
@@ -192,45 +188,38 @@ jobs:
rm -f "$response_file"
if [ "$http_code" != "201" ]; then
echo "::error::Unexpected Gitea upload status for ${filename}: HTTP ${http_code}"
echo "::warning::Unexpected Gitea upload status for ${filename}: HTTP ${http_code}"
return 1
fi
echo " [done] ${filename} -> HTTP ${http_code}"
return 0
}
echo "==> Uploading macOS assets first (Apple Silicon archive has highest priority)..."
for file in "${priority_files[@]}"; do
upload_asset "$file"
echo "==> Step 1: Uploading core compressed archives & checksums..."
for file in "${archive_files[@]}"; do
if [ -f "$file" ]; then
upload_asset "$file" || true
fi
done
echo "==> Uploading remaining assets with at most 2 concurrent transfers..."
for ((index=0; index<${#remaining_files[@]}; index+=2)); do
pids=()
for ((offset=0; offset<2 && index+offset<${#remaining_files[@]}; offset++)); do
upload_asset "${remaining_files[index+offset]}" &
pids+=("$!")
done
for pid in "${pids[@]}"; do
wait "$pid"
done
echo "==> Step 2: Uploading uncompressed standalone binaries..."
for file in "${raw_binary_files[@]}"; do
if [ -f "$file" ]; then
upload_asset "$file" || true
fi
done
echo "==> Verifying the Gitea release asset manifest..."
echo "==> Verifying Gitea release asset manifest..."
final_release=$(release_json)
verification_failed=false
for file in "${expected_files[@]}"; do
for file in "${archive_files[@]}" "${raw_binary_files[@]}"; do
filename=$(basename "$file")
file_size=$(wc -c < "$file" | tr -d ' ')
matching_count=$(echo "$final_release" | jq -r --arg name "$filename" --argjson size "$file_size" \
'[.assets[] | select(.name == $name and .size == $size)] | length')
total_count=$(echo "$final_release" | jq -r --arg name "$filename" \
'[.assets[] | select(.name == $name)] | length')
if [ "$matching_count" != "1" ] || [ "$total_count" != "1" ]; then
echo "::error::Gitea asset verification failed for ${filename}: matching=${matching_count}, total=${total_count}"
verification_failed=true
if [ "$matching_count" = "1" ]; then
echo " ✓ ${filename} ready"
else
echo " ⚠️ ${filename} not yet synchronized"
fi
done
if [ "$verification_failed" = "true" ]; then
exit 1
fi
echo "✓ Successfully published and verified all Gitea release assets!"
echo "✓ Gitea publishing step completed!"