Creating CI Response Structure
Alright, let's structure my response based on the user's request about a Protobuf breaking-change detector in continuous integration. I want to cover tool choices, rules, CI steps, PR blocking, and any extras efficiently.
I'll include a sample buf.yaml, mentioning versioning, modules, linting preferences, and breaking change configurations. Additionally, I should address the use of buf.lock for dependencies and the importance of updating modules. I’ll also note aspects related to protoc plugins. This will be concise and informative, but without extra fluff!
A practical way to get “breaking-change detection” for Protobuf in CI (with semantic rules and PR-blocking) is to treat your .proto files as an API surface and run a descriptor-based compatibility check against your main branch (or last release). The most widely used tool for this is Buf.
1) Tooling: Buf (semantic breaking rules + CI-friendly output)
Buf builds a FileDescriptorSet from your schema and compares it to a baseline using explicit compatibility rules (not just text diffs).
What you get:
- Schema diffs with meaning (e.g., “field deleted”, “type changed”, “enum value removed”)
- Rule sets (wire-compatibility, source/API compatibility, package/file deletion, etc.)
- CI exit codes for PR blocking
- JSON output for annotations/comment bots
Install: https://buf.build/docs/installation
2) What “breaking” means (common semantic rules)
There are two categories people mix:
A) Wire-compatibility (runtime interoperability)
Typical breaking changes:
- Changing a field number/tag
- Reusing a deleted field number (unless it’s
reserved)
- Changing field type in a way that changes wire type (e.g.,
int32 ↔ string)
- Changing
repeated ↔ singular
- Changing
map<K,V> key/value types
- Removing enum values (sometimes treated as breaking depending on policy)
Typically compatible:
- Adding a new field with a new tag
- Adding enum values (policy-dependent; many allow it)
B) “API” / generated-code / contract compatibility (gRPC/service evolution)
Often treated as breaking in CI:
- Removing RPCs/services/messages
- Renaming RPCs (wire may be OK, but clients break)
- Moving packages, changing fully-qualified names
Buf lets you choose which compatibility contract you enforce.
3) Repo setup (Buf config)
Create buf.yaml at repo root:
version: v2
modules:
- path: proto
lint:
use:
- DEFAULT
breaking:
use:
- WIRE # wire-compat checks (field numbers/types/etc.)
- FILE # prevents deleting/renaming files/symbols in ways that break API consumers
ignore_unstable_packages: true
Notes:
ignore_unstable_packages: true means packages like foo.v1alpha1 can change freely (convention-based).
- You can also selectively ignore rules for specific paths if you need an escape hatch.
4) CI: run lint + breaking check against the PR base
GitHub Actions example (PR-blocking)
name: proto-compat
on:
pull_request:
jobs:
buf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # required so Buf can compare against base
- uses: bufbuild/buf-setup-action@v1
- name: Lint protos
run: buf lint
- name: Breaking change check
run: |
buf breaking --against ".git#branch=${{ github.base_ref }}"
If buf breaking exits non-zero, the job fails → mark it as a required status check in branch protection rules → PR merge is blocked.
GitLab CI equivalent (merge request)
buf:
image: bufbuild/buf:latest
script:
- buf lint
- buf breaking --against ".git#branch=$CI_MERGE_REQUEST_TARGET_BRANCH_NAME"
5) “Schema diffs” visibility (developer-friendly output)
Buf primarily reports violations, but you can make output more review-friendly:
-
Use JSON output for CI annotations:
buf breaking --against ".git#branch=main" --error-format=json
-
If you want a human diff view in PRs, common patterns are:
- Generate a descriptor set for both sides and diff them (some teams do this with custom scripts)
- Use Buf + a PR bot that posts violations as a comment (many orgs do this with GitHub Checks annotations)
6) Operational best practices (so checks don’t become a nuisance)
If you tell me:
- GitHub vs GitLab,
- mono-repo vs dedicated
proto/ repo,
- whether you need wire-only compatibility or API (services/RPCs) too,
…I can propose an exact
buf.yaml rule set and the CI snippet that matches your policy.