Add --last-push-hash option to deploy-ebook-to-www script to decide whether to rebuild the cover images/actual ebook

This commit is contained in:
Alex Cabal 2020-08-27 11:15:19 -05:00
parent 27f7ce9334
commit 73297adbf7

View file

@ -6,12 +6,14 @@ DESCRIPTION
Deploy a Standard Ebook source repository to the web. Deploy a Standard Ebook source repository to the web.
USAGE USAGE
deploy-ebook-to-www [-v,--verbose] [-g,--group GROUP] [--webroot WEBROOT] [--weburl WEBURL] [--no-images] DIRECTORY [DIRECTORY...] deploy-ebook-to-www [-v,--verbose] [-g,--group GROUP] [--webroot WEBROOT] [--weburl WEBURL] [--no-images] [-l,--last-push-hash HASH] DIRECTORY [DIRECTORY...]
DIRECTORY is a bare source repository. DIRECTORY is a bare source repository.
GROUP is a groupname. Defaults to "se". GROUP is a groupname. Defaults to "se".
WEBROOT is the path to your webroot. Defaults to "/standardebooks.org". WEBROOT is the path to your webroot. Defaults to "/standardebooks.org".
WEBURL is the URL the website is served on. Defaults to "https://standardebooks.org". WEBURL is the URL the website is served on. Defaults to "https://standardebooks.org".
With --last-push-hash, check the repo head against HASH to see if the cover image or ebook source changed, which will determine if cover thumbnails get re-generated or the ebook gets re-built.
With --no-images, do not create cover thumbnails or hero images for the web. With --no-images, do not create cover thumbnails or hero images for the web.
EOF EOF
exit exit
@ -22,9 +24,11 @@ require(){ command -v "$1" > /dev/null 2>&1 || { suggestion=""; if [ -n "$2" ];
verbose="false" verbose="false"
images="true" images="true"
build="true"
group="se" group="se"
webRoot="/standardebooks.org/web" webRoot="/standardebooks.org/web"
webUrl="https://standardebooks.org" webUrl="https://standardebooks.org"
lastPushHash=""
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
usage usage
@ -53,6 +57,11 @@ while [ $# -gt 0 ]; do
webUrl="$2" webUrl="$2"
shift 2 shift 2
;; ;;
-l|--last-push-hash)
[ -n "$2" ] || die "Last commit hash cant be empty."
lastPushHash="$2"
shift 2
;;
--no-images) --no-images)
images="false" images="false"
shift 1 shift 1
@ -124,6 +133,25 @@ do
continue continue
fi fi
if [ "${lastPushHash}" != "" ]; then
# We were passed the hash of the last push before this one.
# Check to see if the cover image changed, to decide if we want to rebuild the cover image thumbnail/hero
diff=$(git diff "${lastPushHash}" HEAD)
if [[ "${diff}" =~ diff\ --git\ a/images/cover.jpg ]] || [[ "${diff}" =~ diff\ --git\ a/images/cover.svg ]]; then
images="true"
else
images="false"
fi
# Check to see if the actual ebook changed, to decide if we want to build
if [[ "${diff}" =~ diff\ --git\ a/src/ ]]; then
build="true"
else
build="false"
fi
fi
webDir=$(git show HEAD:src/epub/content.opf | grep --only-matching --extended-regexp "<dc:identifier id=\"uid\">url:https://standardebooks.org/ebooks/[^<]+<\/dc:identifier>" | sed --regexp-extended "s/<[^>]+?>//g" | sed --regexp-extended "s/^url:https:\/\/standardebooks.org\/ebooks\/?//") webDir=$(git show HEAD:src/epub/content.opf | grep --only-matching --extended-regexp "<dc:identifier id=\"uid\">url:https://standardebooks.org/ebooks/[^<]+<\/dc:identifier>" | sed --regexp-extended "s/<[^>]+?>//g" | sed --regexp-extended "s/^url:https:\/\/standardebooks.org\/ebooks\/?//")
if [ "${webDir}" = "" ]; then if [ "${webDir}" = "" ]; then
@ -183,6 +211,7 @@ do
popd > /dev/null || die "Couldn't pop directory." popd > /dev/null || die "Couldn't pop directory."
fi fi
if [ "${build}" = "true" ]; then
if [ "${verbose}" = "true" ]; then if [ "${verbose}" = "true" ]; then
printf "Building ebook ... " printf "Building ebook ... "
fi fi
@ -214,6 +243,7 @@ do
# Move contents of the work dir over # Move contents of the work dir over
mv "${workDir}"/* "${webDir}/" mv "${workDir}"/* "${webDir}/"
fi
if [ "${images}" = "true" ]; then if [ "${images}" = "true" ]; then
# Move the cover images over # Move the cover images over