faster deploy to clean stale bundles, reading the live site

This commit is contained in:
Joe Lothan 2026-05-25 23:50:35 -04:00
parent 6649c09d12
commit 2256055632

View file

@ -90,25 +90,20 @@ echo "Uploaded 4 files"
rm -rf "$TMPDIR" rm -rf "$TMPDIR"
# Clean up stale bundles from previous runs # Clean up stale bundles from previous runs
echo "Cleaning stale bundles above $TOTAL_BUNDLES..." # Read old TOTAL_BUNDLES from the live index.html before we overwrite it
STALE=$(aws s3api list-objects-v2 --bucket "$SITE_BUCKET" --prefix "tabs/" --query "Contents[].Key" --output text \ OLD_TOTAL=$(aws s3 cp "s3://$SITE_BUCKET/index.html" - 2>/dev/null \
| tr '\t' '\n' \ | grep -oP 'TOTAL_BUNDLES = \K[0-9]+' || echo "0")
| while read -r key; do
num=$(echo "$key" | grep -oP '\d+' || true)
if [ -n "$num" ] && [ "$((10#$num))" -ge "$TOTAL_BUNDLES" ]; then
echo "$key"
fi
done)
if [ -n "$STALE" ]; then if [ "$OLD_TOTAL" -gt "$TOTAL_BUNDLES" ]; then
STALE_COUNT=$(echo "$STALE" | wc -l) STALE_COUNT=$((OLD_TOTAL - TOTAL_BUNDLES))
echo "Deleting $STALE_COUNT stale bundles..." echo "Deleting $STALE_COUNT stale bundles ($TOTAL_BUNDLES to $((OLD_TOTAL - 1)))..."
echo "$STALE" | while read -r key; do for i in $(seq "$TOTAL_BUNDLES" "$((OLD_TOTAL - 1))"); do
aws s3 rm "s3://$SITE_BUCKET/$key" --quiet PADDED=$(printf "%04d" "$i")
aws s3 rm "s3://$SITE_BUCKET/tabs/${PADDED}.json" --quiet
done done
echo "Deleted $STALE_COUNT stale bundles" echo "Deleted $STALE_COUNT stale bundles"
else else
echo "No stale bundles found" echo "No stale bundles to clean (old=$OLD_TOTAL, new=$TOTAL_BUNDLES)"
fi fi
# Invalidate CloudFront # Invalidate CloudFront