Skip to content

Commit

Permalink
ci: add buf workflow (#209)
Browse files Browse the repository at this point in the history
## Description

This PR adds the [Buf](https://buf.build) support inside our GitHub
workflows. This ensures that our Proto files do not change without
notice, the liting pass and other checks. You can read more about it.

**Note**: the `breaking` CI is not passing because I removed some
imports from some files. Those imports were unused, but they now cause
some Proto files to be missing so that's why it's giving errors. Those
can be ignored as they don't break formatting, linting nor building of
the Proto files.

Closes: MILK-36

<!-- Add a description of the changes that this PR introduces and the
files that
are the most critical to review. -->

---

### Author Checklist

*All items are required. Please add a note to the item if the item is
not applicable and
please add links to any relevant follow up issues.*

I have...

- [ ] included the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR
Targeting](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building
modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [ ] included the necessary unit and integration
[tests](https://github.com/milkyway-labs/milkyway/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go
code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [ ] reviewed "Files changed" and left comments if necessary
- [ ] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable
and please add
your handle next to the items reviewed if you only reviewed selected
items.*

I have...

- [ ] confirmed the correct [type
prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json)
in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
  • Loading branch information
RiccardoM authored Dec 17, 2024
1 parent 3eaeec2 commit a5dc1b8
Show file tree
Hide file tree
Showing 61 changed files with 1,832 additions and 1,873 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/buf.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Buf CI
on:
push:
pull_request:
types: [opened, synchronize, reopened, labeled, unlabeled]
delete:

permissions:
contents: read
pull-requests: write

jobs:
buf:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4

- name: Run Buf checks 👀
uses: bufbuild/buf-action@v1
with:
token: ${{ secrets.BUF_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,11 @@ update-swagger-docs: statik
### Protobuf ###
###############################################################################

protoVer=0.14.0
bufVer=1.47.2
bufImageName=bufbuild/buf:$(bufVer)
bufImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(bufImageName)

protoVer=0.15.2
protoImageName=ghcr.io/cosmos/proto-builder:$(protoVer)
protoImage=$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace $(protoImageName)

Expand All @@ -204,10 +208,10 @@ proto-pulsar-gen:
@$(protoImage) sh ./scripts/protocgen-pulsar.sh

proto-format:
@$(protoImage) find ./ -name "*.proto" -exec clang-format -i {} \;
@$(bufImage) format -w

proto-lint:
@$(protoImage) buf lint --error-format=json ./proto
@$(bufImage) lint --error-format=json ./proto

proto-check-breaking:
@$(protoImage) buf breaking --against $(HTTPS_GIT)#branch=main
Expand Down Expand Up @@ -293,10 +297,10 @@ endif
### Benchmark ###
###############################################################################

becnchstat_cmd=golang.org/x/perf/cmd/benchstat
benchstat_cmd=golang.org/x/perf/cmd/benchstat
benchmark:
@go test -mod=readonly -bench=. -count=$(BENCH_COUNT) -run=^a ./... > bench-$(REF_NAME).txt
@test -e bench-master.txt && go run $(becnchstat_cmd) bench-master.txt bench-$(REF_NAME).txt || go run $(becnchstat_cmd) bench-$(REF_NAME).txt
@test -e bench-master.txt && go run $(benchstat_cmd) bench-master.txt bench-$(REF_NAME).txt || go run $(benchstat_cmd) bench-$(REF_NAME).txt
.PHONY: benchmark

###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion proto/buf.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Protobufs

This is the public protocol buffers API for the [MilkyWay](https://github.com/milkyway-labs/milkyway).
This is the public protocol buffers API for [MilkyWay](https://github.com/milkyway-labs/milkyway).
6 changes: 5 additions & 1 deletion proto/buf.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This module represents buf.build/milkyway-labs/milkyway
version: v1
name: buf.build/milkyway-labs/milkyway

deps:
- buf.build/cosmos/cosmos-sdk
- buf.build/cosmos/cosmos-proto
Expand All @@ -14,7 +15,7 @@ breaking:
- FILE
lint:
use:
- DEFAULT
- STANDARD
- COMMENTS
- FILE_LOWER_SNAKE_CASE
except:
Expand All @@ -23,5 +24,8 @@ lint:
- SERVICE_SUFFIX
- PACKAGE_VERSION_SUFFIX
- RPC_REQUEST_STANDARD_NAME
- RPC_RESPONSE_STANDARD_NAME
- RPC_REQUEST_RESPONSE_UNIQUE
- ENUM_NO_ALLOW_ALIAS
ignore:
- tendermint
8 changes: 5 additions & 3 deletions proto/milkyway/assets/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ option go_package = "github.com/milkyway-labs/milkyway/v3/x/assets/types";
// GenesisState defines the module's genesis state.
message GenesisState {
// Assets defines the registered assets.
repeated Asset assets = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
}
repeated Asset assets = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}
10 changes: 5 additions & 5 deletions proto/milkyway/assets/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ syntax = "proto3";
package milkyway.assets.v1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "milkyway/assets/v1/models.proto";

Expand All @@ -29,10 +29,10 @@ message MsgRegisterAsset {

// Authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// Asset represents the asset to be registered.
Asset asset = 2 [ (gogoproto.nullable) = false ];
Asset asset = 2 [(gogoproto.nullable) = false];
}

// MsgRegisterAssetResponse is the return value of MsgRegisterAsset.
Expand All @@ -47,11 +47,11 @@ message MsgDeregisterAsset {

// Authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// Denom represents the denomination of the token associated with the asset.
string denom = 2;
}

// MsgRegisterAssetResponse is the return value of MsgDeregisterAsset.
message MsgDeregisterAssetResponse {}
message MsgDeregisterAssetResponse {}
10 changes: 6 additions & 4 deletions proto/milkyway/assets/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ syntax = "proto3";
package milkyway.assets.v1;

import "amino/amino.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "milkyway/assets/v1/models.proto";

option go_package = "github.com/milkyway-labs/milkyway/v3/x/assets/types";
Expand Down Expand Up @@ -36,8 +36,10 @@ message QueryAssetsRequest {
// QueryAssetsResponse is the response type for the Query/Assets RPC method.
message QueryAssetsResponse {
// Assets represents all the assets registered.
repeated Asset assets = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
repeated Asset assets = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];

// Pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
Expand All @@ -52,5 +54,5 @@ message QueryAssetRequest {
// QueryAssetResponse is the response type for the Query/Asset RPC method.
message QueryAssetResponse {
// Asset is the asset associated with the token denomination.
Asset asset = 1 [ (gogoproto.nullable) = false ];
Asset asset = 1 [(gogoproto.nullable) = false];
}
10 changes: 4 additions & 6 deletions proto/milkyway/liquidvesting/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,20 @@ syntax = "proto3";
package milkyway.liquidvesting.v1;

import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "milkyway/liquidvesting/v1/params.proto";
import "milkyway/liquidvesting/v1/models.proto";
import "milkyway/liquidvesting/v1/params.proto";

option go_package = "github.com/milkyway-labs/milkyway/v3/x/liquidvesting/types";

// GenesisState defines the liquidvesting module's genesis state.
message GenesisState {
// Params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
Params params = 1 [(gogoproto.nullable) = false];

// BurnCoins represents the list of coins that should be burned from the
// users' balances
repeated BurnCoins burn_coins = 2 [ (gogoproto.nullable) = false ];
repeated BurnCoins burn_coins = 2 [(gogoproto.nullable) = false];

// UserInsuranceFunds represents the users' insurance fund.
repeated UserInsuranceFundEntry user_insurance_funds = 3
[ (gogoproto.nullable) = false ];
repeated UserInsuranceFundEntry user_insurance_funds = 3 [(gogoproto.nullable) = false];
}
26 changes: 12 additions & 14 deletions proto/milkyway/liquidvesting/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ syntax = "proto3";
package milkyway.liquidvesting.v1;

import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "milkyway/liquidvesting/v1/params.proto";

Expand All @@ -16,22 +16,19 @@ service Msg {

// MintLockedRepresentation defines the operation to mint a user's staked
// locked tokens representation that can be used in the liquid vesting module.
rpc MintLockedRepresentation(MsgMintLockedRepresentation)
returns (MsgMintLockedRepresentationResponse);
rpc MintLockedRepresentation(MsgMintLockedRepresentation) returns (MsgMintLockedRepresentationResponse);

// BurnLockedRepresentation defines the operation to burn a user's staked
// locked tokens representation.
rpc BurnLockedRepresentation(MsgBurnLockedRepresentation)
returns (MsgBurnLockedRepresentationResponse);
rpc BurnLockedRepresentation(MsgBurnLockedRepresentation) returns (MsgBurnLockedRepresentationResponse);

// WithdrawInsuranceFund defines the operation to withdraw an amount
// of tokens from the user's insurance fund.
// This can be used from the user to withdraw their funds after
// some of their staking representations have been burned or if the
// balance in the insurance fund is more than the required to cover all
// their staking representations.
rpc WithdrawInsuranceFund(MsgWithdrawInsuranceFund)
returns (MsgWithdrawInsuranceFundResponse);
rpc WithdrawInsuranceFund(MsgWithdrawInsuranceFund) returns (MsgWithdrawInsuranceFundResponse);

// UpdateParams defines a (governance) operation for updating the module
// parameters.
Expand All @@ -48,10 +45,10 @@ message MsgMintLockedRepresentation {
option (amino.name) = "milkyway/MsgMintLockedRepresentation";

// User that want to trigger the tokens mint.
string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// User that will receive the minted tokens.
string receiver = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string receiver = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// The amount of tokens that will be minted
repeated cosmos.base.v1beta1.Coin amount = 3 [
Expand All @@ -73,10 +70,10 @@ message MsgBurnLockedRepresentation {
option (amino.name) = "milkyway/MsgBurnLockedRepresentation";

// User that want to trigger the tokens burn.
string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// User from which we want to burn the tokens.
string user = 2 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string user = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// The amount of tokens that will be burned from the user's balance.
repeated cosmos.base.v1beta1.Coin amount = 3 [
Expand All @@ -97,7 +94,7 @@ message MsgWithdrawInsuranceFund {
option (amino.name) = "milkyway/MsgWithdrawInsuranceFund";

// User that want to withdraw the tokens.
string sender = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string sender = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// The amount of tokens that will be withdrawn from the user's insurance fund.
repeated cosmos.base.v1beta1.Coin amount = 2 [
Expand All @@ -107,6 +104,7 @@ message MsgWithdrawInsuranceFund {
];
}

// MsgWithdrawInsuranceFundResponse is the return value of MsgWithdrawInsuranceFund.
message MsgWithdrawInsuranceFundResponse {}

// MsgUpdateParams defines the message structure for the UpdateParams gRPC
Expand All @@ -125,7 +123,7 @@ message MsgUpdateParams {
// Params define the parameters to update.
//
// NOTE: All parameters must be supplied.
Params params = 2 [ (gogoproto.nullable) = false ];
Params params = 2 [(gogoproto.nullable) = false];
}

// MsgUpdateParamsResponse is the return value of MsgUpdateParams.
Expand Down
15 changes: 8 additions & 7 deletions proto/milkyway/liquidvesting/v1/models.proto
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
syntax = "proto3";
package milkyway.liquidvesting.v1;

import "amino/amino.proto";
import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/protobuf/timestamp.proto";
import "amino/amino.proto";
import "cosmos_proto/cosmos.proto";

option go_package = "github.com/milkyway-labs/milkyway/v3/x/liquidvesting/types";

Expand All @@ -25,8 +25,7 @@ message BurnCoins {
option (gogoproto.goproto_getters) = false;

// Address of who has delegated the coins.
string delegator_address = 1
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string delegator_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// CompletionTime is the unix time for unbonding completion.
google.protobuf.Timestamp completion_time = 2 [
Expand All @@ -44,15 +43,17 @@ message BurnCoins {

// BurnCoinsList represents a list of BurnCoins.
message BurnCoinsList {
repeated BurnCoins data = 1
[ (gogoproto.nullable) = false, (amino.dont_omitempty) = true ];
repeated BurnCoins data = 1 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true
];
}

// UserInsuranceFundEntry represents an entry containing the data of a user
// insurance fund.
message UserInsuranceFundEntry {
// Address of who owns the insurance fund.
string user_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
string user_address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// Amount of coins deposited into the user's insurance fund.
repeated cosmos.base.v1beta1.Coin balance = 2 [
Expand Down
8 changes: 3 additions & 5 deletions proto/milkyway/liquidvesting/v1/params.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
syntax = "proto3";
package milkyway.liquidvesting.v1;

import "gogoproto/gogo.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/milkyway-labs/milkyway/v3/x/liquidvesting/types";

Expand All @@ -23,13 +23,11 @@ message Params {

// This value represents the list of users who are authorized to execute the
// MsgBurnLockedRepresentation.
repeated string burners = 2
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
repeated string burners = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// This value represents the list of users who are authorized to execute the
// MsgMintLockedRepresentation.
repeated string minters = 3
[ (cosmos_proto.scalar) = "cosmos.AddressString" ];
repeated string minters = 3 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// List of channels from which is allowed to receive deposits to the insurance
// fund.
Expand Down
Loading

0 comments on commit a5dc1b8

Please sign in to comment.