Workflow: sparse partial checkout (code and _incoming only), book lookup before processing, safe rebase retry; revert cancel-in-progress

This commit is contained in:
Audiobook Producer
2026-10-18 01:48:48 -05:00
parent 517e76c533
commit 153153010e
6 changed files with 77 additions and 18 deletions
+17 -1
View File
@@ -12,8 +12,13 @@ BRANCH="${BRANCH:-main}"
git config user.name "audiobook-bot"
git config user.email "audiobook-bot@noreply.invalid"
# The checkout is sparse (code and _incoming only). Books are pulled in only when needed.
sparse_add() { printf '%s\n' "$@" | git sparse-checkout add --stdin; }
esc() { printf '%s' "$1" | sed -e 's/[][*?\\#!]/\\&/g'; }
pdfs=()
if [ -n "${PDF_INPUT:-}" ]; then
sparse_add "/$(esc "$PDF_INPUT")"
[ -f "$PDF_INPUT" ] || { echo "FAILED: no such file in the repo: $PDF_INPUT"; exit 1; }
pdfs=("$PDF_INPUT")
else
@@ -30,7 +35,7 @@ push_with_retry() { # push HEAD to the branch; if the branch moved, rebase and
for i in 1 2 3 4 5; do
if git push origin "HEAD:refs/heads/$BRANCH"; then return 0; fi
echo "push attempt $i failed; fetching and rebasing"
git pull --rebase origin "$BRANCH" || return 1
git fetch -q --depth=100 origin "$BRANCH" && git rebase FETCH_HEAD || { git rebase --abort 2>/dev/null; return 1; }
done
return 1
}
@@ -39,6 +44,17 @@ failed=0
for pdf in "${pdfs[@]}"; do
echo; echo "################ $pdf"
result="$(mktemp)"
rel="$(python3 _pipeline/cli.py bookpath "$pdf")" || { echo "FAILED: $rel"; failed=1; continue; }
echo "book folder: $rel"
e="$(esc "$rel")"
if git cat-file -e "HEAD:$rel" 2>/dev/null; then
if [ "$DRY_RUN" = "true" ]; then # dry run compares text only: skip audio
sparse_add "/$e/book.json" "/$e/warnings.log" "/$e/LICENSE_STATUS.md" "/$e/text/" "/$e/script/" "/$e/figures/"
else # a real run needs the existing audio so it can skip it
sparse_add "/$e/"
fi
echo "this book already exists in the repo; existing files fetched"
fi
if [ "$DRY_RUN" = "true" ]; then
export AUDIOBOOK_BOOKS_DIR="/tmp/audiobook-dry/books"; rm -rf /tmp/audiobook-dry
mkdir -p /tmp/audiobook-dry