-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
58 lines (47 loc) · 1.61 KB
/
Makefile
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
SHELL = /bin/bash
OS = $(shell uname -s | tr '[:upper:]' '[:lower:]')
# Build variables
COMMIT ?= $(shell git rev-parse HEAD 2>/dev/null)
BUILD_DATE ?= $(shell date +%FT%T%z)
# Go variables
export CGO_ENABLED ?= 0
export GOOS ?= $(OS)
export GOARCH ?= amd64
GOFILES_NOVENDOR = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
.PHONY: vendor
vendor: # Vendor all deps
@go mod vendor
.PHONY: lint
lint: export GOFLAGS=-mod=vendor
lint: golangci-lint fmt ## Lint the source
@$(GOLANGCI_LINT) run --timeout 5m0s
.PHONY: fmt
fmt: ## Format the source
@gofmt -s -w $(GOFILES_NOVENDOR)
.PHONY: test
test: fmt ## Run unit tests
set -o pipefail; go list -mod=vendor ./pkg/... | xargs -n1 go test -mod=vendor -ldflags "$(LDFLAGS)" -v -parallel 1
golangci-lint: ## Install golangci
ifeq (, $(shell which golangci-lint))
@{ \
set -e ;\
GOLANGCI_TMP_DIR=$$(mktemp -d) ;\
cd $$GOLANGCI_TMP_DIR ;\
go mod init tmp ;\
go get github.com/golangci/golangci-lint/cmd/[email protected] ;\
rm -rf $$GOLANGCI_TMP_DIR ;\
}
GOLANGCI_LINT=$(GOBIN)/golangci-lint
else
GOLANGCI_LINT=$(shell which golangci-lint)
endif
.PHONY: list
list: ## List all make targets
@$(MAKE) -pRrn : -f $(MAKEFILE_LIST) 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | sort
.PHONY: help
.DEFAULT_GOAL := help
help: ## Get help output
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
# Variable outputting/exporting rules
var-%: ; @echo $($*)
varexport-%: ; @echo $*=$($*)