Incredible futures of buf to generate Protobuf, GitHub action

Introduction

Maintaining consistent and reliable communication between services is crucial in the evolving API development landscape. Buf, an advanced tool for Protocol Buffers and gRPC, offers powerful features to streamline this process. In this blog, we’ll explore a simple configuration setup for generating Protobuf using Buf, integrate it with GitHub Actions for continuous integration, and address common issues like format inconsistencies and breaking changes. By leveraging Buf’s capabilities, you can ensure smoother and more effective management of your Protobuf schemas and API interactions.

Summary

The text discusses configuring Buf to generate Protocol Buffers (Protobuf) and integrate it with GitHub Actions for continuous integration and delivery. It provides example configurations for Buf and GitHub Actions to automate Protobuf generation and format checking. Key commands such as buf build, buf lint, and buf generate are highlighted, along with troubleshooting steps for format issues. Buf's breaking change detection feature is also mentioned, which helps identify and manage changes that could impact microservices. Additionally, Buf allows for skipping breaking change checks by using a specific PR label, offering flexibility in managing Protobuf schemas.

In my previous blog, I mentioned Buf, and here is a simple configuration for generating Protobuf:

buf. yaml

yaml
version: v2modules:  # - path: lint:  use:    - DEFAULTbreaking:  use:    - FILE

buf.gen.yaml

yaml
version: v2managed:  enabled: true  override:    - file_option: go_package_prefix      value:
github.com/your_addressplugins:  - local: protoc-gen-go    out: go    opt: paths=source_relative

.github/workflow

yaml
name: Default CICD for protorpeoon:  push:    branches: [main, dev]  pull_request:    types:
[opened, synchronize, reopened, labeled, unlabeled]env:  CREATE_RELEASE: falsepermissions:
contents: read  pull-requests: writejobs:  buf:    runs-on: ubuntu-latest    steps:      - uses:
actions/checkout@v4      - uses: bufbuild/buf-action@v1        with:          token:
${{secrets.BUF_TOKEN}}

And also, you need .proto files.

Command lines for executing proto:

bash
buf build
buf lint
buf generate

Format checker

After you execute on GitHub and the GitHub action runs buf action, it will check the protobuf format.

Error:

Check failure on line 1 in models/v1/name.proto
GitHub Actions / buf

Format diff -10/+10.

Incredible futures of  buf to generate Protobuf, GitHub action

It is mandatory to run the below command:

bash
buf format -w

It will fix all protobuf format problems.

Breaking

In addition, buf has an amazing future; it checks all current proto and previous proto.

It is possible to skip this feature by adding a label “buf skip breaking” into pr.

Incredible futures of  buf to generate Protobuf, GitHub action
Incredible futures of  buf to generate Protobuf, GitHub action
Incredible futures of  buf to generate Protobuf, GitHub action

This future is useful when somebody suddenly changes protobuf and API between microservices and may have a problem.