#!/usr/bin/env bash set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" base="${1:-origin/main}" if ! git -C "$root" cat-file -e "$base^{commit}" 2>/dev/null; then echo "Compatibility base does not exist; this is valid only for the initial version baseline: $base" exit 0 fi if [[ "$(git -C "$root" rev-parse "$base")" == "$(git -C "$root" rev-parse HEAD)" ]]; then base="HEAD^" fi if ! git -C "$root" cat-file -e "$base:eng/Versions.props" 2>/dev/null; then echo "Base has no release version manifest; accepting the initial compatibility baseline." exit 0 fi current_property() { sed -n "s:.*<$1>\(.*\).*:\1:p" "$root/eng/Versions.props" } base_property() { git -C "$root" show "$base:eng/Versions.props" \ | sed -n "s:.*<$1>\(.*\).*:\1:p" } changed() { git -C "$root" diff --name-only "$base"...HEAD -- "$@" | grep -q . } require_increase() { local property="$1" local description="$2" shift 2 if changed "$@"; then local before after before="$(base_property "$property")" after="$(current_property "$property")" if [[ ! "$before" =~ ^[0-9]+$ || ! "$after" =~ ^[0-9]+$ || "$after" -le "$before" ]]; then echo "$description changed without increasing $property ($before -> $after)." >&2 exit 1 fi fi } require_increase RendezvousMajorVersion "Published .NET API snapshot" \ 'tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v*/client-public-api.txt' \ 'tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v*/contracts-public-api.txt' require_increase HttpContractVersion "HTTP/OpenAPI contract evidence" \ 'docs/api/*.json' \ 'tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v*/*.json' \ ':(exclude)tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v*/connection-ticket.json' require_increase UdpContractVersion "UDP contract evidence" \ 'tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v*/*.hex' require_increase ConnectionTicketFormatVersion "Connection-ticket format evidence" \ 'tests/FinalFactory.Rendezvous.Tests/TestData/Contracts/v*/connection-ticket.json' echo "Compatibility changes are paired with the required version increase."