|
|
@@ -114,10 +114,6 @@ runs:
|
|
|
local max_attempts=3
|
|
|
local timeout_duration="10m"
|
|
|
|
|
|
- if [ "$TAG_NAME" != "bazel-cache" ]; then
|
|
|
- timeout_duration="30m"
|
|
|
- fi
|
|
|
-
|
|
|
for ((i=1; i<=max_attempts; i++)); do
|
|
|
echo " Attempt $i for $file..."
|
|
|
|
|
|
@@ -141,19 +137,50 @@ runs:
|
|
|
return 1
|
|
|
}
|
|
|
|
|
|
+ # Fetch existing assets to clean up stale entries
|
|
|
+ ASSETS_URL="https://github.com/${TARGET_REPO}/releases/expanded_assets/$TAG_NAME"
|
|
|
+ HTTP_RESPONSE=$(curl -sL -A "Mozilla/5.0" -w "%{http_code}" "$ASSETS_URL" -o assets.html || echo "404")
|
|
|
+ if [ "$HTTP_RESPONSE" -eq 200 ]; then
|
|
|
+ ALL_ASSETS=$(grep -oP "download/$TAG_NAME/\K[^\"' ]+" assets.html | sort || echo "")
|
|
|
+ else
|
|
|
+ ALL_ASSETS=""
|
|
|
+ fi
|
|
|
+ rm -f assets.html
|
|
|
+
|
|
|
chunk_size="1500M"
|
|
|
split_required=false
|
|
|
|
|
|
- if [ "$TAG_NAME" != "bazel-cache" ]; then
|
|
|
- chunk_size="250M"
|
|
|
- split_required=true
|
|
|
- elif [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
|
|
|
+ if [ "$FILE_SIZE" -gt "$MAX_SIZE" ]; then
|
|
|
split_required=true
|
|
|
fi
|
|
|
|
|
|
if [ "$split_required" = "true" ]; then
|
|
|
echo "⚠ Splitting into ${chunk_size} chunks..."
|
|
|
split -b "$chunk_size" -a 2 "$FILENAME" "${FILENAME}.part"
|
|
|
+
|
|
|
+ NEW_PARTS=(${FILENAME}.part*)
|
|
|
+ NEW_PARTS_COUNT=${#NEW_PARTS[@]}
|
|
|
+
|
|
|
+ # Remove old single-file asset if switching to split parts
|
|
|
+ if echo "$ALL_ASSETS" | grep -xF "${FILENAME}" >/dev/null 2>&1; then
|
|
|
+ echo "Removing old single asset to make way for split parts: ${FILENAME}"
|
|
|
+ gh release delete-asset "$TAG_NAME" "${FILENAME}" --repo "$TARGET_REPO" -y || true
|
|
|
+ fi
|
|
|
+
|
|
|
+ # Clean up excess trailing parts from previous builds
|
|
|
+ OLD_PARTS=$(echo "$ALL_ASSETS" | grep -F "${FILENAME}.part" || echo "")
|
|
|
+ if [ -n "$OLD_PARTS" ]; then
|
|
|
+ OLD_PARTS_COUNT=$(echo "$OLD_PARTS" | wc -l)
|
|
|
+ if [ "$OLD_PARTS_COUNT" -gt "$NEW_PARTS_COUNT" ]; then
|
|
|
+ echo "Old build had $OLD_PARTS_COUNT parts, new has $NEW_PARTS_COUNT. Cleaning up excess parts..."
|
|
|
+ EXT_PARTS=$(echo "$OLD_PARTS" | awk -v skip="$NEW_PARTS_COUNT" 'NR>skip')
|
|
|
+ for asset in $EXT_PARTS; do
|
|
|
+ echo "Removing leftover trailing part: $asset"
|
|
|
+ gh release delete-asset "$TAG_NAME" "$asset" --repo "$TARGET_REPO" -y || true
|
|
|
+ done
|
|
|
+ fi
|
|
|
+ fi
|
|
|
+
|
|
|
for part in "${FILENAME}".part*; do
|
|
|
echo "Uploading $part..."
|
|
|
if ! upload_with_retry "$part"; then
|
|
|
@@ -164,6 +191,17 @@ runs:
|
|
|
done
|
|
|
rm -rf "$FILENAME"
|
|
|
else
|
|
|
+ # Remove old split parts if new build fits in a single file
|
|
|
+ OLD_PARTS=$(echo "$ALL_ASSETS" | grep -F "${FILENAME}.part" || echo "")
|
|
|
+ if [ -n "$OLD_PARTS" ]; then
|
|
|
+ echo "New build shrunk to single file. Cleaning up old split parts for ${FILENAME}..."
|
|
|
+ while read -r asset; do
|
|
|
+ [ -z "$asset" ] && continue
|
|
|
+ echo "Removing ghost split part: $asset"
|
|
|
+ gh release delete-asset "$TAG_NAME" "$asset" --repo "$TARGET_REPO" -y || true
|
|
|
+ done <<< "$OLD_PARTS"
|
|
|
+ fi
|
|
|
+
|
|
|
echo "Uploading $FILENAME..."
|
|
|
if ! upload_with_retry "$FILENAME"; then
|
|
|
echo "::error::Failed to upload $FILENAME after multiple attempts."
|