diff options
Diffstat (limited to 'validate.sh')
| -rwxr-xr-x | validate.sh | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/validate.sh b/validate.sh index f932f11..5bc0224 100755 --- a/validate.sh +++ b/validate.sh @@ -1,8 +1,17 @@ #!/usr/bin/env bash -# Validate every generated EPUB with epubcheck (the official EPUB validator). -# Exits non-zero if any EPUB has errors, so it can gate CI. +# Validate every generated EPUB. # -# Requires epubcheck on PATH (e.g. `brew install epubcheck`). +# 1. epubcheck — official EPUB3 conformance (always, required on PATH). +# 2. kindlegen — Amazon's converter, the engine behind "Send to Kindle". +# Optional but recommended: epubcheck does NOT catch the +# Kindle-specific issues that cause "E999" delivery failures. +# +# epubcheck: brew install epubcheck +# kindlegen: bundled inside Kindle Previewer 3 at +# ".../Kindle Previewer 3.app/Contents/lib/fc/bin/kindlegen". +# Put it on PATH or point KINDLEGEN at it to enable the Kindle check. +# +# Exits non-zero if any EPUB fails a check, so it can gate CI. set -uo pipefail @@ -11,6 +20,8 @@ if ! command -v epubcheck >/dev/null 2>&1; then exit 127 fi +KINDLEGEN="${KINDLEGEN:-$(command -v kindlegen 2>/dev/null || true)}" + shopt -s nullglob epubs=(epubs/*.epub) if [ ${#epubs[@]} -eq 0 ]; then @@ -20,13 +31,28 @@ fi fail=0 for f in "${epubs[@]}"; do - if epubcheck "$f" >/dev/null 2>&1; then - echo "PASS $f" - else - echo "FAIL $f" - epubcheck "$f" 2>&1 | grep -E '^(ERROR|FATAL|WARNING)' | sed 's/^/ /' - fail=1 + ok=1 + + if ! epubcheck "$f" >/dev/null 2>&1; then + ok=0 + echo "FAIL (epubcheck) $f" + epubcheck "$f" 2>&1 | grep -E '^(ERROR|FATAL)' | sed 's/^/ /' fi + + if [ -n "$KINDLEGEN" ]; then + # kindlegen writes output next to the input; -o takes a bare filename. + out=$("$KINDLEGEN" "$f" -o "$(basename "${f%.epub}").mobi" 2>&1) + rm -f "${f%.epub}.mobi" + if echo "$out" | grep -q "could not be generated"; then + ok=0 + echo "FAIL (kindlegen) $f" + echo "$out" | grep -E '^Error|E[0-9]{4,}' | sed 's/^/ /' + fi + fi + + if [ $ok -eq 1 ]; then echo "PASS $f"; else fail=1; fi done +[ -z "$KINDLEGEN" ] && echo "note: kindlegen not found; ran epubcheck only (set KINDLEGEN to also test Kindle conversion)." >&2 + exit $fail |
