Skip to content

Commit eeee6f3

Browse files
Use buf.build to manage our protobuf related activities (#2736)
* Introduce `buf.build` files * protobuf: remove google, and use buf dep * Taskfile: use `buf` instead of `protoc` * rpc: regenerate all with `buf` * Taskfile: use buf to generate docs * github: update protobuf related actions * docs: update CONTRIBUTING * buf: add COMMENT linter * Added missing comments (for linter) * Fixed punctation and capitalization of grpc comments --------- Co-authored-by: Cristian Maglie <c.maglie@arduino.cc>
1 parent a008ef0 commit eeee6f3

35 files changed

+1029
-1510
lines changed

.github/workflows/check-markdown-task.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,9 @@ jobs:
116116
- name: Install Go dependencies
117117
run: go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v1.4.1
118118

119-
- name: Install protoc compiler
120-
uses: arduino/setup-protoc@v3
119+
- uses: bufbuild/buf-action@v1
121120
with:
122-
repo-token: ${{ secrets.GITHUB_TOKEN }}
121+
setup_only: true
123122

124123
- name: Install Task
125124
uses: arduino/setup-task@v2

.github/workflows/check-mkdocs-task.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ jobs:
4444
- name: Install Go dependencies
4545
run: go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v1.4.1
4646

47-
- name: Install protoc compiler
48-
uses: arduino/setup-protoc@v3
47+
- uses: bufbuild/buf-action@v1
4948
with:
50-
repo-token: ${{ secrets.GITHUB_TOKEN }}
49+
setup_only: true
5150

5251
- name: Install Python
5352
uses: actions/setup-python@v5

.github/workflows/check-protobuf-task.yml

+11-51
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,9 @@ jobs:
5353
- name: Checkout repository
5454
uses: actions/checkout@v4
5555

56-
- name: Install Go
57-
uses: actions/setup-go@v5
56+
- uses: bufbuild/buf-action@v1
5857
with:
59-
go-version: ${{ env.GO_VERSION }}
60-
61-
- name: Install protoc compiler
62-
uses: arduino/setup-protoc@v3
63-
with:
64-
version: v26.1
65-
repo-token: ${{ secrets.GITHUB_TOKEN }}
66-
67-
- name: Install Go deps
68-
run: |
69-
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2
70-
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0
58+
setup_only: true
7159

7260
- name: Install Task
7361
uses: arduino/setup-task@v2
@@ -90,43 +78,15 @@ jobs:
9078
- name: Checkout repository
9179
uses: actions/checkout@v4
9280

93-
- name: Install Go
94-
uses: actions/setup-go@v5
95-
with:
96-
go-version: ${{ env.GO_VERSION }}
97-
98-
- name: Install buf (protoc linter)
81+
# used by the protobuf breaking change detector
82+
- name: Fetch main branch
9983
run: |
100-
go install github.com/bufbuild/buf/cmd/buf@v1.20.0
101-
go install github.com/bufbuild/buf/cmd/protoc-gen-buf-breaking@v1.20.0
102-
go install github.com/bufbuild/buf/cmd/protoc-gen-buf-lint@v1.20.0
103-
104-
- name: Install Task
105-
uses: arduino/setup-task@v2
106-
with:
107-
repo-token: ${{ secrets.GITHUB_TOKEN }}
108-
version: 3.x
109-
110-
- name: Lint protocol buffers
111-
run: task protoc:check
84+
git fetch origin master
11285
113-
check-formatting:
114-
needs: run-determination
115-
if: needs.run-determination.outputs.result == 'true'
116-
runs-on: ubuntu-latest
117-
118-
steps:
119-
- name: Checkout repository
120-
uses: actions/checkout@v4
121-
122-
- name: Install Task
123-
uses: arduino/setup-task@v2
86+
- uses: bufbuild/buf-action@v1
12487
with:
125-
repo-token: ${{ secrets.GITHUB_TOKEN }}
126-
version: 3.x
127-
128-
- name: Format protocol buffers
129-
run: task protoc:format
130-
131-
- name: Check formatting
132-
run: git diff --color --exit-code
88+
pr_comment: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository }}
89+
lint: ${{ github.event_name == 'pull_request' }}
90+
format: ${{ github.event_name == 'pull_request' }}
91+
breaking: ${{ github.event_name == 'pull_request' && !contains(github.event.pull_request.labels.*.name, 'buf skip breaking') }}
92+
breaking_against: ".git#branch=origin/master,subdir=rpc"

.github/workflows/deploy-cobra-mkdocs-versioned-poetry.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,9 @@ jobs:
6464
- name: Install Go dependencies
6565
run: go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v1.4.1
6666

67-
- name: Install protoc compiler
68-
uses: arduino/setup-protoc@v3
67+
- uses: bufbuild/buf-action@v1
6968
with:
70-
repo-token: ${{ secrets.GITHUB_TOKEN }}
69+
setup_only: true
7170

7271
- name: Install Python
7372
uses: actions/setup-python@v5

Taskfile.yml

+12-4
Original file line numberDiff line numberDiff line change
@@ -232,16 +232,19 @@ tasks:
232232
- protoc:check
233233
- protoc:format
234234
- protoc:compile
235+
- protoc:breaking-change-detection
235236

236237
protoc:compile:
237238
desc: Compile protobuf definitions
238239
cmds:
239-
- '{{ default "protoc" .PROTOC_BINARY }} --proto_path=rpc --go_out=./rpc --go_opt=paths=source_relative --go-grpc_out=./rpc --go-grpc_opt=paths=source_relative ./rpc/cc/arduino/cli/commands/v1/*.proto'
240+
- buf dep update
241+
- buf generate
240242

241243
protoc:docs:
242244
desc: Generate docs for protobuf definitions
243245
cmds:
244-
- '{{ default "protoc" .PROTOC_BINARY }} --doc_out=./docs/rpc --doc_opt=markdown,commands.md --proto_path=rpc ./rpc/cc/arduino/cli/commands/v1/*.proto'
246+
- |
247+
buf generate --template buf.doc.gen.yaml
245248
246249
docs:include-configuration-json-schema:
247250
desc: Copy configuration JSON schema to make it available in documentation
@@ -251,7 +254,7 @@ tasks:
251254
protoc:check:
252255
desc: Perform linting of the protobuf definitions
253256
cmds:
254-
- buf lint rpc
257+
- buf lint
255258

256259
protoc:collect:
257260
desc: Create a zip file containing all .proto files in DIST_DIR
@@ -263,7 +266,12 @@ tasks:
263266
protoc:format:
264267
desc: Perform formatting of the protobuf definitions
265268
cmds:
266-
- clang-format -i rpc/cc/arduino/cli/*/*/*.proto
269+
- buf format --write --exit-code
270+
271+
protoc:breaking-change-detection:
272+
desc: Detect protobuf breaking changes
273+
cmds:
274+
- buf breaking --against '.git#branch=origin/master,subdir=rpc'
267275

268276
build:
269277
desc: Build the project

buf.doc.gen.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: v2
2+
plugins:
3+
# Local plugin used to generate docs
4+
# go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v1.4.1
5+
- local: protoc-gen-doc
6+
out: ./docs/rpc
7+
opt:
8+
- markdown,commands.md
9+
inputs:
10+
- directory: ./rpc

buf.gen.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: v2
2+
plugins:
3+
# Use protoc-gen-go
4+
- remote: buf.build/protocolbuffers/go:v1.34.2
5+
out: ./rpc
6+
opt:
7+
- paths=source_relative
8+
# Use of protoc-gen-go-grpc
9+
- remote: buf.build/grpc/go:v1.5.1
10+
out: ./rpc
11+
opt:
12+
- paths=source_relative
13+
inputs:
14+
- directory: ./rpc

buf.lock

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Generated by buf. DO NOT EDIT.
2+
version: v2
3+
deps:
4+
- name: buf.build/googleapis/googleapis
5+
commit: e7f8d366f5264595bcc4cd4139af9973
6+
digest: b5:0cd69a689ee320ed815663d57d1bc3a1d6823224a7a717d46fee3a68197c25a6f5f932c0b0e49f8370c70c247a6635969a6a54af5345cafd51e0667298768aca

buf.yaml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: v2
2+
deps:
3+
- buf.build/googleapis/googleapis:e7f8d366f5264595bcc4cd4139af9973
4+
breaking:
5+
use:
6+
- FILE
7+
lint:
8+
use:
9+
- STANDARD
10+
- COMMENT_ENUM
11+
- COMMENT_ENUM_VALUE
12+
- COMMENT_FIELD
13+
- COMMENT_RPC
14+
- COMMENT_SERVICE
15+
ignore_only:
16+
ENUM_ZERO_VALUE_SUFFIX:
17+
- rpc/cc/arduino/cli/commands/v1/lib.proto
18+
modules:
19+
- path: rpc

docs/CONTRIBUTING.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,7 @@ If you want to run integration tests you will also need:
7979

8080
If you're working on the gRPC interface you will also have to:
8181

82-
- download and install the [protoc][6] compiler (use the version required to match the generated code, please note that
83-
the latest releases does not follow semantic versioning anymore so, for example, the version 5.26.1 must be searched
84-
as 26.1 dropping the major number)
85-
- install `protoc-gen-go` using: `go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.2` (use the version
86-
required to match the generated code)
87-
- install `protoc-gen-go-grpc` using: `go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.3.0` (use the version
88-
required to match the generated code)
82+
- download and install [buf][6] our tool to compile and generate proto files
8983

9084
### Building the source code
9185

@@ -337,7 +331,7 @@ If your PR doesn't need to be included in the changelog, please start the commit
337331
[1]: https://go.dev/doc/install
338332
[2]: https://taskfile.dev/#/installation
339333
[3]: https://www.python.org/downloads/
340-
[6]: https://github.com/protocolbuffers/protobuf/releases
334+
[6]: https://buf.build/docs/installation/
341335
[7]: https://pages.github.com/
342336
[9]: https://www.mkdocs.org/
343337
[11]: https://github.com/arduino/arduino-cli/blob/master/.github/workflows/deploy-cobra-mkdocs-versioned-poetry.yml

rpc/buf.yaml

-7
This file was deleted.

rpc/cc/arduino/cli/commands/v1/board.pb.go

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)