Skip to content

Commit 3724484

Browse files
committed
use buf to generate the protobuf & gRPC code
1 parent 8b5cd10 commit 3724484

19 files changed

+354
-540
lines changed

Makefile

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,15 @@
22
Q=$(if $V,,@)
33
SRC=$(shell find . -type f -name '*.go')
44

5-
# protoc-gen-go constraints
6-
GEN_GO_BIN ?= protoc-gen-go
7-
GEN_GO_MIN_VERSION ?= 1.36.1
8-
GEN_GO_VERSION ?= $(shell $(GEN_GO_BIN) --version | awk -F ' v' '{print $$NF}')
9-
10-
# protoc-gen-go-grpc constraints
11-
GEN_GRPC_BIN ?= protoc-gen-go-grpc
12-
GEN_GRPC_MIN_VERSION ?= 1.5.1
13-
GEN_GRPC_VERSION ?= $(shell $(GEN_GRPC_BIN) --version | awk -F ' ' '{print $$NF}')
14-
155
# Go tools
166
GOIMPORTS=golang.org/x/tools/cmd/goimports
177
GOLANGCI_LINT=github.com/golangci/golangci-lint/v2/cmd/golangci-lint
8+
GOLANGCI_LINT_CONFIG_URL=https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml
189
GOTESTSUM=gotest.tools/gotestsum
1910
GOVULNCHECK=golang.org/x/vuln/cmd/govulncheck
11+
BUF=github.com/bufbuild/buf/cmd/buf
2012

21-
all: lint generate test
13+
all: generate lint test
2214

2315
ci: test
2416

@@ -30,16 +22,6 @@ ci: test
3022

3123
build: ;
3224

33-
#########################################
34-
# Bootstrapping
35-
#########################################
36-
37-
bootstra%:
38-
$Q go install -mod=readonly google.golang.org/protobuf/cmd/protoc-gen-go
39-
$Q go install -mod=readonly google.golang.org/grpc/cmd/protoc-gen-go-grpc
40-
41-
.PHONY: bootstrap
42-
4325
#########################################
4426
# Test
4527
#########################################
@@ -61,7 +43,7 @@ fmt:
6143

6244
lint: SHELL:=/bin/bash
6345
lint:
64-
$Q LOG_LEVEL=error go tool $(GOLANGCI_LINT) run --config <(curl -s https://raw.githubusercontent.com/smallstep/workflows/master/.golangci.yml) --timeout=30m
46+
$Q LOG_LEVEL=error go tool $(GOLANGCI_LINT) run --config <(curl -s $(GOLANGCI_LINT_CONFIG_URL)) --timeout=30m ./...
6547
$Q go tool $(GOVULNCHECK) ./...
6648

6749
.PHONY: fmt lint
@@ -70,40 +52,15 @@ lint:
7052
# Generate
7153
#########################################
7254

73-
generate: check-gen-go-version check-gen-grpc-version
55+
generate:
7456
@# remove any previously generated protobufs & gRPC files
7557
@find . \
7658
-type f \
7759
-name "*.pb.go" \
7860
-delete
7961

8062
@# generate the corresponding protobufs & gRPC code files
81-
$Q protoc \
82-
--proto_path=spec \
83-
--go_opt=module=github.com/smallstep/linkedca \
84-
--go_out=. \
85-
--go-grpc_opt=module=github.com/smallstep/linkedca \
86-
--go-grpc_out=. \
87-
$(shell find spec -type f -name "*.proto")
63+
$Q go tool $(BUF) generate -o .
8864

8965
.PHONY: generate
9066

91-
#########################################
92-
# Tool constraints
93-
#########################################
94-
95-
check-gen-go-version:
96-
@if ! printf "%s\n%s" "$(GEN_GO_MIN_VERSION)" "$(GEN_GO_VERSION)" | sort -V -C; then \
97-
echo "Your $(GEN_GO_BIN) version (v$(GEN_GO_VERSION)) is older than the minimum required (v$(GEN_GO_MIN_VERSION))."; \
98-
exit 1; \
99-
fi
100-
101-
.PHONY: check-gen-go-version
102-
103-
check-gen-grpc-version:
104-
@if ! printf "%s\n%s" "$(GEN_GRPC_MIN_VERSION)" "$(GEN_GRPC_VERSION)" | sort -V -C; then \
105-
echo "Your $(GEN_GRPC_BIN) version (v$(GEN_GRPC_VERSION)) is older than the minimum required (v$(GEN_GRPC_MIN_VERSION))."; \
106-
exit 1; \
107-
fi
108-
109-
.PHONY: check-gen-grpc-version

admin.pb.go

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

buf.gen.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: v2
2+
3+
managed:
4+
enabled: true
5+
6+
inputs:
7+
- directory: proto
8+
9+
plugins:
10+
- local: [go, tool, google.golang.org/protobuf/cmd/protoc-gen-go]
11+
out: .
12+
opt:
13+
- module=github.com/smallstep/linkedca
14+
15+
- local: [go, tool, google.golang.org/grpc/cmd/protoc-gen-go-grpc]
16+
out: .
17+
opt:
18+
- module=github.com/smallstep/linkedca
19+
- require_unimplemented_servers=true

buf.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: v2
2+
3+
lint:
4+
use:
5+
- STANDARD
6+
7+
breaking:
8+
use:
9+
- FILE
10+
11+
modules:
12+
- path: proto

config.pb.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eab.pb.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)