CI: add the book folder to the sparse checkout before processing, verify it is staged before removing the PDF from _incoming
This commit is contained in:
+9
-3
@@ -54,12 +54,14 @@ for pdf in "${pdfs[@]}"; do
|
|||||||
echo "book folder: $rel"
|
echo "book folder: $rel"
|
||||||
e="$(esc "$rel")"
|
e="$(esc "$rel")"
|
||||||
if git cat-file -e "HEAD:$rel" 2>/dev/null; then
|
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
|
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/"
|
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
|
else # a real run needs the existing audio so it can skip it
|
||||||
sparse_add "/$e/"
|
sparse_add "/$e/"
|
||||||
fi
|
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
|
fi
|
||||||
if [ "$DRY_RUN" = "true" ]; then
|
if [ "$DRY_RUN" = "true" ]; then
|
||||||
export AUDIOBOOK_BOOKS_DIR="/tmp/audiobook-dry/books"; rm -rf /tmp/audiobook-dry
|
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
|
[ "$DRY_RUN" = "true" ] && continue
|
||||||
|
|
||||||
bookdir="$(python3 -c "import json,sys; print(json.load(open(sys.argv[1]))['book_dir'])" "$result")"
|
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
|
case "$pdf" in
|
||||||
_incoming/*)
|
_incoming/*)
|
||||||
git rm -q -- "$pdf"
|
git rm -q -- "$pdf"
|
||||||
side="${pdf%.[pP][dD][fF]}.json"; [ -f "$side" ] && git rm -q -- "$side"
|
side="${pdf%.[pP][dD][fF]}.json"; [ -f "$side" ] && git rm -q -- "$side"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
git add -A -- "$bookdir"
|
|
||||||
if git diff --cached --quiet; then echo "No changes to commit for $pdf"; continue; fi
|
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 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
|
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
|
if push_with_retry; then echo "PUSHED to $BRANCH: $rel"; else echo "FAILED: could not push to $BRANCH"; failed=1; fi
|
||||||
|
|||||||
Reference in New Issue
Block a user