aboutsummaryrefslogtreecommitdiffstats
path: root/validate.sh
blob: f932f11abeb0bf74d7a1d10f56be8be38d598de3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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