forked from leaseweb/cloudstack-csi-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
124 lines (94 loc) · 3.62 KB
/
Makefile
File metadata and controls
124 lines (94 loc) · 3.62 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
CMDS=cloudstack-csi-driver cloudstack-csi-sc-syncer
PKG=github.com/leaseweb/cloudstack-csi-driver
# Revision that gets built into each binary via the main.version
# string. Uses the `git describe` output based on the most recent
# version tag with a short revision suffix or, if nothing has been
# tagged yet, just the revision.
#
# Beware that tags may also be missing in shallow clones as done by
# some CI systems (like TravisCI, which pulls only 50 commits).
REV=$(shell git describe --long --tags --match='v*' --dirty 2>/dev/null || git rev-list -n1 HEAD)
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u -Iseconds)
DOCKER?=docker
IMPORTPATH_LDFLAGS = -X ${PKG}/pkg/driver.driverVersion=$(REV) -X ${PKG}/pkg/driver.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/driver.buildDate=${BUILD_DATE}
LDFLAGS = -s -w
FULL_LDFLAGS = $(LDFLAGS) $(IMPORTPATH_LDFLAGS)
export REPO_ROOT := $(shell git rev-parse --show-toplevel)
# Directories
TOOLS_DIR := $(REPO_ROOT)/hack/tools
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR ?= bin
GO_INSTALL := ./hack/go_install.sh
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT_VER := v1.63.4
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
GOLANGCI_LINT_PKG := github.com/golangci/golangci-lint/cmd/golangci-lint
MOCKGEN_BIN := mockgen
MOCKGEN_VER := v0.5.2
MOCKGEN := $(abspath $(TOOLS_BIN_DIR)/$(MOCKGEN_BIN)-$(MOCKGEN_VER))
MOCKGEN_PKG := go.uber.org/mock/mockgen
##@ Linting
## --------------------------------------
## Linting
## --------------------------------------
.PHONY: fmt
fmt: ## Run go fmt on the whole project.
go fmt ./...
.PHONY: vet
vet: ## Run go vet on the whole project.
go vet ./...
.PHONY: lint
lint: $(GOLANGCI_LINT) generate-mocks ## Run linting for the project.
$(MAKE) fmt
$(MAKE) vet
$(GOLANGCI_LINT) run -v --timeout 360s ./...
##@ Build
## --------------------------------------
## Build
## --------------------------------------
.PHONY: all
all: build
.PHONY: build
build: $(CMDS:%=build-%)
.PHONY: container
container: $(CMDS:%=container-%)
.PHONY: clean
clean:
rm -rf $(TOOLS_BIN_DIR)
rm -rf bin test/e2e/e2e.test test/e2e/ginkgo
.PHONY: build-%
$(CMDS:%=build-%): build-%:
mkdir -p bin
CGO_ENABLED=0 go build -ldflags '$(FULL_LDFLAGS)' -o "./bin/$*" ./cmd/$*
.PHONY: container-%
$(CMDS:%=container-%): container-%: build-%
$(DOCKER) build -f ./cmd/$*/Dockerfile -t $*:latest \
--label org.opencontainers.image.revision=$(REV) .
.PHONY: generate-mocks
generate-mocks: $(MOCKGEN) pkg/cloud/mock_cloud.go ## Generate mocks needed for testing. Primarily mocks of the cloud package.
pkg/cloud/mock%.go: $(shell find ./pkg/cloud -type f -name "*test*" -prune -o -print)
go generate ./...
.PHONY: test
test:
go test ./...
.PHONY: test-sanity
test-sanity:
go test --tags=sanity ./test/sanity
.PHONY: setup-external-e2e
setup-external-e2e: test/e2e/e2e.test test/e2e/ginkgo
test/e2e/e2e.test test/e2e/ginkgo:
curl --location https://dl.k8s.io/v1.30.5/kubernetes-test-linux-amd64.tar.gz | \
tar --strip-components=3 -C test/e2e -zxf - kubernetes/test/bin/e2e.test kubernetes/test/bin/ginkgo
.PHONY: test-e2e
test-e2e: setup-external-e2e
bash ./test/e2e/run.sh
##@ hack/tools:
.PHONY: $(GOLANGCI_LINT_BIN)
$(GOLANGCI_LINT_BIN): $(GOLANGCI_LINT) ## Build a local copy of golangci-lint.
.PHONY: $(MOCKGEN_BIN)
$(MOCKGEN_BIN): $(MOCKGEN) ## Build a local copy of mockgen.
$(GOLANGCI_LINT): # Build golangci-lint from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(GOLANGCI_LINT_PKG) $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
$(MOCKGEN): # Build mockgen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(MOCKGEN_PKG) $(MOCKGEN_BIN) $(MOCKGEN_VER)