Skip to content

Commit 17f99d7

Browse files
committed
feat(proto): add Buf Schema Registry support
Add Buf (https://buf.build) support for managing and publishing myshoes protobuf definitions to Buf Schema Registry (BSR). Changes: - Add api/proto/buf.yaml for Buf configuration with lint rules - Add api/proto/buf.gen.yaml for code generation settings - Add .github/workflows/buf.yaml for CI/CD integration - Update Makefile to use buf for proto code generation - Add .buf/ to .gitignore - Regenerate proto.go files using buf generate This allows other projects (shoes plugins) to depend on myshoes proto definitions via BSR. Manual steps required: 1. Create buf.build account and repository (buf.build/whywaita/myshoes) 2. Add BUF_TOKEN to GitHub Secrets 3. Run: cd api/proto && buf push prompt: Implement the following plan: # myshoes proto を Buf Cloud (BSR) に公開する計画 ---- 計画内容を実装します。まず、タスクを整理してから作業を開始します。 実装が完了しました。以下のファイルを作成・更新しました: ## 作成したファイル 1. **api/proto/buf.yaml** - Buf の設定ファイル(lint と breaking change のルールを定義) 2. **api/proto/buf.gen.yaml** - コード生成の設定ファイル 3. **.github/workflows/buf.yaml** - GitHub Actions ワークフロー ## 更新したファイル 1. **Makefile** - `build-proto` を buf ベースに変更、`lint-proto` ターゲットを追加 2. **.gitignore** - `.buf/` を追加 3. **api/proto.go/myshoes.pb.go** - buf generate で再生成(protoc バージョン表示のみ変更) 4. **api/proto.go/myshoes_grpc.pb.go** - buf generate で再生成(protoc バージョン表示のみ変更) ## 動作確認 - `buf lint` - エラーなし - `buf build` - 成功 - `make build` - 成功 - `make test` - すべてのテストが成功 ## 次のステップ(手動作業が必要) BSR に公開するためには、以下の手順を手動で行う必要があります: 1. **BSR アカウントのセットアップ** - https://buf.build でアカウントを作成 - リポジトリ `buf.build/whywaita/myshoes` を作成 - API トークンを取得 - GitHub の Settings → Secrets and variables → Actions で `BUF_TOKEN` を登録 2. **初回プッシュ** \`\`\`bash cd api/proto && buf push \`\`\` 3. **他のプロジェクトからの利用** 公開後、他のプロジェクトは以下のように依存できます: \`\`\`yaml # 依存先の buf.yaml version: v2 deps: - buf.build/whywaita/myshoes \`\`\`
1 parent d20faef commit 17f99d7

File tree

7 files changed

+56
-9
lines changed

7 files changed

+56
-9
lines changed

.github/workflows/buf.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Buf
2+
on:
3+
push:
4+
branches: [master]
5+
paths: ['api/proto/**']
6+
pull_request:
7+
paths: ['api/proto/**']
8+
9+
jobs:
10+
buf:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: bufbuild/buf-action@v1
15+
with:
16+
token: ${{ secrets.BUF_TOKEN }}
17+
input: api/proto
18+
push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,7 @@ Temporary Items
157157

158158
# End of https://www.toptal.com/developers/gitignore/api/macos,intellij,go
159159

160-
/myshoes*
160+
/myshoes*
161+
162+
# Buf
163+
.buf/

Makefile

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ build-linux: ## Build for Linux
1717
make build-proto
1818
GOOS=linux GOARCH=amd64 go build -o myshoes-linux-amd64 -ldflags $(BUILD_LDFLAGS) cmd/server/cmd.go
1919

20-
build-proto: ## Build proto file
21-
mkdir -p tmp/proto-go
22-
rm -rf api/proto.go
20+
build-proto: ## Build proto file with buf
21+
cd api/proto && buf generate
2322

24-
protoc -I=api/proto/ --go_out=tmp/proto-go/ --go-grpc_out=tmp/proto-go/ api/proto/**.proto
25-
mv tmp/proto-go/github.com/whywaita/myshoes/api/proto.go api/
26-
rm -rf tmp
23+
lint-proto: ## Lint proto files
24+
cd api/proto && buf lint
2725

2826
test: ## Exec test
2927
go test -v ./...

api/proto.go/myshoes.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/proto.go/myshoes_grpc.pb.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/proto/buf.gen.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: v2
2+
clean: true
3+
plugins:
4+
- remote: buf.build/protocolbuffers/go
5+
out: ../proto.go
6+
opt:
7+
- paths=source_relative
8+
- remote: buf.build/grpc/go
9+
out: ../proto.go
10+
opt:
11+
- paths=source_relative

api/proto/buf.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: v2
2+
modules:
3+
- path: .
4+
name: buf.build/whywaita/myshoes
5+
lint:
6+
use:
7+
- STANDARD
8+
except:
9+
- PACKAGE_DIRECTORY_MATCH
10+
- ENUM_ZERO_VALUE_SUFFIX
11+
- PACKAGE_VERSION_SUFFIX
12+
- SERVICE_SUFFIX
13+
- ENUM_VALUE_PREFIX
14+
- ENUM_VALUE_UPPER_SNAKE_CASE
15+
breaking:
16+
use:
17+
- FILE

0 commit comments

Comments
 (0)