diff --git a/_pipeline/ci/run.sh b/_pipeline/ci/run.sh index d46d05d..24aa434 100755 --- a/_pipeline/ci/run.sh +++ b/_pipeline/ci/run.sh @@ -54,12 +54,14 @@ for pdf in "${pdfs[@]}"; do echo "book folder: $rel" e="$(esc "$rel")" if git cat-file -e "HEAD:$rel" 2>/dev/null; then + echo "this book already exists in the repo" 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" + elif [ "$DRY_RUN" != "true" ]; then + sparse_add "/$e/" # new book: its files must be inside the sparse checkout or git add ignores them fi if [ "$DRY_RUN" = "true" ]; then export AUDIOBOOK_BOOKS_DIR="/tmp/audiobook-dry/books"; rm -rf /tmp/audiobook-dry @@ -79,15 +81,19 @@ for pdf in "${pdfs[@]}"; do [ "$DRY_RUN" = "true" ] && continue bookdir="$(python3 -c "import json,sys; print(json.load(open(sys.argv[1]))['book_dir'])" "$result")" + rel="${bookdir#"$PWD"/}" + git add -A -- "$bookdir" || { echo "FAILED: git add failed for $rel. Nothing was committed."; failed=1; continue; } + # Safety net: the book must really be staged, or the PDF must not be removed from _incoming/. + if ! git ls-files --error-unmatch -- "$rel/book.json" >/dev/null 2>&1; then + echo "FAILED: $rel/book.json is not tracked after git add. Nothing was committed."; failed=1; continue + fi case "$pdf" in _incoming/*) git rm -q -- "$pdf" side="${pdf%.[pP][dD][fF]}.json"; [ -f "$side" ] && git rm -q -- "$side" ;; esac - git add -A -- "$bookdir" if git diff --cached --quiet; then echo "No changes to commit for $pdf"; continue; fi - rel="${bookdir#"$PWD"/}" git commit -q -m "Audiobook: $rel (from $pdf, Actions run ${GITHUB_RUN_NUMBER:-?}) [skip ci]" git --no-pager show --stat --format='commit %H' HEAD | head -40 if push_with_retry; then echo "PUSHED to $BRANCH: $rel"; else echo "FAILED: could not push to $BRANCH"; failed=1; fi