Skip to content

Commit

Permalink
Update protobuf toolchain & CICD (#78)
Browse files Browse the repository at this point in the history
* Enable protobuf lint on CICD

refs oursky#40

* Adopt ignite-cli (starport) for codegen from protobuf

Ref oursky#40

* Handle proto dependencies using buf mod

Ref oursky#40

* Ignore comment rules at proto lint

Ref oursky#222

* Ignore proto enum prefix / suffix rule

Ref oursky#222

- golang already add prefix to enum type
- suffix rule is too rigid

* Adopt buf format for proto files format checking and autofix

Ref oursky#213

* Fix iscn proto format

Ref oursky#213

Co-authored-by: Rico <[email protected]>
Co-authored-by: Elliot Ng <[email protected]>
  • Loading branch information
3 people authored Jun 29, 2022
1 parent cf74a31 commit 874c89a
Show file tree
Hide file tree
Showing 18 changed files with 242 additions and 251 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/[email protected]
- name: update proto dependency
run: make proto-update-deps
- name: format-check
run: make proto-format-check
- name: lint
# TODO: Remove after fixing protobuf
if: ${{ false }}
run: make proto-lint

breakage:
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: check-breakage
# TODO: Remove after fixing protobuf
if: ${{ false }}
run: make proto-check-breaking
26 changes: 8 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ BUILDDIR ?= $(CURDIR)/build
GOPATH ?= '$(HOME)/go'
GOLANG_VERSION ?= 1.18
GOLANG_CROSS_VERSION := v$(GOLANG_VERSION)
GOGO_PROTO_URL = https://raw.githubusercontent.com/regen-network/protobuf/cosmos
COSMOS_SDK_URL = https://raw.githubusercontent.com/cosmos/cosmos-sdk/v0.43.0
COSMOS_PROTO_URL = https://raw.githubusercontent.com/regen-network/cosmos-proto/master
GOGO_PROTO_TYPES = proto/gogoproto
COSMOS_PROTO_TYPES = proto/cosmos_proto

###############################################################################
### Development ###
Expand Down Expand Up @@ -134,26 +129,21 @@ release:
### Protobuf ###
###############################################################################

proto-all: proto-format proto-lint gen-proto
proto-all: proto-update-deps proto-format proto-lint gen-proto

gen-proto: x/
./scripts/gen_proto.sh
ignite generate proto-go

proto-format:
@echo "Formatting Protobuf files"
find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;
@$(DOCKER_BUF) format -w

proto-format-check:
@$(DOCKER_BUF) format --diff --exit-code

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

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

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

@mkdir -p $(COSMOS_PROTO_TYPES)
@curl -sSL $(COSMOS_PROTO_URL)/cosmos.proto > $(COSMOS_PROTO_TYPES)/cosmos.proto
@$(DOCKER_BUF) mod update proto

.PHONY: proto-all gen-proto proto-format proto-lint proto-check-breaking
.PHONY: proto-all gen-proto proto-format proto-format-check proto-lint proto-update-deps
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
19 changes: 19 additions & 0 deletions proto/buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: cosmos
repository: cosmos-proto
commit: 1935555c206d4afb9e94615dfd0fad31
- remote: buf.build
owner: cosmos
repository: cosmos-sdk
commit: 5463f864d90d42678e5622499c08548a
- remote: buf.build
owner: cosmos
repository: gogo-proto
commit: bee5511075b7499da6178d9e4aaa628b
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 40f07f5b563941f2b20b991a7aedd53d
27 changes: 27 additions & 0 deletions proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: v1
deps:
- buf.build/cosmos/cosmos-sdk
lint:
use:
- DEFAULT
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
- UNARY_RPC
- COMMENT_FIELD
- SERVICE_SUFFIX
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
- COMMENT_RPC
- COMMENT_MESSAGE
- COMMENT_ENUM
- COMMENT_ENUM_VALUE
- ENUM_VALUE_PREFIX
- ENUM_ZERO_VALUE_SUFFIX
ignore:
- iscn
breaking:
use:
- FILE
ignore:
- iscn
5 changes: 2 additions & 3 deletions proto/iscn/genesis.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package likechain.iscn;

import "gogoproto/gogo.proto";
Expand All @@ -13,9 +14,7 @@ message GenesisState {
uint64 latest_version = 3;
}
Params params = 1 [(gogoproto.nullable) = false];
repeated ContentIdRecord content_id_records = 2 [
(gogoproto.nullable) = false
];
repeated ContentIdRecord content_id_records = 2 [(gogoproto.nullable) = false];
repeated bytes iscn_records = 3 [
(gogoproto.nullable) = false,
(gogoproto.customtype) = "IscnInput"
Expand Down
13 changes: 6 additions & 7 deletions proto/iscn/iscnid.proto
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
syntax = "proto3";

package likechain.iscn;

import "gogoproto/gogo.proto";

option go_package = "github.com/likecoin/likecoin-chain/v2/x/iscn/types";

message IscnIdPrefix {
option (gogoproto.equal) = true;
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.stringer) = false;
option (gogoproto.stringer) = false;

string registry_name = 1;
string content_id = 2;
}

message IscnId {
option (gogoproto.equal) = true;
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.stringer) = false;
option (gogoproto.stringer) = false;

IscnIdPrefix prefix = 1 [
(gogoproto.nullable) = false
];
IscnIdPrefix prefix = 1 [(gogoproto.nullable) = false];
uint64 version = 2;
}
13 changes: 6 additions & 7 deletions proto/iscn/params.proto
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
syntax = "proto3";

package likechain.iscn;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/likecoin/likecoin-chain/v2/x/iscn/types";

message Params {
option (gogoproto.equal) = false;
option (gogoproto.equal) = false;
option (gogoproto.goproto_stringer) = false;
option (gogoproto.stringer) = false;
option (gogoproto.goproto_getters) = false;
option (gogoproto.stringer) = false;
option (gogoproto.goproto_getters) = false;

string registry_name = 1;
cosmos.base.v1beta1.DecCoin fee_per_byte = 2 [
(gogoproto.nullable) = false
];
cosmos.base.v1beta1.DecCoin fee_per_byte = 2 [(gogoproto.nullable) = false];
}
10 changes: 5 additions & 5 deletions proto/iscn/query.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package likechain.iscn;

import "gogoproto/gogo.proto";
Expand Down Expand Up @@ -68,7 +69,7 @@ message QueryRecordsByIdRequest {
uint64 to_version = 3;
}

message QueryRecordsByIdResponse {
message QueryRecordsByIdResponse {
string owner = 1;
uint64 latest_version = 2;
repeated QueryResponseRecord records = 3 [(gogoproto.nullable) = false];
Expand All @@ -85,7 +86,7 @@ message QueryRecordsByFingerprintRequest {
uint64 from_sequence = 2;
}

message QueryRecordsByFingerprintResponse {
message QueryRecordsByFingerprintResponse {
repeated QueryResponseRecord records = 1 [(gogoproto.nullable) = false];

// For pagination.
Expand All @@ -102,13 +103,12 @@ message QueryRecordsByOwnerRequest {
uint64 from_sequence = 2;
}

message QueryRecordsByOwnerResponse {
message QueryRecordsByOwnerResponse {
repeated QueryResponseRecord records = 1 [(gogoproto.nullable) = false];
uint64 next_sequence = 2;
}

message QueryParamsRequest {
}
message QueryParamsRequest {}

message QueryParamsResponse {
Params params = 1 [(gogoproto.nullable) = false];
Expand Down
5 changes: 2 additions & 3 deletions proto/iscn/store.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package likechain.iscn;

import "gogoproto/gogo.proto";
Expand All @@ -7,9 +8,7 @@ import "iscn/iscnid.proto";
option go_package = "github.com/likecoin/likecoin-chain/v2/x/iscn/types";

message StoreRecord {
IscnId iscn_id = 1 [
(gogoproto.nullable) = false
];
IscnId iscn_id = 1 [(gogoproto.nullable) = false];
bytes cid_bytes = 2;
bytes data = 3 [
(gogoproto.nullable) = false,
Expand Down
16 changes: 5 additions & 11 deletions proto/iscn/tx.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
syntax = "proto3";

package likechain.iscn;

import "gogoproto/gogo.proto";
Expand All @@ -21,9 +22,7 @@ message IscnRecord {
repeated string contentFingerprints = 2;

// Here, `IscnInput` is JSON encoded bytes
repeated bytes stakeholders = 3 [
(gogoproto.customtype) = "IscnInput"
];
repeated bytes stakeholders = 3 [(gogoproto.customtype) = "IscnInput"];
bytes contentMetadata = 4 [
(gogoproto.nullable) = false,
(gogoproto.customtype) = "IscnInput"
Expand All @@ -32,9 +31,7 @@ message IscnRecord {

message MsgCreateIscnRecord {
string from = 1;
IscnRecord record = 2 [
(gogoproto.nullable) = false
];
IscnRecord record = 2 [(gogoproto.nullable) = false];
}

message MsgCreateIscnRecordResponse {
Expand All @@ -45,9 +42,7 @@ message MsgCreateIscnRecordResponse {
message MsgUpdateIscnRecord {
string from = 1;
string iscn_id = 2;
IscnRecord record = 3 [
(gogoproto.nullable) = false
];
IscnRecord record = 3 [(gogoproto.nullable) = false];
}

message MsgUpdateIscnRecordResponse {
Expand All @@ -61,5 +56,4 @@ message MsgChangeIscnRecordOwnership {
string new_owner = 3;
}

message MsgChangeIscnRecordOwnershipResponse {
}
message MsgChangeIscnRecordOwnershipResponse {}
34 changes: 0 additions & 34 deletions scripts/gen_proto.sh

This file was deleted.

46 changes: 23 additions & 23 deletions x/iscn/types/genesis.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 874c89a

Please sign in to comment.