-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (76 loc) · 2.26 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
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
PACKAGE=github.com/sergk/tkn-graph/pkg/cmd
# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build -v
GOTEST=$(GOCMD) test
GOLINT=golangci-lint run
GOFMT=$(GOCMD) fmt
GOVET=$(GOCMD) vet
CURRENT_DIR=$(shell pwd)
# Binary name
BINARY_NAME=tkn-graph
# Versioning
GIT_DESCRIBE=$(shell git describe --tags --always --dirty)
LDFLAGS=-ldflags "-X $(PACKAGE)/version.cliVersion=$(GIT_DESCRIBE)"
override GCFLAGS +=all=-trimpath=${CURRENT_DIR}
.DEFAULT_GOAL:=help
# Directories
SRC_DIR=./cmd/graph
DIST_DIR=./dist
BIN_DIR=./bin
# Build targets
.PHONY: build
build: ## build the binary
CGO_ENABLED=0 $(GOBUILD) $(LDFLAGS) -o $(DIST_DIR)/$(BINARY_NAME) -gcflags '${GCFLAGS}' $(SRC_DIR)/...
# Test targets
.PHONY: test
test: ## run tests
KUBECONFIG=${CURRENT_DIR}/hack/kubeconfig-stub.yaml $(GOTEST) -v -coverprofile=coverage.out ./...
# Lint targets
.PHONY: lint
lint: ## run linter
$(GOLINT) ./...
# Format targets
.PHONY: fmt
fmt: ## run gofmt
$(GOFMT) ./...
.PHONY: vet
vet: ## Run go vet
$(GOVET) ./...
# Clean targets
.PHONY: clean
clean: ## remove the binary
rm -rf $(DIST_DIR)
# make CI run all targets
.PHONY: all
all: lint test fmt vet build ## run all targets: lint test fmt build
# use https://github.com/git-chglog/git-chglog/
.PHONY: changelog
changelog: git-chglog ## generate changelog
ifneq (${NEXT_RELEASE_TAG},)
$(GITCHGLOG) --next-tag v${NEXT_RELEASE_TAG} -o CHANGELOG.md v0.1.0..
else
$(GITCHGLOG) -o CHANGELOG.md v0.1.0..
endif
# Help target
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
GITCHGLOG = ${BIN_DIR}/git-chglog
.PHONY: git-chglog
git-chglog: ## Download git-chglog locally if necessary.
$(call go-get-tool,$(GITCHGLOG),github.com/git-chglog/git-chglog/cmd/git-chglog,v0.15.4)
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
go get -d $(2)@$(3) ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef