Skip to content

Commit c20887d

Browse files
committed
fix: add proto dir
1 parent 1b9ccc9 commit c20887d

File tree

8 files changed

+216
-14
lines changed

8 files changed

+216
-14
lines changed

.github/workflows/proto.yml

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Protobuf
2-
# Protobuf runs buf (https://buf.build/) lint and check-breakage
2+
# Protobuf runs buf[](https://buf.build/) lint and check-breakage
33
# This workflow is only run when a .proto file has been changed
44
on:
55
pull_request:
@@ -14,36 +14,89 @@ jobs:
1414
timeout-minutes: 5
1515
steps:
1616
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
1719
- uses: technote-space/get-diff-action@f27caffdd0fb9b13f4fc191c016bb4e0632844af # v6
1820
with:
1921
PATTERNS: |
2022
**/**.proto
23+
- uses: bufbuild/buf-setup-action@v1
24+
with:
25+
version: 1.41.0
26+
github_token: ${{ secrets.GITHUB_TOKEN }}
27+
- name: Update Buf Dependencies
28+
if: env.GIT_DIFF
29+
run: |
30+
cd proto
31+
buf dep update
2132
- name: lint
2233
run: make proto-lint
2334
if: env.GIT_DIFF
2435
breakage:
2536
runs-on: ubuntu-latest
2637
steps:
2738
- uses: actions/checkout@v3
39+
with:
40+
fetch-depth: 0
2841
- uses: technote-space/get-diff-action@f27caffdd0fb9b13f4fc191c016bb4e0632844af # v6
2942
with:
3043
PATTERNS: |
3144
**/**.proto
45+
- name: Check if proto files exist on base branch
46+
id: check_base_proto
47+
if: env.GIT_DIFF
48+
run: |
49+
if git ls-tree -r origin/${{ github.event.pull_request.base.ref }} -- proto | grep -q '\.proto$'; then
50+
echo "has_proto=true" >> $GITHUB_OUTPUT
51+
else
52+
echo "has_proto=false" >> $GITHUB_OUTPUT
53+
fi
54+
- uses: bufbuild/buf-setup-action@v1
55+
if: env.GIT_DIFF && steps.check_base_proto.outputs.has_proto == 'true'
56+
with:
57+
version: 1.41.0
58+
github_token: ${{ secrets.GITHUB_TOKEN }}
59+
- name: Update Buf Dependencies
60+
if: env.GIT_DIFF && steps.check_base_proto.outputs.has_proto == 'true'
61+
run: |
62+
cd proto
63+
buf dep update
3264
- name: check-breakage
65+
if: env.GIT_DIFF && steps.check_base_proto.outputs.has_proto == 'true'
3366
run: make proto-check-breaking
34-
if: env.GIT_DIFF
67+
env:
68+
BUF_BREAKING_AGAINST: origin/${{ github.event.pull_request.base.ref }}
3569
protogen:
3670
runs-on: ubuntu-latest
3771
steps:
3872
- uses: actions/checkout@v3
73+
with:
74+
fetch-depth: 0
3975
- uses: technote-space/get-diff-action@f27caffdd0fb9b13f4fc191c016bb4e0632844af # v6
4076
with:
4177
PATTERNS: |
4278
**/**.proto
79+
- uses: bufbuild/buf-setup-action@v1
80+
with:
81+
version: 1.41.0
82+
github_token: ${{ secrets.GITHUB_TOKEN }}
83+
- name: Install Go
84+
if: env.GIT_DIFF
85+
uses: actions/setup-go@v5
86+
with:
87+
go-version: '1.21'
88+
- name: Install Proto Plugins
89+
if: env.GIT_DIFF
90+
run: go install github.com/cosmos/gogo-proto/protoc-gen-gogofaster@v1.4.11
91+
- name: Update Buf Dependencies
92+
if: env.GIT_DIFF
93+
run: |
94+
cd proto
95+
buf dep update
4396
- name: proto-gen-ci
4497
if: env.GIT_DIFF
4598
run: |
4699
make proto-gen-ci # proto-swagger-gen FIXME swagger-gen result is not reproducible in CI
47100
git checkout -- go.mod go.sum # FIXME doc gen not reproducible in CI
48101
- name: check working directory is clean
49-
uses: numtide/clean-git-action@30e3d6d6e2d6e77e73761cf5324467cb74386f87 # v2
102+
uses: numtide/clean-git-action@30e3d6d6e2d6e77e73761cf5324467cb74386f87 # v2

Makefile

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11
COVERAGE ?= coverage.txt
2-
3-
.PHONY: all build test clean
2+
GO ?= go
3+
GOBIN ?= $(shell $(GO) env GOBIN)
4+
ifeq ($(strip $(GOBIN)),)
5+
GOBIN := $(shell $(GO) env GOPATH)/bin
6+
endif
7+
BUF_VERSION ?= v1.41.0
8+
BUF_BIN ?= $(GOBIN)/buf
9+
PROTO_DIR ?= proto
10+
BUF_BREAKING_AGAINST ?= origin/main
11+
12+
BUF := $(shell command -v buf 2>/dev/null)
13+
ifeq ($(strip $(BUF)),)
14+
BUF := $(BUF_BIN)
15+
endif
16+
17+
.PHONY: all build test clean fmt vet \
18+
proto-lint proto-gen proto-gen-ci proto-check-breaking buf-install
419

520
all: build
621

722
build: build-memiavl build-store build-versiondb
823

924
build-memiavl:
10-
@cd memiavl && go build -mod=readonly -tags=objstore ./...
25+
@cd memiavl && $(GO) build -mod=readonly -tags=objstore ./...
1126

1227
build-store:
13-
@cd store && go build -mod=readonly -tags=objstore ./...
28+
@cd store && $(GO) build -mod=readonly -tags=objstore ./...
1429

1530
build-versiondb:
16-
@cd versiondb && go build -mod=readonly -tags=objstore ./...
31+
@cd versiondb && $(GO) build -mod=readonly -tags=objstore ./...
1732

1833

1934
test: test-memiavl test-store test-versiondb
2035

2136
test-memiavl:
22-
@cd memiavl && go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;
37+
@cd memiavl && $(GO) test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;
2338

2439
test-store:
25-
@cd store && go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;
40+
@cd store && $(GO) test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;
2641

2742
test-versiondb:
28-
@cd versiondb && go test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;
43+
@cd versiondb && $(GO) test -tags=objstore -v -mod=readonly ./... -coverprofile=$(COVERAGE) -covermode=atomic;
2944

3045
clean: clean-memiavl clean-store clean-versiondb
3146

@@ -36,10 +51,27 @@ clean-store:
3651
@cd store && go clean
3752

3853
clean-versiondb:
39-
@cd versiondb && go clean
54+
@cd versiondb && $(GO) clean
4055

4156
fmt:
42-
go fmt ./memiavl/... ./store/... ./versiondb/...
57+
$(GO) fmt ./memiavl/... ./store/... ./versiondb/...
4358

4459
vet:
45-
go vet ./memiavl/... ./store/... ./versiondb/...
60+
$(GO) vet ./memiavl/... ./store/... ./versiondb/...
61+
62+
buf-install:
63+
@if ! command -v buf >/dev/null 2>&1 && [ ! -x "$(BUF_BIN)" ]; then \
64+
echo "Installing buf $(BUF_VERSION)"; \
65+
GOBIN=$(GOBIN) $(GO) install github.com/bufbuild/buf/cmd/buf@$(BUF_VERSION); \
66+
fi
67+
68+
proto-lint: buf-install
69+
$(BUF) lint $(PROTO_DIR) --config $(PROTO_DIR)/buf.yaml
70+
71+
proto-gen: buf-install
72+
$(BUF) generate $(PROTO_DIR) --template $(PROTO_DIR)/buf.gen.yaml
73+
74+
proto-gen-ci: proto-gen
75+
76+
proto-check-breaking: buf-install
77+
$(BUF) breaking $(PROTO_DIR) --against ".git#branch=$(BUF_BREAKING_AGAINST),subdir=$(PROTO_DIR)" --config $(PROTO_DIR)/buf.yaml

proto/buf.gen.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: v1
2+
managed:
3+
enabled: true
4+
go_package_prefix:
5+
default: github.com/crypto-org-chain/cronos-store
6+
plugins:
7+
- name: gogofaster # Changed from 'plugin: buf.build/community/gogo/protoc-gen-gogofaster'
8+
out: .
9+
opt:
10+
- paths=source_relative

proto/buf.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: v1
2+
3+
name: buf.build/crypto-org-chain/cronos-store
4+
5+
deps:
6+
- buf.build/cosmos/gogo-proto
7+
8+
lint:
9+
use:
10+
- STANDARD
11+
except:
12+
- PACKAGE_VERSION_SUFFIX
13+
- PACKAGE_SAME_DIRECTORY
14+
- PACKAGE_DIRECTORY_MATCH
15+
16+
breaking:
17+
use:
18+
- FILE

proto/memiavl/changeset.proto

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
syntax = "proto3";
2+
3+
package memiavl;
4+
5+
option go_package = "github.com/crypto-org-chain/cronos-store/memiavl";
6+
7+
import "gogoproto/gogo.proto";
8+
9+
// KVPair represents a key-value pair in a change set.
10+
message KVPair {
11+
bool delete = 1;
12+
bytes key = 2;
13+
bytes value = 3;
14+
}
15+
16+
// ChangeSet represents a list of key-value updates.
17+
message ChangeSet {
18+
repeated KVPair pairs = 1 [(gogoproto.nullable) = false];
19+
}

proto/memiavl/commit_info.proto

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
syntax = "proto3";
2+
3+
package memiavl;
4+
5+
option go_package = "github.com/crypto-org-chain/cronos-store/memiavl";
6+
7+
import "gogoproto/gogo.proto";
8+
9+
// CommitInfo defines commit information used by the multi-store when committing a version.
10+
message CommitInfo {
11+
int64 version = 1;
12+
repeated StoreInfo store_infos = 2 [(gogoproto.nullable) = false];
13+
}
14+
15+
// StoreInfo defines store-specific commit information.
16+
message StoreInfo {
17+
string name = 1;
18+
CommitID commit_id = 2 [(gogoproto.nullable) = false];
19+
}
20+
21+
// CommitID defines the commitment information for a specific store.
22+
message CommitID {
23+
int64 version = 1;
24+
bytes hash = 2;
25+
}

proto/memiavl/kv.proto

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
syntax = "proto3";
2+
3+
package memiavl;
4+
5+
option go_package = "github.com/crypto-org-chain/cronos-store/memiavl";
6+
7+
import "gogoproto/gogo.proto";
8+
9+
// Pairs defines a repeated slice of Pair objects.
10+
message Pairs {
11+
repeated Pair pairs = 1 [(gogoproto.nullable) = false];
12+
}
13+
14+
// Pair defines a key/value bytes tuple.
15+
message Pair {
16+
bytes key = 1;
17+
bytes value = 2;
18+
}

proto/memiavl/wal.proto

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
syntax = "proto3";
2+
3+
package memiavl;
4+
5+
option go_package = "github.com/crypto-org-chain/cronos-store/memiavl";
6+
7+
import "gogoproto/gogo.proto";
8+
import "memiavl/changeset.proto";
9+
10+
// NamedChangeSet combines a tree name with the associated change set.
11+
message NamedChangeSet {
12+
ChangeSet changeset = 1 [(gogoproto.nullable) = false];
13+
string name = 2;
14+
}
15+
16+
// TreeNameUpgrade defines upgrade operations on tree names.
17+
message TreeNameUpgrade {
18+
string name = 1;
19+
string rename_from = 2;
20+
bool delete = 3;
21+
}
22+
23+
// WALEntry represents a single write-ahead log entry.
24+
message WALEntry {
25+
repeated NamedChangeSet changesets = 1;
26+
repeated TreeNameUpgrade upgrades = 2;
27+
}

0 commit comments

Comments
 (0)