#!/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