-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMakefile
110 lines (88 loc) · 2.73 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
ROOT := $(shell git rev-parse --show-toplevel)
OS := $(shell uname -s | awk '{print tolower($$0)}')
ARCH := amd64
PROJECT := echoperator
VERSION := $(shell git describe --abbrev=0 --tags)
LD_FLAGS := -X main.version=$(VERSION) -s -w
SOURCE_FILES ?= ./internal/... ./pkg/... ./cmd/...
export CGO_ENABLED := 0
export GO111MODULE := on
export GOBIN := $(shell pwd)/bin
export KUBECONFIG ?= $(HOME)/.kube/config
.PHONY: all
all: help
.PHONY: help
help: ### Show targets documentation
ifeq ($(OS), linux)
@grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
else
@awk -F ':.*###' '$$0 ~ FS {printf "%15s%s\n", $$1 ":", $$2}' \
$(MAKEFILE_LIST) | grep -v '@awk' | sort
endif
KIND := $(GOBIN)/kind
KIND_VERSION := v0.14.0
kind:
$(call go-install,sigs.k8s.io/kind@$(KIND_VERSION))
GOLANGCI_LINT := $(GOBIN)/golangci-lint
GOLANGCI_LINT_VERSION := v1.46.2
golangci-lint:
$(call go-install,github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION))
GORELEASER := $(GOBIN)/goreleaser
GORELEASER_VERSION := v1.9.2
goreleaser:
$(call go-install,github.com/goreleaser/goreleaser@$(GORELEASER_VERSION))
MOCKERY := $(GOBIN)/mockery
MOCKERY_VERSION := v2.12.3
mockery:
$(call go-install,github.com/vektra/mockery/v2@$(MOCKERY_VERSION))
.PHONY: generate
generate: vendor ### Generate code
@bash ./hack/hack.sh
.PHONY: install-crds
install-crds: ## Install CRDs
@kubectl apply -f manifests/crds
.PHONY: cluster
cluster: kind ### Create a KIND cluster
$(KIND) create cluster --name $(PROJECT)
clean: ### Clean build files
@rm -rf ./bin
@go clean
.PHONY: build
build: clean ### Build binary
@go build -tags netgo -a -v -ldflags "${LD_FLAGS}" -o ./bin/echoperator ./cmd/echoperator/*.go
@chmod +x ./bin/*
.PHONY: run
run: lint install-crds ### Quick run
@CGO_ENABLED=1 go run -race cmd/echoperator/*.go
.PHONY: deps
deps: ### Optimize dependencies
@go mod tidy
.PHONY: vendor
vendor: ### Vendor dependencies
@go mod vendor
.PHONY: lint
lint: golangci-lint ### Lint
$(GOLANGCI_LINT) run
.PHONY: release
release: goreleaser ### Dry-run release
$(GORELEASER) release --snapshot --rm-dist
.PHONY: test-clean
test-clean: ### Clean test cache
@go clean -testcache ./...
.PHONY: test
test: ### Run tests
@go test -v -coverprofile=cover.out -timeout 10s ./...
.PHONY: cover
cover: test ### Run tests and generate coverage
@go tool cover -html=cover.out -o=cover.html
.PHONY: mocks
mocks: mockery ### Generate mocks
$(MOCKERY) --all --dir internal --output internal/mocks
# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-install
@[ -f $(1) ] || { \
go install $(1) ; \
}
endef