|
| 1 | +################################################################################ |
| 2 | +# Target: lint # |
| 3 | +################################################################################ |
| 4 | +# Please use golangci-lint with matching version, otherwise you might encounter errors. |
| 5 | +# You can download at https://github.com/golangci/golangci-lint/releases/ |
| 6 | +# Check .github/wortkflows/test.yaml for the version used in GitHub actions. |
| 7 | + |
| 8 | +ifeq ($(GOOS),windows) |
| 9 | +GOLANGCI_LINT:=golangci-lint.exe |
| 10 | +else |
| 11 | +GOLANGCI_LINT:=golangci-lint |
| 12 | +endif |
| 13 | + |
| 14 | +.PHONY: lint |
| 15 | +lint: |
| 16 | + $(GOLANGCI_LINT) run --timeout=20m |
| 17 | + |
| 18 | + |
| 19 | +################################################################################ |
| 20 | +# Target: check-linter # |
| 21 | +################################################################################ |
| 22 | +.SILENT: check-linter # Silence output other than the application run |
| 23 | +.PHONY: check-linter |
| 24 | +check-linter: |
| 25 | + $(RUN_BUILD_TOOLS) check-linter |
| 26 | + |
| 27 | + |
| 28 | +################################################################################ |
| 29 | +# Target: modtidy # |
| 30 | +################################################################################ |
| 31 | +.PHONY: modtidy |
| 32 | +modtidy: |
| 33 | + go mod tidy |
| 34 | + |
| 35 | +################################################################################ |
| 36 | +# Target: gen-proto # |
| 37 | +################################################################################ |
| 38 | +PROTOC ?=protoc |
| 39 | +PROTOC_VERSION = 24.4 |
| 40 | +PROTOBUF_SUITE_VERSION = 24.4 |
| 41 | +PROTOC_GEN_GO_VERSION = v1.32.0 |
| 42 | + |
| 43 | +PROTOC_GEN_GO_GRPC_VERSION = 1.3.0 |
| 44 | + |
| 45 | +PROTOS:=$(shell ls proto) |
| 46 | +PROTO_PREFIX:=github.com/diagridio/go-etcd-cron |
| 47 | + |
| 48 | +.PHONY: check-proto-version |
| 49 | +check-proto-version: ## Checking the version of proto related tools |
| 50 | + @test "$(shell protoc --version)" = "libprotoc $(PROTOC_VERSION)" \ |
| 51 | + || { echo "please use protoc $(PROTOC_VERSION) (protobuf $(PROTOBUF_SUITE_VERSION)) to generate proto"; exit 1; } |
| 52 | + |
| 53 | + @test "$(shell protoc-gen-go-grpc --version)" = "protoc-gen-go-grpc $(PROTOC_GEN_GO_GRPC_VERSION)" \ |
| 54 | + || { echo "please use protoc-gen-go-grpc $(PROTOC_GEN_GO_GRPC_VERSION) to generate proto"; exit 1; } |
| 55 | + |
| 56 | + @test "$(shell protoc-gen-go --version 2>&1)" = "protoc-gen-go $(PROTOC_GEN_GO_VERSION)" \ |
| 57 | + || { echo "please use protoc-gen-go $(PROTOC_GEN_GO_VERSION) to generate proto"; exit 1; } |
| 58 | + |
| 59 | +# Generate archive files for each binary |
| 60 | +# $(1): the binary name to be archived |
| 61 | +define genProtoc |
| 62 | +.PHONY: gen-proto-$(1) |
| 63 | +gen-proto-$(1): |
| 64 | + $(PROTOC) --go_out=. --go_opt=module=$(PROTO_PREFIX) --go-grpc_out=. --go-grpc_opt=require_unimplemented_servers=false,module=$(PROTO_PREFIX) ./proto/$(1)/* |
| 65 | +endef |
| 66 | + |
| 67 | +$(foreach ITEM,$(PROTOS),$(eval $(call genProtoc,$(ITEM)))) |
| 68 | + |
| 69 | +GEN_PROTOS:=$(foreach ITEM,$(PROTOS),gen-proto-$(ITEM)) |
| 70 | + |
| 71 | +.PHONY: gen-proto |
| 72 | +gen-proto: check-proto-version $(GEN_PROTOS) modtidy |
| 73 | + |
| 74 | +test: |
| 75 | + go test -timeout 300s --race ./... |
0 commit comments