Skip to content

Commit

Permalink
Update Buf actions (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
hariso committed Aug 19, 2024
1 parent 4dd7c5a commit 9b70f37
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 42 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/buf-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: buf-push

on:
push:
branches:
- main
paths:
- 'proto/**'

jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# This step sets up the variable steps.buf-version.outputs.v
# to contain the version of Buf (e.g. v1.36.0) from go.mod.
- name: Get Buf version
id: buf-version
run: |
BUF_VERSION=$( go list -m -f '{{.Version}}' github.com/bufbuild/buf )
# remove the leading 'v' in front of the version
BUF_VERSION=${BUF_VERSION#v}
echo "v=$BUF_VERSION" >> "$GITHUB_OUTPUT"
- uses: bufbuild/buf-action@v1
with:
version: ${{ steps.buf-version.outputs.v }}
token: ${{ secrets.BUF_TOKEN }}
input: 'proto'
# The repository should already exist.
# If it can be automatically created, that's a sign that it was deleted,
# which is likely a major issue, which we want to be aware of.
push_disable_create: true
27 changes: 27 additions & 0 deletions .github/workflows/buf-update.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: "Run 'buf update'"

on:
workflow_dispatch:
schedule:
- cron: '30 10 * * 1'

jobs:
update-buf-dependencies:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ github.token }}
steps:
- uses: actions/checkout@v4

- name: Run 'buf update'
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make install-tools proto-update
- name: Create pull request
uses: peter-evans/create-pull-request@v6.1.0
with:
title: Update Buf dependencies
body: Automatic pull request for updating Buf dependencies
branch: update-buf-dependencies
commit-message: "[automated] Update Buf dependencies"
33 changes: 33 additions & 0 deletions .github/workflows/buf-validate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: buf-validate

on:
pull_request:
# 'labeled' and 'unlabeled' are included so we can use the 'Buf Skip Breaking' label
# and skip a breaking change if that's required.
# See: https://github.com/bufbuild/buf-action?tab=readme-ov-file#skip-the-breaking-change-detection-step
types: [opened, synchronize, reopened, labeled, unlabeled]
paths:
- 'proto/**'

jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# This step sets up the variable steps.buf-version.outputs.v
# to contain the version of Buf (e.g. v1.36.0) from go.mod.
- name: Get Buf version
id: buf-version
run: |
BUF_VERSION=$( go list -m -f '{{.Version}}' github.com/bufbuild/buf )
# remove the leading 'v' in front of the version
BUF_VERSION=${BUF_VERSION#v}
echo "v=$BUF_VERSION" >> "$GITHUB_OUTPUT"
- uses: bufbuild/buf-action@v1
with:
version: ${{ steps.buf-version.outputs.v }}
token: ${{ secrets.BUF_TOKEN }}
input: 'proto'
push: false
breaking_against: '${{ github.event.repository.clone_url }}#branch=main,subdir=proto'
39 changes: 0 additions & 39 deletions .github/workflows/buf.yml

This file was deleted.

5 changes: 4 additions & 1 deletion .github/workflows/validate-generated-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ jobs:
go-version-file: 'go.mod'

- name: Check generated files
env:
BUF_TOKEN: ${{ secrets.BUF_TOKEN }}
run: |
export PATH=$PATH:$(go env GOPATH)/bin
make install-tools generate buf
make install-tools generate proto-generate
git diff
git diff --exit-code --numstat
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ install-tools:
generate:
go generate ./...

.PHONY: buf
buf:
.PHONY: proto-generate
proto-generate:
cd proto && buf generate

.PHONY: proto-update
proto-update:
cd proto && buf dep update

.PHONY: proto-lint
proto-lint:
cd proto && buf lint

0 comments on commit 9b70f37

Please sign in to comment.