reportist/tools/validate.sh

11 lines
783 B
Bash
Executable File

#!/usr/bin/env bash
# Validate by compiling through the same Typst data and contract path as rendering.
set -euo pipefail
[[ $# -eq 1 ]] || { echo "Usage: $0 INPUT" >&2; exit 2; }
root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P); input=$(realpath "$1")
case $input in *.json) format=json;; *.yaml|*.yml) format=yaml;; *) echo "error: expected YAML or JSON" >&2; exit 1;; esac
temp=$(mktemp -d "${TMPDIR:-/tmp}/reportist-validate.XXXXXXXX"); trap 'rm -rf "$temp"' EXIT
cp "$input" "$temp/report.$format"; cp "$root/tools/validate.typ" "$temp/validate.typ"
typst query --root "$temp" --input "report=report.$format" --input "format=$format" "$temp/validate.typ" '<validated>' --one >/dev/null 2>&1 || { echo "error: invalid report v1" >&2; exit 1; }
echo "Valid report v1: $1"