#!/bin/sh
set -euo pipefail

# Consumer synchronization is opt-in. It commits into every registered consumer repository, so it
# runs only for a commit made with SHARED_SYNC_COMMIT=1 in the environment.
if [ "${SHARED_SYNC_COMMIT:-0}" != "1" ]; then
  exit 0
fi

repo_root="$(git rev-parse --show-toplevel)"
sync_script="$repo_root/scripts/sync-consumers.ps1"

if command -v pwsh >/dev/null 2>&1; then
  pwsh -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$sync_script" -Commit
elif command -v powershell.exe >/dev/null 2>&1; then
  powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -File "$sync_script" -Commit
else
  echo "shared synchronization requires pwsh or powershell.exe." >&2
  exit 1
fi
