#!/bin/sh
set -eu

ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
# shellcheck disable=SC1091
. "$ROOT/rehearsal-versions.env"

# Scan the exact host tree, including JSON contents, before any container can
# receive it as a bind mount. Executable evidence also requires a clean commit.
node "$ROOT/scripts/verify-release-scope.mjs" --require-committed-candidate

if command -v docker >/dev/null 2>&1; then
  runtime=docker
elif command -v podman >/dev/null 2>&1; then
  runtime=podman
else
  echo "Docker or Podman is required. No toolchain is installed by this script." >&2
  exit 2
fi

exec "$runtime" run --rm \
  --volume "$ROOT:/workspace:rw" \
  --workdir /workspace \
  "$REHEARSAL_IMAGE" \
  sh scripts/ci-rehearsal.sh
