-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
97 lines (76 loc) · 3.08 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
SHELL = /bin/bash
export GOPROXY?=https://proxy.golang.org/
# Build-time variables to inject into binaries
export SIMPLE_VERSION = $(shell (test "$(shell git describe --tags)" = "$(shell git describe --tags --abbrev=0)" && echo $(shell git describe --tags)) || echo $(shell git describe --tags --abbrev=0)+git)
export GIT_VERSION = $(shell git describe --dirty --tags --always)
export GIT_COMMIT = $(shell git rev-parse HEAD)
export K8S_VERSION = 1.24.2
# Build settings
export TOOLS_DIR = tools/bin
export SCRIPTS_DIR = tools/scripts
REPO = $(shell go list -m)
BUILD_DIR = build
GO_ASMFLAGS = -asmflags "all=-trimpath=$(shell dirname $(PWD))"
GO_GCFLAGS = -gcflags "all=-trimpath=$(shell dirname $(PWD))"
GO_BUILD_ARGS = \
$(GO_GCFLAGS) $(GO_ASMFLAGS) \
-ldflags " \
-X '$(REPO)/internal/version.Version=$(SIMPLE_VERSION)' \
-X '$(REPO)/internal/version.GitVersion=$(GIT_VERSION)' \
-X '$(REPO)/internal/version.GitCommit=$(GIT_COMMIT)' \
-X '$(REPO)/internal/version.KubernetesVersion=v$(K8S_VERSION)' \
" \
##@ Development
# TODO: add test data generation
.PHONY: fix
fix: ## Fixup files in the repo.
go mod tidy
go fmt ./...
make setup-lint
$(TOOLS_DIR)/golangci-lint run --fix
.PHONY: setup-lint
setup-lint: ## Setup the lint
$(SCRIPTS_DIR)/fetch golangci-lint 1.46.2
.PHONY: lint
lint: setup-lint ## Run the lint check
$(TOOLS_DIR)/golangci-lint run
.PHONY: clean
clean: ## Cleanup build artifacts and tool binaries.
rm -rf $(BUILD_DIR) dist $(TOOLS_DIR)
##@ Build
.PHONY: build
build: ## Build kcp-operator-sdk
@mkdir -p $(BUILD_DIR)
go build $(GO_BUILD_ARGS) -o $(BUILD_DIR) .
.PHONY: install
install: ## Install kcp-operator-sdk.
go install $(GO_BUILD_ARGS) ./kcp-operator-sdk
##@ Test
# TODO: add e2e tests
# TODO: add unit tests
.PHONY: test-sanity
test-sanity: generate fix ## Test repo formatting, linting, etc.
git diff --exit-code # fast-fail if generate or fix produced changes
go vet ./...
make setup-lint
make lint
git diff --exit-code # diff again to ensure other checks don't change repo
.DEFAULT_GOAL := help
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
help: ## Show this help screen.
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
@echo ''
@echo 'Available targets are:'
@echo ''
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z0-9_-]+:.*?##/ { printf " \033[36m%-25s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)