Skip to content

Commit

Permalink
ci: Fixes protobuf linting and compliation (#935)
Browse files Browse the repository at this point in the history
* Fixes protobuf linting and compliation

* Update proto/cosmos/base/coin.proto

Co-authored-by: toteki <[email protected]>

* CHANGELOG updtes

* Update proto/umee/leverage/v1/gov.proto

Co-authored-by: Adam Wozniak <[email protected]>

* Update proto/umee/leverage/v1/leverage.proto

Co-authored-by: Adam Wozniak <[email protected]>

* Rewrote Makefile for proper linting

* Removes + ignores third_party, fixes clang_format

* Fixes github workflow for proto linting

* Makefile fix to remove sed from proto-deps

* lint++

* Fixes proto-breaking check
Migrated buf to v1
removes third_party from .gitignore
Removing unused scripts

* Update buf.work.yaml

Co-authored-by: toteki <[email protected]>

* Update proto/buf.yaml

Co-authored-by: toteki <[email protected]>

* Removing third_party from Makefile

* Update Dockerfile.protocgen

Co-authored-by: Robert Zaremba <[email protected]>

* Update Dockerfile.protocgen

Co-authored-by: Robert Zaremba <[email protected]>

* Moves generated proto files, cleans up Makefile

* adding protobuf readme

Co-authored-by: toteki <[email protected]>
Co-authored-by: Adam Wozniak <[email protected]>
Co-authored-by: Robert Zaremba <[email protected]>
  • Loading branch information
4 people authored May 26, 2022
1 parent b992fd6 commit 2bba354
Show file tree
Hide file tree
Showing 23 changed files with 505 additions and 329 deletions.
9 changes: 9 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
Language: Proto
BasedOnStyle: Google
AlignConsecutiveDeclarations: true
AlignConsecutiveAssignments: true
ColumnLimit: 0
IndentWidth: 2
...

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [913](https://github.com/umee-network/umee/pull/913) Changed update registry gov proposal to add and update tokens, but never delete them.
- [918](https://github.com/umee-network/umee/pull/918) Add MarketSummary query to CLI

### Improvements

- [935](https://github.com/umee-network/umee/pull/935) Fix protobuf linting

## [v2.0.2](https://github.com/umee-network/umee/releases/tag/v2.0.2) - 2022-05-13

### Features
Expand Down
38 changes: 21 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/make -f


BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
COMMIT := $(shell git log -1 --format='%H')
BUILD_DIR ?= $(CURDIR)/build
Expand All @@ -8,6 +9,7 @@ LEDGER_ENABLED ?= true
TM_VERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::')
DOCKER := $(shell which docker)
PROJECT_NAME = $(shell git remote get-url origin | xargs basename -s .git)
HTTPS_GIT := https://github.com/umee-network/umee.git

###############################################################################
## Version ##
Expand Down Expand Up @@ -184,31 +186,33 @@ test-sim-benchmark-invariants
## Protobuf ##
###############################################################################

DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf
#DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuild/buf:1.0.0-rc11
DOCKER_BUF := $(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf:1.4.0

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

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 tendermintdev/docker-build-proto \
find ./ -not -path "./third_party/*" -name "*.proto" -exec clang-format -i {} \; ; fi
proto-all: proto-gen proto-lint proto-check-breaking proto-format
.PHONY: proto-all proto-gen proto-lint proto-check-breaking proto-format

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 $(protoImageName) \
@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) \
sh ./contrib/scripts/protocgen.sh; fi

proto-lint:
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 ./ -name "*.proto" -exec sh -c 'clang-format -style=file -i {}' \; ; fi

proto-lint:
@echo "Linting Protobuf files"
@$(DOCKER_BUF) lint --error-format=json

proto-check-breaking:
@$(DOCKER_BUF) breaking --against https://github.com/umee-network/umee.git#branch=main
proto-check-breaking:
@echo "Checking for breaking changes"
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=brianosaurus/fix-proto-linting

.PHONY: proto-all proto-gen proto-format proto-lint proto-check-breaking
3 changes: 3 additions & 0 deletions buf.work.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version: v1
directories:
- ./proto
47 changes: 22 additions & 25 deletions contrib/scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,30 @@

set -eo pipefail

# get protoc executions
go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null
protoc_gen_go() {
if ! grep "github.com/gogo/protobuf => github.com/umee-network/umee" go.mod &>/dev/null ; then
echo -e "\tPlease run this command from somewhere inside the umee-core folder."
return 1
fi

# get cosmos sdk from github
go get github.com/cosmos/cosmos-sdk 2>/dev/null

# get the path of the cosmos-sdk repo from go/pkg/mod
cosmos_sdk_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-sdk)
proto_dirs=$(find . -path ./third_party -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null
}

cd proto
proto_dirs=$(find ./umee -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 dirname | sort | uniq)
for dir in $proto_dirs; do
# generate protobuf bind
buf protoc \
-I "proto" \
-I "$cosmos_sdk_dir/third_party/proto" \
-I "$cosmos_sdk_dir/proto" \
--gocosmos_out=plugins=interfacetype+grpc,Mgoogle/protobuf/any.proto=github.com/cosmos/cosmos-sdk/codec/types:. \
$(find "${dir}" -name '*.proto')

# generate grpc gateway
buf protoc \
-I "proto" \
-I "$cosmos_sdk_dir/third_party/proto" \
-I "$cosmos_sdk_dir/proto" \
--grpc-gateway_out=logtostderr=true:. \
$(find "${dir}" -maxdepth 1 -name '*.proto')
for file in $(find "${dir}" -maxdepth 1 -name '*.proto'); do
if grep go_package $file &> /dev/null ; then
buf generate --template buf.gen.gogo.yaml $file
fi
done
done

cp -r ./github.com/umee-network/umee/v*/x/* x/
rm -rf ./github.com
cd ..

# after the proto files have been generated add them to the the repo
# in the proper location. Then, remove the ephemeral tree used for generation
cp -r github.com/umee-network/umee/v2/* .
rm -rf github.com

go mod tidy
30 changes: 30 additions & 0 deletions proto/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Protobuf
![Logo!](../assets/umee-logo.png)

[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://img.shields.io/badge/repo%20status-WIP-yellow.svg?style=flat-square)](https://www.repostatus.org/#wip)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue?style=flat-square&logo=go)](https://godoc.org/github.com/umee-network/umee)
[![Go Report Card](https://goreportcard.com/badge/github.com/umee-network/umee?style=flat-square)](https://goreportcard.com/report/github.com/umee-network/umee)
[![Version](https://img.shields.io/github/tag/umee-network/umee.svg?style=flat-square)](https://github.com/umee-network/umee/releases/latest)
[![License: Apache-2.0](https://img.shields.io/github/license/umee-network/umee.svg?style=flat-square)](https://github.com/umee-network/umee/blob/main/LICENSE)
[![Lines Of Code](https://img.shields.io/tokei/lines/github/umee-network/umee?style=flat-square)](https://github.com/umee-network/umee)
[![GitHub Super-Linter](https://img.shields.io/github/workflow/status/umee-network/umee/Lint?style=flat-square&label=Lint)](https://github.com/marketplace/actions/super-linter)

> A Golang implementation of the Umee network, a decentralized universal capital
> facility in the Cosmos ecosystem.
Umee is a Universal Capital Facility that can collateralize assets on one blockchain
towards borrowing assets on another blockchain. The platform specializes in
allowing staked assets from PoS blockchains to be used as collateral for borrowing
across blockchains. The platform uses a combination of algorithmically determined
interest rates based on market-driven conditions. As a cross-chain DeFi protocol,
Umee will allow a multitude of decentralized debt products.

## Table of Contents

- [Protobuf](#protobuf-endpoints)

## Protobuf Endpoints

See the swagger HTTP endpoint to see how to use Umee's protobuf additions.

`http://API_HOST:API_PORT/swagger`
5 changes: 5 additions & 0 deletions proto/buf.gen.gogo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: v1
plugins:
- name: gocosmos
out: ..
opt: plugins=grpc,Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types
31 changes: 31 additions & 0 deletions proto/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
branch: main
commit: 1935555c206d4afb9e94615dfd0fad31
digest: b1-TNqW6xj2Pjha5Uoj9a-5uOeRo4mwswKfyqMcN3I_gZ0=
create_time: 2021-12-02T22:04:00.31049Z
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
branch: main
commit: af8d763f189a4482b59f9f283b446293
digest: b1-_yAm1-e1B5X3nv4-_DX5VR8YY0C_A42zokN3WshF9IE=
create_time: 2022-01-05T19:59:53.846919Z
- remote: buf.build
owner: cosmos
repository: gogo-proto
branch: main
commit: bee5511075b7499da6178d9e4aaa628b
digest: b1-rrBIustouD-S80cVoZ_rM0qJsmei9AgbXy9GPQu6vxg=
create_time: 2021-12-02T20:01:17.069307Z
- remote: buf.build
owner: googleapis
repository: googleapis
branch: main
commit: c21d9ee7a8c74d6a8cce1338a2839547
digest: b1-Rdf7A_4QeTLvu6BdzORkijdmHsAyJd2MHEEZWBEUFIM=
create_time: 2022-01-15T15:04:23.382499Z
20 changes: 20 additions & 0 deletions proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: v1
name: buf.build/umee-network/umee
deps:
- buf.build/cosmos/cosmos-sdk
- buf.build/cosmos/cosmos-proto
- buf.build/cosmos/gogo-proto
- buf.build/googleapis/googleapis
breaking:
use:
- FILE
lint:
use:
- DEFAULT
- COMMENTS
except:
- SERVICE_SUFFIX
- RPC_REQUEST_STANDARD_NAME
- COMMENT_FIELD
- FIELD_LOWER_SNAKE_CASE
- PACKAGE_DIRECTORY_MATCH
54 changes: 33 additions & 21 deletions proto/umee/leverage/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,41 +1,49 @@
syntax = "proto3";
package umeenetwork.umee.leverage.v1;

import "gogoproto/gogo.proto";
option go_package = "github.com/umee-network/umee/v2/x/leverage/types";

import "cosmos/base/v1beta1/coin.proto";
import "umee/leverage/v1/leverage.proto";

option go_package = "github.com/umee-network/umee/v2/x/leverage/types";
import "gogoproto/gogo.proto";

// GenesisState defines the x/leverage module's genesis state.
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated Token registry = 2 [(gogoproto.nullable) = false];
repeated AdjustedBorrow adjusted_borrows = 3 [(gogoproto.nullable) = false];
repeated CollateralSetting collateral_settings = 4 [(gogoproto.nullable) = false];
repeated Collateral collateral = 5 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin reserves = 6
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
int64 last_interest_time = 7;
repeated BadDebt bad_debts = 8 [(gogoproto.nullable) = false];
repeated InterestScalar interest_scalars = 9 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin utoken_supply = 10
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
Params params = 1 [(gogoproto.nullable) = false];
repeated Token registry = 2 [(gogoproto.nullable) = false];
repeated AdjustedBorrow adjusted_borrows = 3 [(gogoproto.nullable) = false];
repeated CollateralSetting collateral_settings = 4
[(gogoproto.nullable) = false];
repeated Collateral collateral = 5 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin reserves = 6 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
int64 last_interest_time = 7;
repeated BadDebt bad_debts = 8 [(gogoproto.nullable) = false];
repeated InterestScalar interest_scalars = 9 [(gogoproto.nullable) = false];
repeated cosmos.base.v1beta1.Coin utoken_supply = 10 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// AdjustedBorrow is a borrow struct used in the leverage module's genesis state.
// AdjustedBorrow is a borrow struct used in the leverage module's genesis
// state.
message AdjustedBorrow {
string address = 1;
cosmos.base.v1beta1.DecCoin amount = 2 [(gogoproto.nullable) = false];
}

// CollateralSetting is a collateral setting struct used in the leverage module's genesis state.
// CollateralSetting is a collateral setting struct used in the leverage
// module's genesis state.
message CollateralSetting {
string address = 1;
string denom = 2;
}

// Collateral is a collateral struct used in the leverage module's genesis state.
// Collateral is a collateral struct used in the leverage module's genesis
// state.
message Collateral {
string address = 1;
cosmos.base.v1beta1.Coin amount = 2 [(gogoproto.nullable) = false];
Expand All @@ -47,8 +55,12 @@ message BadDebt {
string denom = 2;
}

// InterestScalar is an interest scalar used in the leverage module's genesis state.
// InterestScalar is an interest scalar used in the leverage module's genesis
// state.
message InterestScalar {
string denom = 1;
string scalar = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}
string scalar = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
Loading

0 comments on commit 2bba354

Please sign in to comment.