Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved to buf; Added buf lint; Fixed ping service to match standards; … #383

Merged
merged 2 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ $(BINGO): $(BINGO_DIR)/bingo.mod
@echo "(re)installing $(GOBIN)/bingo-v0.3.0"
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=bingo.mod -o=$(GOBIN)/bingo-v0.3.0 "github.com/bwplotka/bingo"

BUF := $(GOBIN)/buf-v0.35.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding buf dependency? Wanted to know for info purpose 😛

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we use now buf as a tool! (:

$(BUF): $(BINGO_DIR)/buf.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/buf-v0.35.1"
@cd $(BINGO_DIR) && $(GO) build -mod=mod -modfile=buf.mod -o=$(GOBIN)/buf-v0.35.1 "github.com/bufbuild/buf/cmd/buf"

FAILLINT := $(GOBIN)/faillint-v1.5.0
$(FAILLINT): $(BINGO_DIR)/faillint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
Expand Down
5 changes: 5 additions & 0 deletions .bingo/buf.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.15

require github.com/bufbuild/buf v0.35.1 // cmd/buf
2 changes: 2 additions & 0 deletions .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ fi

BINGO="${GOBIN}/bingo-v0.3.0"

BUF="${GOBIN}/buf-v0.35.1"

FAILLINT="${GOBIN}/faillint-v1.5.0"

GOIMPORTS="${GOBIN}/goimports-v0.0.0-20200529172331-a64b76657301"
Expand Down
36 changes: 20 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ MODULES ?= $(PROVIDER_MODULES) $(PWD)/

GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin

// TODO(bwplotka): Move to buf.
PROTOC_VERSION ?= 3.12.3
PROTOC ?= $(GOBIN)/protoc-$(PROTOC_VERSION)
TMP_GOPATH ?= /tmp/gopath

GO111MODULE ?= on
Expand Down Expand Up @@ -43,11 +40,6 @@ fmt: $(GOIMPORTS)
@echo "Running fmt for all modules: $(MODULES)"
@$(GOIMPORTS) -local github.com/grpc-ecosystem/go-grpc-middleware/v2 -w $(MODULES)

.PHONY: proto
proto: ## Generates Go files from Thanos proto files.
proto: $(GOIMPORTS) $(PROTOC) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) ./grpctesting/testpb/test.proto
@GOIMPORTS_BIN="$(GOIMPORTS)" PROTOC_BIN="$(PROTOC)" PROTOC_GEN_GO_BIN="$(PROTOC_GEN_GO)" PROTOC_GEN_GO_GRPC_BIN="$(PROTOC_GEN_GO_GRPC)" scripts/genproto.sh

.PHONY: test
test:
@echo "Running tests for all modules: $(MODULES)"
Expand Down Expand Up @@ -76,7 +68,9 @@ deps:
# --mem-profile-path string Path to memory profile output file
# to debug big allocations during linting.
lint: ## Runs various static analysis tools against our code.
lint: fmt proto
lint: $(BUF) fmt
@echo ">> lint proto files"
@$(BUF) lint
@echo "Running lint for all modules: $(MODULES)"
./scripts/git-tree.sh
for dir in $(MODULES) ; do \
Expand All @@ -99,11 +93,21 @@ lint_module: $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL)
@cd $(DIR) && $(GOLANGCI_LINT) run
@./scripts/git-tree.sh

# TODO(bwplotka): Move to buf.
$(PROTOC):

# For protoc naming matters.
PROTOC_GEN_GO_CURRENT := $(TMP_GOPATH)/protoc-gen-go
PROTOC_GEN_GO_GRPC_CURRENT := $(TMP_GOPATH)/protoc-gen-go-grpc
PROTO_TEST_DIR := testing/testpb/v1

.PHONY: proto
proto: ## Generate testing protobufs
proto: $(BUF) $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_GRPC) $(PROTO_TEST_DIR)/test.proto
Comment on lines +103 to +104
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have two targets name proto? I'm not familiar with this Makefile pattern, if it is one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see this being confusing, but it's totally ok. It's to ensure make help works (and shows this command)

@mkdir -p $(TMP_GOPATH)
@echo ">> fetching protoc@${PROTOC_VERSION}"
@PROTOC_VERSION="$(PROTOC_VERSION)" TMP_GOPATH="$(TMP_GOPATH)" scripts/installprotoc.sh
@echo ">> installing protoc@${PROTOC_VERSION}"
@mv -- "$(TMP_GOPATH)/bin/protoc" "$(GOBIN)/protoc-$(PROTOC_VERSION)"
@echo ">> produced $(GOBIN)/protoc-$(PROTOC_VERSION)"
@cp $(PROTOC_GEN_GO) $(PROTOC_GEN_GO_CURRENT)
@cp $(PROTOC_GEN_GO_GRPC) $(PROTOC_GEN_GO_GRPC_CURRENT)
@echo ">> generating $(PROTO_TEST_DIR)"
@PATH=$(GOBIN):$(TMP_GOPATH) $(BUF) protoc \
-I $(PROTO_TEST_DIR) \
--go_out=$(PROTO_TEST_DIR)/../ \
--go-grpc_out=$(PROTO_TEST_DIR)/../ \
$(PROTO_TEST_DIR)/*.proto
Comment on lines +109 to +113
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, next step would be to just use buf generate: https://docs.buf.build/tour-6/. If you're feeling keen it should be possible to do here already with buf.gen.yaml:

version: v1beta1
plugins:
  - name: go
    out: testing/testpb/v1
  - name: go-grpc
    out: testing/testpb/v1

You may want opt: paths=source_relative if the files aren't going in the right place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uuu nice, let's try it (or in sep PR)

7 changes: 7 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: v1beta1
build:
roots:
- .
lint:
use:
- DEFAULT
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 h1:FlFbCRLd5Jr4iYXZufAvgWN6Ao0JrI5chLINnUXDDr0=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down
31 changes: 0 additions & 31 deletions grpctesting/mutex_readerwriter.go

This file was deleted.

82 changes: 0 additions & 82 deletions grpctesting/pingservice.go

This file was deleted.

10 changes: 0 additions & 10 deletions grpctesting/testpb/test.manual_extractfields.pb.go

This file was deleted.

12 changes: 0 additions & 12 deletions grpctesting/testpb/test.manual_validator.pb.go

This file was deleted.

Loading