aboutsummaryrefslogtreecommitdiffstats
path: root/validate.sh
diff options
context:
space:
mode:
Diffstat (limited to 'validate.sh')
-rwxr-xr-xvalidate.sh32
1 files changed, 32 insertions, 0 deletions
diff --git a/validate.sh b/validate.sh
new file mode 100755
index 0000000..f932f11
--- /dev/null
+++ b/validate.sh
@@ -0,0 +1,32 @@
+#!/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.
+#
+# Requires epubcheck on PATH (e.g. `brew install epubcheck`).
+
+set -uo pipefail
+
+if ! command -v epubcheck >/dev/null 2>&1; then
+ echo "error: epubcheck not found. Install it (e.g. 'brew install epubcheck')." >&2
+ exit 127
+fi
+
+shopt -s nullglob
+epubs=(epubs/*.epub)
+if [ ${#epubs[@]} -eq 0 ]; then
+ echo "error: no EPUBs in epubs/. Run 'zig build run' first." >&2
+ exit 1
+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
+ fi
+done
+
+exit $fail