Debian Codegraph @

Makefile

raw
1 include .bingo/Variables.mk
2
3 GO111MODULE ?= on
4 export GO111MODULE
5
6 GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin
7
8 # Tools.
9 GIT ?= $(shell which git)
10
11 # Support gsed on OSX (installed via brew), falling back to sed. On Linux
12 # systems gsed won't be installed, so will use sed as expected.
13 SED ?= $(shell which gsed 2>/dev/null || which sed)
14
15 define require_clean_work_tree
16 @git update-index -q --ignore-submodules --refresh
17
18 @if ! git diff-files --quiet --ignore-submodules --; then \
19 echo >&2 "$1: you have unstaged changes."; \
20 git diff-files --name-status -r --ignore-submodules -- >&2; \
21 echo >&2 "Please commit or stash them."; \
22 exit 1; \
23 fi
24
25 @if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \
26 echo >&2 "$1: your index contains uncommitted changes."; \
27 git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \
28 echo >&2 "Please commit or stash them."; \
29 exit 1; \
30 fi
31
32 endef
33
34 help: ## Displays help.
35 @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)
36
37 .PHONY: all
38 all: format build
39
40 .PHONY: build
41 build: ## Build modules
42 go test -run=nope ./...
43
44 .PHONY: deps
45 deps: ## Cleans up deps for all modules
46 @echo ">> running deps tidy"
47 go mod tidy
48
49 .PHONY: docs
50 docs: $(MDOX) ## Generates config snippets and doc formatting.
51 @echo ">> generating docs $(PATH)"
52 @$(MDOX) fmt -l *.md
53
54 .PHONY: format
55 format: ## Formats Go code.
56 format: $(GOIMPORTS)
57 @echo ">> formatting module"
58 @$(GOIMPORTS) -w .
59
60 .PHONY: test
61 test: ## Runs all Go unit tests.
62 @echo ">> running tests with -race"
63 go test -v -race ./...
64
65 .PHONY: check-git
66 check-git:
67 ifneq ($(GIT),)
68 @test -x $(GIT) || (echo >&2 "No git executable binary found at $(GIT)."; exit 1)
69 else
70 @echo >&2 "No git binary found."; exit 1
71 endif
72
73 # PROTIP:
74 # Add
75 # --cpu-profile-path string Path to CPU profile output file
76 # --mem-profile-path string Path to memory profile output file
77 # to debug big allocations during linting.
78 lint: ## Runs various static analysis against our code.
79 lint: $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL) $(COPYRIGHT) build format docs check-git deps
80 $(call require_clean_work_tree,"detected not clean master before running lint - run make lint and commit changes.")
81 @echo ">> verifying imported packages"
82 $(FAILLINT) -paths "fmt.{Print,PrintfPrintln,Sprint}" -ignore-tests ./...
83 @echo ">> examining all of the Go files"
84 go vet -stdmethods=false ./...
85 @echo ">> linting all of the Go files GOGC=${GOGC}"
86 $(GOLANGCI_LINT) run
87 @echo ">> detecting misspells"
88 @find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error
89 @echo ">> ensuring Copyright headers"
90 @ $(COPYRIGHT) $(shell go list -f "{{.Dir}}" ./... | xargs -i find "{}" -name "*.go")
91 $(call require_clean_work_tree,"detected files without copyright - run make lint and commit changes.")