#!/bin/sh
# ci-docs-only.sh CMD [ARG...] — run CMD unless the change under test
# touched documentation only, in which case pass without running it.
#
# The runner sets QUARRY_TOUCHED to a file listing the paths the change
# touched: a branch's own changes, or on trunk what the check-in landed.
# Documentation is anything under docs/ except docs/api.md, which is
# generated from the code and checked by a test, and any Markdown file
# at the top of the tree. With no list (a local run, a lookup that
# failed) or an empty one, CMD runs: a check is only skipped on a list
# that proves there is nothing for it to test (dmestas, 2026-11-08: "there
# should be no tests on docs").
set -eu
list=${QUARRY_TOUCHED:-}
if [ -n "$list" ] && [ -r "$list" ] && [ -s "$list" ]; then
if ! grep -vqE '^(docs/.+|[^/]+\.md)$' "$list" && ! grep -qx 'docs/api.md' "$list"; then
echo "docs only: $(wc -l <"$list" | tr -d ' ') path(s) under docs/ or top-level Markdown; nothing to test" >&2
exit 0
fi
fi
exec "$@"