check-behavior-contract.sh
1 #!/usr/bin/env bash 2 set -euo pipefail 3 4 BASE_REF="${1:-origin/master}" 5 6 if ! git rev-parse --verify "$BASE_REF" >/dev/null 2>&1; then 7 echo "ERROR: base ref '$BASE_REF' does not exist" >&2 8 exit 1 9 fi 10 11 changed_files="$(git diff --name-only "$BASE_REF"...HEAD)" 12 13 if [ -z "$changed_files" ]; then 14 exit 0 15 fi 16 17 behavior_changed=false 18 for path in SKILL.md README.md references/workflow.md; do 19 if printf '%s\n' "$changed_files" | rg -qx "$path"; then 20 behavior_changed=true 21 break 22 fi 23 done 24 25 if [ "$behavior_changed" = false ]; then 26 exit 0 27 fi 28 29 if ! printf '%s\n' "$changed_files" | rg -qx 'VERSION'; then 30 echo "ERROR: VERSION must change when behavior-contract files change" >&2 31 exit 1 32 fi 33 34 required_contract_files=( 35 "SKILL.md" 36 "README.md" 37 "references/workflow.md" 38 ) 39 40 missing_files=() 41 for path in "${required_contract_files[@]}"; do 42 if ! printf '%s\n' "$changed_files" | rg -qx "$path"; then 43 missing_files+=("$path") 44 fi 45 done 46 47 if [ "${#missing_files[@]}" -gt 0 ]; then 48 printf 'ERROR: behavior-contract changes must update all contract files together. Missing:%s\n' "" >&2 49 for path in "${missing_files[@]}"; do 50 printf ' - %s\n' "$path" >&2 51 done 52 exit 1 53 fi 54 55 exit 0