Skip to content

Commit

Permalink
chore: update protobuf generation to latest buf changes (cosmos#2705)
Browse files Browse the repository at this point in the history
* updating buf proto generation setup

* revert adding test msg type

* updating proto-swagger-gen configs

* updating to latest proto builder image

* downgrade to 0.46 support

* go mod tidy e2e

* cleanup makefile

* rerun make proto-update-deps

* updating buf yaml

* updating cosmos/gogo-proto pin

* regenerate protos

* go mod tidy e2e

* removing pulsar buf yaml

* Update proto/buf.yaml

* adding proto-registry.yml workflow for buf push to BSR
  • Loading branch information
damiannolan authored Nov 9, 2022
1 parent 48321ff commit cd228d1
Show file tree
Hide file tree
Showing 41 changed files with 765 additions and 1,792 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/proto-registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Buf-Push
# Protobuf runs buf (https://buf.build/) push updated proto files to https://buf.build/cosmos/ibc
# This workflow is only run when a .proto file has been changed
on:
push:
branches:
- main
paths:
- "proto/**"

jobs:
push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: bufbuild/buf-setup-action@v1.9.0
- uses: bufbuild/buf-push-action@v1
with:
input: "proto"
buf_token: ${{ secrets.BUF_TOKEN }}
90 changes: 19 additions & 71 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ SIMAPP = ./testing/simapp
MOCKS_DIR = $(CURDIR)/tests/mocks
HTTPS_GIT := https://github.com/cosmos/ibc-go.git
DOCKER := $(shell which docker)
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc8
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.9.0
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)

export GO111MODULE = on

Expand Down Expand Up @@ -302,90 +303,37 @@ format:
### Protobuf ###
###############################################################################

containerProtoVer=v0.2
containerProtoImage=tendermintdev/sdk-proto-gen:$(containerProtoVer)
containerProtoGen=cosmos-sdk-proto-gen-$(containerProtoVer)
containerProtoGenSwagger=cosmos-sdk-proto-gen-swagger-$(containerProtoVer)
containerProtoFmt=cosmos-sdk-proto-fmt-$(containerProtoVer)
protoVer=v0.7
protoImageName=tendermintdev/sdk-proto-gen:$(protoVer)
containerProtoGen=$(PROJECT_NAME)-proto-gen-$(protoVer)
containerProtoGenSwagger=$(PROJECT_NAME)-proto-gen-swagger-$(protoVer)
containerProtoFmt=$(PROJECT_NAME)-proto-fmt-$(protoVer)

proto-all: proto-format proto-lint proto-gen

proto-format:
@echo "Formatting Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoFmt}$$"; then docker start -a $(containerProtoFmt); else docker run --name $(containerProtoFmt) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
find ./ -name "*.proto" -exec clang-format -i {} \; ; fi

proto-lint:
@$(DOCKER_BUF) lint --error-format=json

proto-gen:
@echo "Generating Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGen}$$"; then docker start -a $(containerProtoGen); else docker run --name $(containerProtoGen) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protocgen.sh; fi

proto-format:
@echo "Formatting Protobuf files"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoFmt}$$"; then docker start -a $(containerProtoFmt); else docker run --name $(containerProtoFmt) -v $(CURDIR):/workspace --workdir /workspace tendermintdev/docker-build-proto \
find ./ -not -path "./third_party/*" -name "*.proto" -exec clang-format -i {} \; ; fi

proto-swagger-gen:
@echo "Generating Protobuf Swagger"
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGenSwagger}$$"; then docker start -a $(containerProtoGenSwagger); else docker run --name $(containerProtoGenSwagger) -v $(CURDIR):/workspace --workdir /workspace $(containerProtoImage) \
@if docker ps -a --format '{{.Names}}' | grep -Eq "^${containerProtoGenSwagger}$$"; then docker start -a $(containerProtoGenSwagger); else docker run --name $(containerProtoGenSwagger) -v $(CURDIR):/workspace --workdir /workspace $(protoImageName) \
sh ./scripts/protoc-swagger-gen.sh; fi

proto-lint:
@$(DOCKER_BUF) lint --error-format=json

proto-check-breaking:
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=main

TM_URL = https://raw.githubusercontent.com/tendermint/tendermint/v0.34.20/proto/tendermint
GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos
CONFIO_URL = https://raw.githubusercontent.com/confio/ics23/v0.7.1
SDK_PROTO_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.46.0/proto/cosmos

TM_CRYPTO_TYPES = third_party/proto/tendermint/crypto
TM_ABCI_TYPES = third_party/proto/tendermint/abci
TM_TYPES = third_party/proto/tendermint/types
TM_VERSION = third_party/proto/tendermint/version
TM_LIBS = third_party/proto/tendermint/libs/bits
TM_P2P = third_party/proto/tendermint/p2p

SDK_QUERY = third_party/proto/cosmos/base/query/v1beta1
SDK_BASE = third_party/proto/cosmos/base/v1beta1
SDK_UPGRADE = third_party/proto/cosmos/upgrade

GOGO_PROTO_TYPES = third_party/proto/gogoproto
CONFIO_TYPES = third_party/proto

proto-update-deps:
@mkdir -p $(GOGO_PROTO_TYPES)
@curl -sSL $(GOGO_PROTO_URL)/gogoproto/gogo.proto > $(GOGO_PROTO_TYPES)/gogo.proto

@mkdir -p $(SDK_QUERY)
@curl -sSL $(SDK_PROTO_URL)/base/query/v1beta1/pagination.proto > $(SDK_QUERY)/pagination.proto

@mkdir -p $(SDK_BASE)
@curl -sSL $(SDK_PROTO_URL)/base/v1beta1/coin.proto > $(SDK_BASE)/coin.proto

@mkdir -p $(SDK_UPGRADE)
@curl -sSL $(SDK_PROTO_URL)/upgrade/v1beta1/upgrade.proto > $(SDK_UPGRADE)/v1beta1/upgrade.proto

## Importing of tendermint protobuf definitions currently requires the
## use of `sed` in order to build properly with cosmos-sdk's proto file layout
## (which is the standard Buf.build FILE_LAYOUT)
## Issue link: https://github.com/tendermint/tendermint/issues/5021
@mkdir -p $(TM_TYPES)
@curl -sSL $(TM_URL)/types/types.proto > $(TM_TYPES)/types.proto
@curl -sSL $(TM_URL)/types/validator.proto > $(TM_TYPES)/validator.proto

@mkdir -p $(TM_VERSION)
@curl -sSL $(TM_URL)/version/types.proto > $(TM_VERSION)/types.proto

@mkdir -p $(TM_LIBS)
@curl -sSL $(TM_URL)/libs/bits/types.proto > $(TM_LIBS)/types.proto

@mkdir -p $(TM_CRYPTO_TYPES)
@curl -sSL $(TM_URL)/crypto/proof.proto > $(TM_CRYPTO_TYPES)/proof.proto
@curl -sSL $(TM_URL)/crypto/keys.proto > $(TM_CRYPTO_TYPES)/keys.proto

@mkdir -p $(CONFIO_TYPES)
@curl -sSL $(CONFIO_URL)/proofs.proto > $(CONFIO_TYPES)/proofs.proto

## insert go package option into proofs.proto file
## Issue link: https://github.com/confio/ics23/issues/32
@perl -lp -i -e 'print q(option go_package = "github.com/confio/ics23/go";) if $$. == 4' $(CONFIO_TYPES)/proofs.proto
@echo "Updating Protobuf dependencies"
@cd proto && buf mod update

.PHONY: proto-all proto-gen proto-gen-any proto-swagger-gen proto-format proto-lint proto-check-breaking proto-update-deps
3 changes: 1 addition & 2 deletions buf.work.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
# previous "buf.yaml" configuration.
version: v1
directories:
- proto
- third_party/proto
- proto
Loading

0 comments on commit cd228d1

Please sign in to comment.