forked from spdk/spdk-csi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
146 lines (129 loc) · 4.64 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Copyright (c) Arm Limited and Contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# output dir
OUT_DIR := ./_out
# dir for tools: e.g., golangci-lint
TOOL_DIR := $(OUT_DIR)/tool
# use golangci-lint for static code check
GOLANGCI_VERSION := v1.52.2
GOLANGCI_BIN := $(TOOL_DIR)/golangci-lint
# go source, scripts
SOURCE_DIRS := cmd pkg
SCRIPT_DIRS := scripts deploy e2e
# goarch for cross building
ifeq ($(origin GOARCH), undefined)
GOARCH := $(shell go env GOARCH)
endif
# csi image info (spdkcsi/spdkcsi:canary)
ifeq ($(origin CSI_IMAGE_REGISTRY), undefined)
CSI_IMAGE_REGISTRY := spdkcsi
endif
ifeq ($(origin CSI_IMAGE_TAG), undefined)
CSI_IMAGE_TAG := canary
endif
CSI_IMAGE := $(CSI_IMAGE_REGISTRY)/spdkcsi:$(CSI_IMAGE_TAG)
# default target
all: spdkcsi lint test
# build binary
.PHONY: spdkcsi
spdkcsi:
@echo === building spdkcsi binary
@CGO_ENABLED=0 GOARCH=$(GOARCH) GOOS=linux go build -buildvcs=false -o $(OUT_DIR)/spdkcsi ./cmd/
# static code check, text lint
lint: golangci yamllint shellcheck mdl codespell
.PHONY: golangci
golangci: $(GOLANGCI_BIN)
@echo === running golangci-lint
@$(TOOL_DIR)/golangci-lint --config=scripts/golangci.yml run ./...
$(GOLANGCI_BIN):
@echo === installing golangci-lint
@curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $(TOOL_DIR) $(GOLANGCI_VERSION)
.PHONY: yamllint
yamllint:
@echo === running yamllint
@if hash yamllint 2> /dev/null; then \
yamllint -s -c scripts/yamllint.yml $(SCRIPT_DIRS); \
bash scripts/verify-helm-yamllint.sh; \
else \
echo yamllint not installed, skip test; \
fi
.PHONY: shellcheck
shellcheck:
@echo === running shellcheck
@find $(SCRIPT_DIRS) -name "*.sh" -type f | xargs bash -n
@if hash shellcheck 2> /dev/null; then \
find $(SCRIPT_DIRS) -name "*.sh" -type f | xargs shellcheck -x; \
else \
echo shellcheck not installed, skip test; \
fi
.PHONY: mdl
mdl:
@echo === running mdl
@if hash mdl 2> /dev/null; then \
mdl --git-recurse --style scripts/ci/mdl_rules.rb .; \
else \
echo Markdown linter not found, please install; \
false ; \
fi
.PHONY: codespell
codespell:
@echo === running codespell
@if hash codespell 2> /dev/null; then \
git ls-files -z | xargs -0 codespell; \
else \
echo codespell linter not found, please install; \
false ; \
fi
# tests
test: mod-check unit-test
.PHONY: mod-check
mod-check:
@echo === runnng go mod verify
@go mod verify
.PHONY: unit-test
unit-test:
@echo === running unit test
@go test -v -race -cover $(foreach d,$(SOURCE_DIRS),./$(d)/...)
# e2e test
.PHONY: e2e-test
# Pass extra arguments to e2e tests. Could be used
# to pass --ginkgo.label-filter or --ginkgo.focus
# for quick testing.
# The below example tests:
# make e2e-test E2E_TEST_ARGS='--ginkgo.label-filter=\"!xpu-vm-tests\" --ginkgo.focus=\"TEST SPDK CSI SMA NVME\"'
# ginkgo documents can be found here: https://onsi.github.io/ginkgo/
E2E_TEST_ARGS=
e2e-test:
@echo === running e2e test
go test -v -race -timeout 30m ./e2e $(E2E_TEST_ARGS)
# helm test
.PHONY: helm-test
helm-test:
@echo === running helm test
@./scripts/install-helm.sh up
@./scripts/install-helm.sh install-spdkcsi
@./scripts/install-helm.sh cleanup-spdkcsi
@./scripts/install-helm.sh clean
# docker image
image: spdkcsi
@echo === running docker build
@if [ -n $(HTTP_PROXY) ]; then \
proxy_opt="--build-arg http_proxy=$(HTTP_PROXY) --build-arg https_proxy=$(HTTP_PROXY)"; \
fi; \
docker build -t $(CSI_IMAGE) $$proxy_opt \
-f deploy/image/Dockerfile $(OUT_DIR)
.PHONY: clean
clean:
rm -f $(OUT_DIR)/spdkcsi
go clean -testcache