main
John Lauer Component record TPS16850VMAR: files batch 1 6db00ed 20h ago
#!/usr/bin/env bash
# usage: push.sh <page_dir> <owner/slug>  (batches under 3.3 MB, a file bigger than that alone, page.json last)
set -u
dir="$1"; ref="$2"; cd "$dir" || exit 1
mapfile -t files < <(find . -type f ! -name page.json -printf '%s %P\n' | sort -n)
batch=(); size=0; n=0
push() {
  local tries=0
  while :; do
    out=$(adom-wiki repo push "$ref" --files "$@" -m "$MSG" 2>&1); rc=$?
    if echo "$out" | grep -q -E '429|RATE_LIMITED'; then
      w=$(echo "$out" | grep -oE '"retry_after":[0-9]+' | grep -oE '[0-9]+' | head -1); w=${w:-20}
      echo "rate limited, waiting $w s"; sleep "$w"; tries=$((tries+1)); [ $tries -gt 5 ] && return 1; continue
    fi
    echo "$out" | tail -3; return $rc
  done
}
flush() {
  [ ${#batch[@]} -eq 0 ] && return 0
  n=$((n+1)); MSG="Component record TPS16850VMAR: files batch $n"
  echo "== batch $n: ${#batch[@]} files, $size bytes"
  push "${batch[@]}" || { echo "PUSH FAILED"; exit 1; }
  batch=(); size=0; sleep 3
}
for line in "${files[@]}"; do
  s=${line%% *}; f=${line#* }
  if [ $((size + s)) -gt 3300000 ]; then flush; fi
  batch+=("$f"); size=$((size + s))
done
flush
MSG="Component record TPS16850VMAR: page.json (last, keeps hero and title)"
echo "== page.json"; push page.json || { echo "PUSH FAILED"; exit 1; }