{
  "slug": "Incredible-futures-of--buf-to-generate-Protobuf--GitHub-action-871f0d4f2339",
  "title": "Incredible futures of  buf to generate Protobuf, GitHub action",
  "subtitle": "Explore how Buf and GitHub Actions streamline Protobuf generation, format checking, and breaking change detection for smoother API…",
  "excerpt": "Explore how Buf and GitHub Actions streamline Protobuf generation, format checking, and breaking change detection for smoother API…",
  "date": "2024-08-13",
  "tags": [
    "API"
  ],
  "readingTime": "2 min",
  "url": "https://medium.com/@mobinshaterian/incredible-futures-of-buf-to-generate-protobuf-github-action-871f0d4f2339",
  "hero": "https://cdn-images-1.medium.com/max/800/1*rRJcbwVTH2jK0_jj2PHj-A.jpeg",
  "content": [
    {
      "type": "heading",
      "level": 2,
      "text": "Incredible futures of buf to generate Protobuf, GitHub action"
    },
    {
      "type": "paragraph",
      "html": "<strong>Introduction</strong>"
    },
    {
      "type": "paragraph",
      "html": "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."
    },
    {
      "type": "paragraph",
      "html": "<strong>Summary</strong>"
    },
    {
      "type": "paragraph",
      "html": "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 <code>buf build</code>, <code>buf lint</code>, and <code>buf generate</code> 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."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*rRJcbwVTH2jK0_jj2PHj-A.jpeg",
      "alt": "Incredible futures of  buf to generate Protobuf, GitHub action",
      "caption": "",
      "width": 1024,
      "height": 1024
    },
    {
      "type": "paragraph",
      "html": "In my previous blog, I mentioned Buf, and here is a simple configuration for generating Protobuf:"
    },
    {
      "type": "paragraph",
      "html": "buf. yaml"
    },
    {
      "type": "code",
      "lang": "yaml",
      "code": "version: v2modules:  # - path: lint:  use:    - DEFAULTbreaking:  use:    - FILE"
    },
    {
      "type": "paragraph",
      "html": "buf.gen.yaml"
    },
    {
      "type": "code",
      "lang": "yaml",
      "code": "version: v2managed:  enabled: true  override:    - file_option: go_package_prefix      value:\ngithub.com/your_addressplugins:  - local: protoc-gen-go    out: go    opt: paths=source_relative"
    },
    {
      "type": "paragraph",
      "html": ".github/workflow"
    },
    {
      "type": "code",
      "lang": "yaml",
      "code": "name: Default CICD for protorpeoon:  push:    branches: [main, dev]  pull_request:    types:\n[opened, synchronize, reopened, labeled, unlabeled]env:  CREATE_RELEASE: falsepermissions:\ncontents: read  pull-requests: writejobs:  buf:    runs-on: ubuntu-latest    steps:      - uses:\nactions/checkout@v4      - uses: bufbuild/buf-action@v1        with:          token:\n${{secrets.BUF_TOKEN}}"
    },
    {
      "type": "paragraph",
      "html": "And also, you need&nbsp;.proto files."
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Command lines for executing proto:"
    },
    {
      "type": "code",
      "lang": "bash",
      "code": "buf build\nbuf lint\nbuf generate"
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Format checker"
    },
    {
      "type": "paragraph",
      "html": "After you execute on GitHub and the GitHub action runs buf action, it will check the protobuf format."
    },
    {
      "type": "heading",
      "level": 3,
      "text": "Error:"
    },
    {
      "type": "paragraph",
      "html": "Check failure on line 1 in models/v1/name.proto<br>GitHub Actions / buf"
    },
    {
      "type": "paragraph",
      "html": "Format diff -10/+10."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*ovSXmgyEe1vS85boHHTTuA.png",
      "alt": "Incredible futures of  buf to generate Protobuf, GitHub action",
      "caption": "",
      "width": 364,
      "height": 178
    },
    {
      "type": "paragraph",
      "html": "It is mandatory to run the below command:"
    },
    {
      "type": "code",
      "lang": "bash",
      "code": "buf format -w"
    },
    {
      "type": "paragraph",
      "html": "It will fix all protobuf format problems."
    },
    {
      "type": "heading",
      "level": 2,
      "text": "Breaking"
    },
    {
      "type": "paragraph",
      "html": "In addition, buf has an amazing future; it checks all current proto and previous proto."
    },
    {
      "type": "paragraph",
      "html": "It is possible to skip this feature by adding a label “buf skip breaking” into pr."
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*JnJW4HY8SD4DRi6uEONbCw.png",
      "alt": "Incredible futures of  buf to generate Protobuf, GitHub action",
      "caption": "",
      "width": 493,
      "height": 71
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*Dba5sr7sVeb4xdT9q310Kg.png",
      "alt": "Incredible futures of  buf to generate Protobuf, GitHub action",
      "caption": "",
      "width": 919,
      "height": 263
    },
    {
      "type": "image",
      "src": "https://cdn-images-1.medium.com/max/800/1*RLXq7Z2W21f2iFQ-V494Uw.png",
      "alt": "Incredible futures of  buf to generate Protobuf, GitHub action",
      "caption": "",
      "width": 916,
      "height": 436
    },
    {
      "type": "paragraph",
      "html": "This future is useful when somebody suddenly changes protobuf and API between microservices and may have a problem."
    }
  ]
}
