Files
go-sip/scripts/update-contracts.sh
T

25 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Explicit maintenance operation: fetch latest shared main before contract edits.
set -euo pipefail
cd "$(dirname "$0")/.."
sub=contracts/schema
if [[ ! -e "$sub/.git" ]]; then
git submodule update --init -- "$sub"
fi
# A previously fetched fast-forward may be unstaged after a failed check.
# Still reject dirty submodule files, wrong origins and divergent history.
python3 -c 'from pathlib import Path; from runpy import run_path; run_path("scripts/check-current-contracts.py")["check_checkout"](Path.cwd(), updating=True)'
git -C "$sub" fetch origin main
git -C "$sub" merge --ff-only FETCH_HEAD
if [[ "$(git -C "$sub" rev-parse HEAD)" != "$(git -C "$sub" rev-parse FETCH_HEAD)" ]]; then
echo 'Contract checkout is ahead of shared main; publish/reconcile it explicitly before updating.' >&2
exit 1
fi
python3 contracts/verify.py
python3 -m unittest discover -s contracts -p 'test_*.py' -v
# This stages only the contract pointer. Implementations, tests and the pointer
# still need a reviewed consumer-project commit; unrelated files are untouched.
git add -- "$sub"
python3 scripts/check-current-contracts.py
printf 'Shared contract updated to %s; pointer staged, consumer changes still require verification and commit.\n' "$(git -C "$sub" rev-parse HEAD)"