GitHub Action
buf-push
Push buf modules to the Buf Schema Registry (BSR). The pushed module will be created with a module tag equal to the git commit SHA.
Refer to the action.yml to see all of the action parameters.
The buf-push
action requires that buf
is installed in the Github Action
runner, so we'll use the buf-setup action to install it.
In most cases, all you'll need to do is configure buf-setup and the
buf_token
(used to authenticate access to the BSR). For details on
creating a buf
API token, please refer to the
documentation.
Once you've created a buf
API token, you'll need to create an encrypted
Github Secret
for it. In the following example, the API token is set to BUF_TOKEN
.
steps:
- uses: actions/checkout@v2
- uses: bufbuild/[email protected]
with:
version: '0.41.0'
- uses: bufbuild/[email protected]
with:
github_token: ${{ github.token }}
buf_token: ${{ secrets.BUF_TOKEN }}
Some repositories are structured so that their buf.yaml
is defined
in a sub-directory alongside their Protobuf sources, such as a proto/
directory. In this case, you can specify the relative input
path.
$ tree
.
└── proto
├── acme
│ └── weather
│ └── v1
│ └── weather.proto
└── buf.yaml
steps:
- uses: actions/checkout@v2
- uses: bufbuild/[email protected]
with:
version: '0.41.0'
- uses: bufbuild/[email protected]
with:
input: 'proto'
github_token: ${{ github.token }}
buf_token: ${{ secrets.BUF_TOKEN }}
The buf-push
action is also commonly used alongside other buf
actions,
such as buf-breaking and buf-lint.
In combination, you can verify that your module passes both buf-breaking
and buf-lint
before the module is pushed to the BSR. The following example
uses the hypothetical https://github.com/acme/weather.git
repository,
and includes a few additional if
conditions to do exactly this.
on:
push:
branches:
- main
steps:
- uses: actions/checkout@v2
- uses: bufbuild/[email protected]
id: setup
with:
version: '0.41.0'
- uses: bufbuild/[email protected]
if: ${{ steps.setup.outcome == 'success' }}
env:
BUF_INPUT_HTTPS_USERNAME: ${{ github.actor }}
BUF_INPUT_HTTPS_PASSWORD: ${{ github.token }}
with:
input: 'proto'
against: 'https://github.com/acme/weather.git#branch=master,ref=HEAD~1,subdir=proto'
github_token: ${{ github.token }}
- uses: bufbuild/[email protected]
if: ${{ steps.setup.outcome == 'success' }}
with:
input: 'proto'
github_token: ${{ github.token }}
- uses: bufbuild/[email protected]
if: success() # Only trigger the 'buf-push-action' if all previous steps succeed.
with:
input: 'proto'
buf_token: ${{ secrets.BUF_TOKEN }}