|
| 1 | +## Location to install dependencies to |
| 2 | +LOCALBIN ?= $(shell pwd)/bin |
| 3 | +$(LOCALBIN): |
| 4 | + mkdir -p $(LOCALBIN) |
| 5 | + |
| 6 | +## Tool Binaries |
| 7 | +GO_IMPORTS ?= $(LOCALBIN)/goimports |
| 8 | +GCI ?= $(LOCALBIN)/gci |
| 9 | + |
| 10 | +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) |
| 11 | +ifeq (,$(shell go env GOBIN)) |
| 12 | +GOBIN=$(shell go env GOPATH)/bin |
| 13 | +else |
| 14 | +GOBIN=$(shell go env GOBIN) |
| 15 | +endif |
| 16 | + |
| 17 | +# Setting SHELL to bash allows bash commands to be executed by recipes. |
| 18 | +# Options are set to exit when a recipe line exits non-zero or a piped command fails. |
| 19 | +SHELL = /usr/bin/env bash -o pipefail |
| 20 | +.SHELLFLAGS = -ec |
| 21 | + |
| 22 | +.PHONY: help |
| 23 | +help: ## Display this help. |
| 24 | + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) |
| 25 | + |
| 26 | +##@ Development |
| 27 | + |
| 28 | +.PHONY: go_fmt |
| 29 | +go_fmt: ## Run go fmt against code. |
| 30 | + gofmt -w -s . |
| 31 | + |
| 32 | +.PHONY: fmt_imports |
| 33 | +fmt_imports: $(GCI) ## Run goimports against code. |
| 34 | + $(GCI) write ./ --skip-generated -s standard -s default -s 'prefix(github.com/qdrant)' |
| 35 | + |
| 36 | +.PHONY: fmt |
| 37 | +format: go_fmt fmt_imports ## Format the code. |
| 38 | + |
| 39 | +fmt: format ## Format the code. |
| 40 | + |
| 41 | +.PHONY: vet |
| 42 | +vet: ## Run go vet against code. |
| 43 | + go vet ./... |
| 44 | + |
| 45 | +lint: $(GCI) ## Run linters. |
| 46 | + bash -c 'files=$$(gofmt -l .) && echo $$files && [ -z "$$files" ]' |
| 47 | + golangci-lint run |
| 48 | + |
| 49 | +.PHONY: test_unit |
| 50 | +test_unit: ## Run unit tests. |
| 51 | + go test ./... -coverprofile cover.out |
| 52 | + |
| 53 | +$(GO_IMPORTS): $(LOCALBIN) |
| 54 | + GOBIN=$(LOCALBIN) go install golang.org/x/tools/cmd/goimports@latest |
| 55 | + |
| 56 | +$(GCI): $(LOCALBIN) |
| 57 | + GOBIN=$(LOCALBIN) go install github.com/daixiang0/gci@latest |
| 58 | + |
| 59 | + |
0 commit comments