| 1 |
include .bingo/Variables.mk |
| 2 |
FILES_TO_FMT ?= $(shell find . -path ./vendor -prune -o -name '*.go' -print) |
| 3 |
MDOX_VALIDATE_CONFIG ?= .mdox.validators.yaml |
| 4 |
|
| 5 |
GO111MODULE ?= on |
| 6 |
export GO111MODULE |
| 7 |
|
| 8 |
GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin |
| 9 |
PATH := $(PATH):$(GOBIN) |
| 10 |
|
| 11 |
|
| 12 |
GIT ?= $(shell which git) |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
SED ?= $(shell which gsed 2>/dev/null || which sed) |
| 17 |
|
| 18 |
define require_clean_work_tree |
| 19 |
@git update-index -q --ignore-submodules --refresh |
| 20 |
|
| 21 |
@if ! git diff-files --quiet --ignore-submodules --; then \ |
| 22 |
echo >&2 "cannot $1: you have unstaged changes."; \ |
| 23 |
git diff-files --name-status -r --ignore-submodules -- >&2; \ |
| 24 |
echo >&2 "Please commit or stash them."; \ |
| 25 |
exit 1; \ |
| 26 |
fi |
| 27 |
|
| 28 |
@if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \ |
| 29 |
echo >&2 "cannot $1: your index contains uncommitted changes."; \ |
| 30 |
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \ |
| 31 |
echo >&2 "Please commit or stash them."; \ |
| 32 |
exit 1; \ |
| 33 |
fi |
| 34 |
|
| 35 |
endef |
| 36 |
|
| 37 |
help: |
| 38 |
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-10s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST) |
| 39 |
|
| 40 |
.PHONY: all |
| 41 |
all: format build |
| 42 |
|
| 43 |
.PHONY: build |
| 44 |
build: |
| 45 |
@echo ">> building bingo" |
| 46 |
@go install github.com/bwplotka/bingo |
| 47 |
|
| 48 |
.PHONY: check-comments |
| 49 |
check-comments: |
| 50 |
@echo ">> checking Go comments trailing periods\n\n\n" |
| 51 |
@./scripts/build-check-comments.sh |
| 52 |
|
| 53 |
.PHONY: deps |
| 54 |
deps: |
| 55 |
@go mod tidy |
| 56 |
@go mod verify |
| 57 |
|
| 58 |
.PHONY: docs |
| 59 |
docs: build $(MDOX) |
| 60 |
@echo ">> generating docs $(PATH)" |
| 61 |
@$(MDOX) fmt -l --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) *.md |
| 62 |
|
| 63 |
.PHONY: check-docs |
| 64 |
check-docs: build $(MDOX) |
| 65 |
@echo ">> checking docs $(PATH)" |
| 66 |
@$(MDOX) fmt --check -l --links.validate.config-file=$(MDOX_VALIDATE_CONFIG) *.md |
| 67 |
|
| 68 |
.PHONY: format |
| 69 |
format: |
| 70 |
format: $(GOIMPORTS) |
| 71 |
@echo ">> formatting code" |
| 72 |
@$(GOIMPORTS) -w $(FILES_TO_FMT) |
| 73 |
|
| 74 |
.PHONY: test |
| 75 |
test: |
| 76 |
export GOCACHE=/tmp/cache |
| 77 |
test: |
| 78 |
@echo ">> running unit tests (without cache)" |
| 79 |
@rm -rf $(GOCACHE) |
| 80 |
@go test -v -timeout=30m $(shell go list ./... | grep -v /vendor/); |
| 81 |
|
| 82 |
.PHONY: check-git |
| 83 |
check-git: |
| 84 |
ifneq ($(GIT),) |
| 85 |
@test -x $(GIT) || (echo >&2 "No git executable binary found at $(GIT)."; exit 1) |
| 86 |
else |
| 87 |
@echo >&2 "No git binary found."; exit 1 |
| 88 |
endif |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
lint: |
| 96 |
lint: $(FAILLINT) $(GOLANGCI_LINT) $(COPYRIGHT) $(MISSPELL) format check-docs check-git deps |
| 97 |
$(call require_clean_work_tree,"detected not clean master before running lint") |
| 98 |
@echo ">> verifying modules being imported" |
| 99 |
@$(FAILLINT) -paths "errors=github.com/pkg/errors" ./... |
| 100 |
@$(FAILLINT) -paths "fmt.{Print,Printf,Println,Sprint}" -ignore-tests ./... |
| 101 |
@echo ">> examining all of the Go files" |
| 102 |
@go vet -stdmethods=false ./... |
| 103 |
@echo ">> linting all of the Go files GOGC=${GOGC}" |
| 104 |
@$(GOLANGCI_LINT) run |
| 105 |
@echo ">> detecting misspells" |
| 106 |
@find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error |
| 107 |
@echo ">> ensuring Copyright headers" |
| 108 |
@$(COPYRIGHT) $(shell go list -f "{{.Dir}}" ./... | xargs -I {} find "{}" -name "*.go") |
| 109 |
$(call require_clean_work_tree,"detected white noise or/and files without copyright; run 'make lint' file and commit changes.") |