Repository navigation
build: check the Protobuf schema with buf - #28
Conversation
One-line messages are written over several lines, and two comments that followed a closing brace now follow the field they describe. Nothing else changes: the descriptors without source info are byte-identical, and protoc generates the same Python bindings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VERSIONING.md asks that released field numbers and meanings be kept and that retired fields be reserved, but nothing checked it: compatibility rested on review. buf 1.75.0 now checks the schema in CI (job `protobuf`, part of the required `ci` result): - lint with buf's STANDARD rules, except four the released names cannot meet without renaming the package or every enum value (buf.yaml says which); - formatting, with `buf format`; - on pull requests, compatibility with the latest release tag reachable from the base, with the FILE rules: the release covers the generated Python and C++ bindings, so a renamed or removed field breaks callers even when its number is kept. A pull request that intends a break carries the `breaking-change` label and changes CHANGELOG.md; the labels are read when the job runs, so re-running it after labelling is enough. buf is downloaded from its release and checked against the release's SHA-256, as actionlint is. The pre-commit configuration gains buf's lint and format hooks, and README.md and VERSIONING.md describe the checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@xtk8532704 Could you review this, and answer three questions from #27? Each is a small change either way. CI is green.
|
xtk8532704
left a comment
There was a problem hiding this comment.
The FILE rules and the v0.1.0 release baseline look right. I ran Buf 1.75.0 lint, format and the release comparison, compared the two compiled descriptors byte-for-byte, and confirmed a renumbered released field is rejected without the required label and changelog. One blocking behavior remains: the intended-break exception must not make the job pass when Buf never loaded the baseline.
| PR_NUMBER: ${{ github.event.pull_request.number }} | ||
| run: | | ||
| release=$(git describe --tags --abbrev=0 --match 'v[0-9]*' "$BASE_SHA") | ||
| if buf breaking --against ".git#tag=${release},subdir=t4scene/proto"; then |
There was a problem hiding this comment.
This treats any buf breaking failure as a confirmed schema incompatibility. I ran the exact step with the real Buf binary, the breaking-change label stub and a committed changelog edit. When the temporary directory was unavailable, Buf printed could not clone … and exited 1 without comparing against v0.1.0, but the step emitted an incompatibility warning and returned 0. Please fail if the baseline cannot be built/read or if the comparison fails without actual compatibility diagnostics. Only confirmed schema violations should take the label/changelog exception. Add a regression for a baseline-load failure with both exception prerequisites present.
There was a problem hiding this comment.
Fixed in 2290bc9. Thanks for running it with the real binary.
With Buf 1.75.0, buf breaking exits 100 when it reports violations and 1 when it cannot load an input. Your could not clone case exits 1. It also exits 100 when the changed schema does not compile, because it annotates compile errors as COMPILE with the same status. Checking the exit code alone would have left that second hole open.
The step now runs .github/scripts/check_breaking.py:
- It builds the release schema with
buf buildfirst. If that fails, the job fails, and the label is not consulted. - It compares against the built image. Exit 0 passes. Any exit other than 100 fails.
- On exit 100, every annotation must name a rule from
buf config ls-breaking-rules --configured-only. Otherwise the job fails. - Only then are the label and
CHANGELOG.mdconsulted. The violations are reported as annotations on the proto file.
.github/scripts/test_check_breaking.py runs the real Buf against a scratch repository. It commits a one-message schema, tags it v0.1.0, and uses a stub gh for the labels. It has five cases:
- compatible;
- a break without the label, or without a changelog change;
- a labelled and recorded break;
- a release that cannot be built (TMPDIR missing), with the label and the changelog both present;
- a changed schema that does not compile, with both present.
The last two fail against the previous acceptance logic and pass now. CI runs the tests before the check (Ran 5 tests … OK, then Compatible with v0.1.0.). VERSIONING.md now states that the label never excuses a comparison that could not run.
The compatibility step treated any `buf breaking` failure as an incompatibility, so a release schema that could not be cloned or built passed once the pull request was labelled and the changelog changed. Build the release schema first and fail when that fails. Accept the label only when buf exits 100 and every annotation names a configured breaking rule: buf reports compile errors in the changed schema with the same status. The check moves to .github/scripts/check_breaking.py, with regression tests that run the real buf against a scratch repository. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
xtk8532704
left a comment
There was a problem hiding this comment.
Rechecked at 2290bc91 with the pinned Buf 1.75.0. Lint, formatting, the comparison against v0.1.0, and all five compatibility-script regression tests passed. The two failure cases I was concerned about now fail even with the label and changelog edit, while an actual compatibility violation still goes through the intended exception.
Summary
Closes #27.
CI now checks the Protobuf schema with buf 1.75.0, in a new
protobufjob that is part of the aggregateciresult:buf lintbuf format --diff --exit-codebuf breakingTwo commits:
style(proto)formats the schema asbuf formatdoes: six one-line messages, and two comments that followed a closing brace and now follow their field. The descriptors without source info are byte-identical, and protoc generates the same Python bindings.buildadds:buf.yaml, the job, and buf's lint and format pre-commit hooks;Design choices
These answer #27's questions provisionally; each is easy to change.
PACKAGE_DIRECTORY_MATCH,PACKAGE_VERSION_SUFFIX,ENUM_VALUE_PREFIXandENUM_ZERO_VALUE_SUFFIX.t4scene.protobufor every enum value, which breaks the generated bindings and the JSON form. New declarations follow the existing style, andbuf.yamlsays why each rule is off.git describe --tags --abbrev=0 --match 'v[0-9]*'of the pull request's base, todayv0.1.0, because VERSIONING.md speaks of released fields.subdir=t4scene/protolines the tag's files up with the module, so tags made beforebuf.yamlexisted compare too.breaking-changelabel and changes CHANGELOG.md.grpc_tools.protocandprotoc, and never needs buf.Verification
buf lint,buf format --diff --exit-codebuf breakingagainstv0.1.0buf breakingon scratch editsci.ymland run with a stubghgrpc_tools.protocoutput (_pb2.py,.pyi) identicalpre-commit run --all-files(ruff, buf lint, buf format, actionlint)🤖 Generated with Claude Code