Skip to content

Commit

Permalink
Update to v2 (#70)
Browse files Browse the repository at this point in the history
Update examples to use `v2` configurations throughout. This also updates
the Github Actions to follow `v1` instead of managing them explicitly.
  • Loading branch information
doriable authored Oct 16, 2024
1 parent 5a27533 commit c65923b
Show file tree
Hide file tree
Showing 45 changed files with 1,486 additions and 916 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/buf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
with:
github_token: ${{ github.token }}
- uses: bufbuild/[email protected]
- uses: bufbuild/buf-action@v1
with:
input: 'limit-output-types'
buf_token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-push-action@v1.1.1
token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-action@v1
with:
input: 'linting/bad'
buf_token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-push-action@v1.1.1
token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-action@v1
with:
input: 'linting/good'
buf_token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-push-action@v1.1.1
token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-action@v1
with:
input: 'workspace/observabilitytypes'
buf_token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-push-action@v1.1.1
token: ${{ secrets.BUF_TOKEN }}
- uses: bufbuild/buf-action@v1
with:
input: 'workspace/observabilityapi'
buf_token: ${{ secrets.BUF_TOKEN }}
token: ${{ secrets.BUF_TOKEN }}
19 changes: 3 additions & 16 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,10 @@ jobs:
lint-and-breaking-change-detection:
runs-on: ubuntu-latest
steps:
# Run `git checkout`
- name: Checkout
uses: actions/checkout@v4
# Install the `buf` CLI
- name: Setup
uses: bufbuild/[email protected]
with:
github_token: ${{ github.token }}
# Lint the Buf module in the `github-actions` directory
- name: Lint
uses: bufbuild/buf-lint-action@v1
with:
input: github-actions
# Detect breaking changes for the Buf module in the `github-actions` directory
# against the current `main` branch
- name: Breaking change detection against `main`
uses: bufbuild/buf-breaking-action@v1
- name: Buf Action
uses: bufbuild/buf-action@v1
with:
input: github-actions
against: https://github.com/bufbuild/buf-examples.git#branch=main,ref=HEAD~1,subdir=github-actions
token: ${{ secrets.BUF_TOKEN }}
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ This repo houses example projects for learning how to use [Buf]. For more inform

## Version

The examples in this repo currently use version [1.8.0][version] of the [`buf` CLI][cli].
The examples in this repo use [v2 `buf.yaml`][v2-buf-yaml] and [v2 `buf.gen.yaml`][v2-buf-gen-yaml]
configurations. All examples require the `buf` CLI at version [v1.32.0][min-version] or higher.

## Projects

Project | Directory | Category
:-------|:----------|:--------
Buf [workspace] | [`workspace-modules`](./workspace) | Code organization
Buf [workspace] | [`workspace`](./workspace) | Code organization
[Linting][lint] Protobuf sources | [`linting`](./linting) | Maintenance
[Breaking change detection][breaking] | [`breaking-change-detection`](./breaking-change-detection) | Maintenance
[Remote plugin execution][remote] | [`plugin-execution-remote`](./plugin-execution-remote) | Code generation
Expand All @@ -36,5 +37,7 @@ Several of these projects available as modules on the [Buf Schema Registry][bsr]
[modules]: https://docs.buf.build/bsr/overview#modules
[plugin]: https://docs.buf.build/bsr/remote-generation/concepts#plugins
[remote]: https://docs.buf.build/bsr/remote-generation/remote-plugin-execution
[version]: https://github.com/bufbuild/buf/releases/tag/v1.8.0
[workspace]: https://docs.buf.build/reference/workspaces
[min-version]: https://github.com/bufbuild/buf/releases/tag/v1.32.0
[v2-buf-yaml]: https://buf.build/docs/configuration/v2/buf-yaml
[v2-buf-gen-yaml]: https://buf.build/docs/configuration/v2/buf-gen-yaml
1 change: 1 addition & 0 deletions breaking-change-detection/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Breaking change detection

> [!NOTE]
> You need to have the [`buf` CLI][install] installed to follow along with this example.
This project shows Buf [breaking change detection][breaking] in action. There are three different [Buf inputs][inputs] in play here:
Expand Down
15 changes: 11 additions & 4 deletions breaking-change-detection/compatible/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
version: v1
version: v2
name: buf.build/acme/weather
breaking:
use:
- FILE
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
15 changes: 11 additions & 4 deletions breaking-change-detection/incompatible/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
version: v1
version: v2
name: buf.build/acme/weather
breaking:
use:
- FILE
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
15 changes: 11 additions & 4 deletions breaking-change-detection/initial/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
version: v1
version: v2
name: buf.build/acme/weather
breaking:
use:
- FILE
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
13 changes: 3 additions & 10 deletions github-actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

[![GitHub Actions](https://github.com/bufbuild/buf-examples/workflows/CI/badge.svg)](https://github.com/bufbuild/buf-examples/actions?workflow=CI)

This example project shows you how to use Buf in a [GitHub Actions][actions] setting. The Actions pipeline here involves three Buf-specific GitHub Actions:

* [`buf-setup-action`][buf-setup] installs the [`buf` CLI][cli]
* [`buf-lint-action`][buf-lint] [lints][lint] this Protobuf module
* [`buf-breaking-action`][buf-breaking] runs [breaking change detection][breaking] against the current `main` branch
This example project shows you how to use Buf in a [GitHub Actions][actions] setting.
This uses the [Buf Action][buf-action].

> The configuration for [GitHub Actions][actions] is in the [`.github`](../.github) directory in the root, as that's where GitHub expects it to be.
[actions]: https://docs.github.com/actions
[breaking]: https://docs.buf.build/breaking
[buf-breaking]: https://github.com/bufbuild/buf-breaking-action
[buf-lint]: https://github.com/bufbuild/buf-lint-action
[buf-setup]: https://github.com/bufbuild/buf-setup-action
[buf-action]: https://github.com/marketplace/actions/buf-action
[cli]: https://github.com/bufbuild/buf
[lint]: https://docs.buf.build/lint
3 changes: 0 additions & 3 deletions github-actions/buf.work.yaml

This file was deleted.

16 changes: 16 additions & 0 deletions github-actions/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: v2
modules:
- path: proto
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
7 changes: 0 additions & 7 deletions github-actions/proto/buf.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions limit-output-types/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Limit types

> You need to install the [`buf` CLI][install] and [jq] to follow along with this example. Requires
> v1.1.0 or above.
> [!NOTE]
> You need to install the [`buf` CLI][install] and [jq] to follow along with this example.
The [`buf build`][build] command creates a [Buf image][image] (or
[`FileDescriptorSet`][filedescriptorset]) out of a [Buf input][input]. By default, the image or
Expand Down
15 changes: 11 additions & 4 deletions limit-output-types/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
version: v1
version: v2
name: buf.build/buf-examples/limit-output-types
breaking:
use:
- FILE
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
3 changes: 2 additions & 1 deletion linting/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Protobuf linting

> [!NOTE]
> You need to have the [`buf` CLI][install] installed to follow along with this example.
Buf enables you to [lint] Protobuf sources in accordance with [lint rules][rules] that you specify in your [`buf.yaml`][buf-yaml] configuration file. This project shows linting in action with two different [Buf inputs][inputs]:
Expand Down Expand Up @@ -50,7 +51,7 @@ buf lint ./good
[bsr]: https://docs.buf.build/bsr
[bsr-bad]: https://buf.build/buf-examples/linting-bad
[bsr-good]: https://buf.build/buf-examples/linting-good
[buf-yaml]: https://docs.buf.build/configuration/v1/buf-yaml
[buf-yaml]: https://docs.buf.build/configuration/v2/buf-yaml
[default]: https://docs.buf.build/lint/rules#default
[inputs]: https://docs.buf.build/reference/inputs
[install]: https://docs.buf.build/installation
Expand Down
7 changes: 3 additions & 4 deletions linting/bad/buf.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v1
version: v2
deps:
- remote: buf.build
owner: googleapis
repository: googleapis
- name: buf.build/googleapis/googleapis
commit: 783e4b5374fa488ab068d08af9658438
digest: b5:2d674e2936711677a6c4572193f1cfb204f28f01366d570b617bf308fa59869f64be0407880451df2888cc371c7e1069b813c5450b4d8719d639c4a4f7889efe
15 changes: 11 additions & 4 deletions linting/bad/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
version: v1
version: v2
name: buf.build/buf-examples/linting-bad
deps:
- buf.build/googleapis/googleapis:783e4b5374fa488ab068d08af9658438
breaking:
use:
- FILE
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
7 changes: 3 additions & 4 deletions linting/good/buf.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by buf. DO NOT EDIT.
version: v1
version: v2
deps:
- remote: buf.build
owner: googleapis
repository: googleapis
- name: buf.build/googleapis/googleapis
commit: 783e4b5374fa488ab068d08af9658438
digest: b5:2d674e2936711677a6c4572193f1cfb204f28f01366d570b617bf308fa59869f64be0407880451df2888cc371c7e1069b813c5450b4d8719d639c4a4f7889efe
15 changes: 11 additions & 4 deletions linting/good/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
version: v1
version: v2
name: buf.build/buf-examples/linting-good
deps:
- buf.build/googleapis/googleapis:783e4b5374fa488ab068d08af9658438
breaking:
use:
- FILE
lint:
use:
- DEFAULT
except:
- FIELD_NOT_REQUIRED
- PACKAGE_NO_IMPORT_CYCLE
disallow_comment_ignores: true
breaking:
use:
- FILE
except:
- EXTENSION_NO_DELETE
- FIELD_SAME_DEFAULT
2 changes: 1 addition & 1 deletion managed-mode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ When you run this command, the `buf` CLI uses the configuration in [`buf.gen.yam
* [Ruby](./gen/proto/ruby)

[arena]: https://developers.google.com/protocol-buffers/docs/reference/arenas
[buf-gen-yaml]: https://docs.buf.build/configuration/v1/buf-gen-yaml#managed
[buf-gen-yaml]: https://docs.buf.build/configuration/v2/buf-gen-yaml#managed
[install]: https://docs.buf.build/installation
[managed]: https://docs.buf.build/generate/managed-mode
[plugins]: https://docs.buf.build/bsr/remote-generation/overview#hosted-plugins
Expand Down
42 changes: 21 additions & 21 deletions managed-mode/buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
version: v1
version: v2
managed:
enabled: true
optimize_for: CODE_SIZE

# C++
cc_enable_arenas: true

# Go
go_package_prefix:
default: github.com/acme/weather/v1

# Java
java_multiple_files: false
java_package_prefix: io
java_string_check_utf8: false
override:
- file_option: cc_enable_arenas
value: true
- file_option: java_multiple_files
value: false
- file_option: java_string_check_utf8
value: false
- file_option: java_package_prefix
value: io
- file_option: optimize_for
value: CODE_SIZE
- file_option: go_package_prefix
value: github.com/acme/weather/v1
plugins:
- plugin: buf.build/protocolbuffers/cpp
- remote: buf.build/protocolbuffers/cpp
out: gen/proto/cpp
- plugin: buf.build/protocolbuffers/csharp
- remote: buf.build/protocolbuffers/csharp
out: gen/proto/csharp
- plugin: buf.build/protocolbuffers/go
- remote: buf.build/protocolbuffers/go
out: gen/proto/go
- plugin: buf.build/protocolbuffers/java
- remote: buf.build/protocolbuffers/java
out: gen/proto/java
- plugin: buf.build/protocolbuffers/objc
- remote: buf.build/protocolbuffers/objc
out: gen/proto/objc
- plugin: buf.build/protocolbuffers/php
- remote: buf.build/protocolbuffers/php
out: gen/proto/php
- plugin: buf.build/protocolbuffers/ruby
- remote: buf.build/protocolbuffers/ruby
out: gen/proto/ruby
Loading

0 comments on commit c65923b

Please sign in to comment.