diff --git a/scripts/buf.sh b/scripts/buf.sh index eeda901..7c1a494 100755 --- a/scripts/buf.sh +++ b/scripts/buf.sh @@ -14,6 +14,7 @@ # (or when a local clone has no origin/main) # A baseline without grpc/grpc-contract/buf.yaml has nothing to be compatible with, and the check # says so and passes. A baseline Git cannot find fails: a shallow clone cannot answer the question. +# A break passes only when a commit between the baseline and HEAD declares it (`BREAKING CHANGE:`). set -euo pipefail root=$(git rev-parse --show-toplevel) @@ -55,7 +56,18 @@ case "${1:-}" in exit 0 fi echo "buf.sh: breaking against ${commit:0:12}" - "$buf" breaking --against "$root/.git#ref=$commit,subdir=$module" + if "$buf" breaking --against "$root/.git#ref=$commit,subdir=$module"; then + exit 0 + fi + # A breaking change passes only when a commit in the range declares it (commit rules: `!` in + # the title and a `BREAKING CHANGE:` trailer), which is also what makes it a MAJOR version + # (docs/work/release.md 2절). An undeclared one fails, so a wire break cannot slip in unnoticed. + if git log --format=%B "$commit..HEAD" | grep -q '^BREAKING CHANGE:'; then + echo "buf.sh: the schema breaks against ${commit:0:12}, and a commit in ${commit:0:12}..HEAD declares BREAKING CHANGE; passing." + exit 0 + fi + echo "buf.sh: breaking schema change against ${commit:0:12} that no commit declares. Undo it, or declare it (title '!', trailer 'BREAKING CHANGE:') and release it as MAJOR." >&2 + exit 1 ;; *) echo "usage: scripts/buf.sh lint|breaking" >&2