1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
include .bingo/Variables.mk
SHELL=/usr/bin/env bash
PROVIDER_MODULES ?= $(shell find $(PWD)/providers/ -name "go.mod" | grep -v ".bingo" | xargs dirname)
MODULES ?= $(PROVIDER_MODULES) $(PWD) $(PWD)/examples
GO_FILES_TO_FMT ?= $(shell find . -path -prune -o -name '*.go' -print)
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
TMP_GOPATH ?= /tmp/gopath
GO111MODULE ?= on
export GO111MODULE
GOPROXY ?= https://proxy.golang.org
export GOPROXY
define require_clean_work_tree
@git update-index -q --ignore-submodules --refresh
@if ! git diff-files --quiet --ignore-submodules --; then \
echo >&2 "cannot $1: you have unstaged changes."; \
git diff-files --name-status -r --ignore-submodules -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi
@if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \
echo >&2 "cannot $1: your index contains uncommitted changes."; \
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi
endef
all: fmt proto lint test
.PHONY: fmt
fmt: $(GOIMPORTS)
@echo ">> formatting go code"
@gofmt -s -w $(GO_FILES_TO_FMT)
@for file in $(GO_FILES_TO_FMT) ; do \
./goimports.sh "$${file}"; \
done
@$(GOIMPORTS) -w $(GO_FILES_TO_FMT)
.PHONY: test
test:
@echo "Running tests for all modules: $(MODULES)"
$(MAKE) $(MODULES:%=test_module_%)
.PHONY: test_module_%
$(MODULES:%=test_module_%): test_module_%:
@echo "Running tests for dir: $*"
cd $* && go test -v -race ./...
.PHONY: deps
deps:
@echo "Running deps tidy for all modules: $(MODULES)"
for dir in $(MODULES) ; do \
echo "$${dir}"; \
cd $${dir} && go mod tidy; \
done
.PHONY: docs
docs: $(MDOX) ## Generates code snippets, doc formatting and check links.
@echo ">> generating docs $(PATH)"
@$(MDOX) fmt -l --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) *.md
.PHONY: check-docs
check-docs: $(MDOX) ## Generates code snippets and doc formatting and checks links.
@echo ">> checking docs $(PATH)"
@$(MDOX) fmt --check -l --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) *.md
.PHONY: lint
# PROTIP:
# Add
# --cpu-profile-path string Path to CPU profile output file
# --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: $(BUF) $(COPYRIGHT) fmt docs
@echo ">> lint proto files"
@$(BUF) lint
@echo ">> ensuring copyright headers"
@$(COPYRIGHT) $(shell go list -f "{{.Dir}}" ./... | xargs -i find "{}" -name "*.go")
@$(call require_clean_work_tree,"set copyright headers")
@echo ">> ensured all .go files have copyright headers"
@echo "Running lint for all modules: $(MODULES)"
@$(call require_clean_work_tree,"before lint")
$(MAKE) $(MODULES:%=lint_module_%)
@$(call require_clean_work_tree,"lint and format files")
.PHONY: lint_module_%
# PROTIP:
# Add
# --cpu-profile-path string Path to CPU profile output file
# --mem-profile-path string Path to memory profile output file
# to debug big allocations during linting.
lint_module_%: ## Runs various static analysis against our code.
$(MODULES:%=lint_module_%): lint_module_%: $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL)
@echo ">> verifying modules being imported"
@cd $* && $(FAILLINT) -paths "fmt.{Print,Printf,Println},github.com/golang/protobuf=google.golang.org/protobuf" ./...
@echo ">> examining all of the Go files"
@cd $* && go vet -stdmethods=false ./...
@echo ">> linting all of the Go files GOGC=${GOGC}"
@cd $* && $(GOLANGCI_LINT) run
@$(call require_clean_work_tree,"golangci lint")
# 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
@mkdir -p $(TMP_GOPATH)
@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) alpha protoc \
-I $(PROTO_TEST_DIR) \
--go_out=$(PROTO_TEST_DIR)/../ \
--go-grpc_out=$(PROTO_TEST_DIR)/../ \
$(PROTO_TEST_DIR)/*.proto
.PHONY: buf.gen
buf.gen:
@$(BUF) generate \
--template ./testing/testvalidate/testvalidate.buf.gen.yaml \
--path ./testing/testvalidate/v1
|