Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
583 lines (512 loc) · 21.4 KB
/
Copy pathMakefile
File metadata and controls
583 lines (512 loc) · 21.4 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
.PHONY: default testing local deps prepare cspell build_external_local ebpf_nocgo_ci
default: local
# new version notify settings
NEW_VERSION_PUSH_TOKEN ?=NOT_SET
NEW_VERSION_PUSH_URL ?=NOT_SET
DOCKER_IMAGE_REPO ?= NOT_SET
DOCKER_BUILDX_CACHE_REPO ?=
BRAND ?= NOT_SET
DIST_DIR = dist
BIN = datakit
NAME = datakit
NAME_EBPF = datakit-ebpf
ENTRY = cmd/datakit/main.go
LOCAL_ARCHS = local
DEFAULT_ARCHS = all
MAC_ARCHS = darwin/amd64,darwin/arm64
DOCKER_IMAGE_ARCHS = linux/arm64,linux/amd64
UOS_DOCKER_IMAGE_ARCHS = linux/arm64,linux/amd64
DCA_BUILD_ARCH = linux/arm64,linux/amd64
FLAMESHOT_NAME = flameshot
FLAMESHOT_ARCHS = linux/amd64,linux/arm64
GOLINT_BINARY ?= golangci-lint
CGO_FLAGS = "-Wno-undef-prefix -Wno-deprecated-declarations" # to disable warnings from gopsutil on macOS
HL = \033[0;32m # high light
NC = \033[0m # no color
RED = \033[31m # red
LOG_LEVEL ?= "info"
GO_MODULE_MODE ?= vendor
GO_MODULE_ENV = GO111MODULE=on GOFLAGS=-mod=$(GO_MODULE_MODE)
GO_VERSION_EXPECTED ?= 1.26.2
DK_BUILD_ENV_IMAGE ?= pubrepo.jiagouyun.com/ebpf-dev/dk_build_env:3.1
comma := ,
export DK_BUILD_ENV_IMAGE
SUPPORTED_GOLINT_VERSION = 2.11.4
SUPPORTED_GOLINT_VERSION_ANOTHER = v2.11.4
MINIMUM_GO_MAJOR_VERSION = 1
MINIMUM_GO_MINOR_VERSION = 16
GO_VERSION_ERR_MSG := Golang version is not supported, please update to at least $(MINIMUM_GO_MAJOR_VERSION).$(MINIMUM_GO_MINOR_VERSION)
GO_VERSION_ACTUAL := $(shell go version | awk '{print $$3}' | sed 's/^go//')
GO_VERSION_LOCK_ERR_MSG := Golang version mismatch: expect $(GO_VERSION_EXPECTED), got $(GO_VERSION_ACTUAL) from go. Switch current shell PATH or CI-installed Go before running make.
# Make them evaluate(expand) only once
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m | sed -e s/x86_64/x86_64/ -e s/aarch64.\*/arm64/)
DATE := $(shell date -u +'%Y-%m-%d %H:%M:%S')
GOVERSION := $(shell go version)
COMMIT := $(shell git rev-parse --short HEAD)
COMMITER := $(shell git log -1 --pretty=format:'%an')
UPLOADER := $(shell hostname)/${USER}/${COMMITER}
GO_MAJOR_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
GO_PATCH_VERSION := $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f3)
BUILDER_GOOS_GOARCH := $(shell go env GOOS)-$(shell go env GOARCH)
GOLINT_VERSION = $(shell $(GOLINT_BINARY) --version 2>/dev/null | cut -c 27- | cut -d' ' -f1)
GOLINT_VERSION_ERR_MSG = golangci-lint version($(GOLINT_VERSION)) is not supported, please use version $(SUPPORTED_GOLINT_VERSION)
# These can be override at runtime by make variables
VERSION ?= $(shell git describe --always --tags)
FLAMESHOT_VERSION ?= NOT_SET
DCA_VERSION ?= NOT_SET
DATAWAY_URL ?= NOT_SET
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
DATAKIT_EBPF_ARCHS ?= linux/arm64,linux/amd64
RACE_DETECTION ?= off
AUTO_FIX ?= false
UT_EXCLUDE ?= "-"
UT_ONLY ?= "-"
UT_IMPACTED ?= false
UT_BASE_BRANCH ?= ""
UT_PARALLEL ?= "0"
DOCKER_REMOTE_HOST ?= "0.0.0.0" # default use localhost as docker server
DOCKER_IMAGE_PROJECT_PATH ?= NOT_SET
DOCKERFILE_SUFFIX ?= NOT_SET
HELM_CHART_DIR ?= "charts/datakit"
SKIP_HELM ?= 0
MERGE_REQUEST_TARGET_BRANCH ?= ""
MERGE_REQUEST_SOURCE_BRANCH ?= ""
ONLY_BUILD_INPUTS_EXTENTIONS ?= 0
EXTERNAL_NAME ?=
EXTERNAL_GOOS ?= linux
EXTERNAL_ARCH ?= $(shell go env GOARCH)
EXTERNAL_OUTDIR ?=
EXTERNAL_OUTPUT ?=
EXTERNAL_LDFLAGS ?= -w -s
EXTERNAL_EBPF_ARGS ?=
EXTERNAL_EBPF_TARGET ?= build
DK_BPF_KERNEL_SRC_PATH ?=
EXTERNAL_SYSROOT_BASE ?= /opt/sysroots/debian10
EBPF_CI_ARCHS ?= amd64 arm64
EBPF_CI_DOCKER_PLATFORM ?= linux/$(shell go env GOARCH)
AWS_REGIONS ?= ""
# Generate 'internal/git' package
define GIT_INFO
// Package git used to define basic git info abount current version.
package git
//nolint
const (
BuildAt string = "$(DATE)"
Version string = "$(VERSION)"
Golang string = "$(GOVERSION)"
Commit string = "$(COMMIT)"
Branch string = "$(GIT_BRANCH)"
Uploader string = "$(UPLOADER)"
DCAVersion string = "$(DCA_VERSION)"
);
endef
export GIT_INFO
##############################################################################
# Functions used within the Makefile
##############################################################################
define notify_build
@if [ "$(GO_VERSION_ACTUAL)" != "$(GO_VERSION_EXPECTED)" ]; then \
echo '$(GO_VERSION_LOCK_ERR_MSG)'; \
exit 1; \
fi
@echo "===== notify $(BIN) $(1) ===="
$(GO_MODULE_ENV) CGO_ENABLED=0 CGO_CFLAGS=$(CGO_FLAGS) go run -tags with_inputs cmd/make/make.go \
-log-level $(LOG_LEVEL) \
-main $(ENTRY) \
-binary $(BIN) \
-name $(NAME) \
-release $(1) \
-dist-dir $(DIST_DIR) \
-archs $(2) \
-notify-only
endef
# build used to compile datakit binary and related dists
define build_bin
@if [ "$(GO_VERSION_ACTUAL)" != "$(GO_VERSION_EXPECTED)" ]; then \
echo '$(GO_VERSION_LOCK_ERR_MSG)'; \
exit 1; \
fi
@rm -rf $(DIST_DIR)/$(1)/*
@mkdir -p $(DIST_DIR)/$(1)
@echo "===== building $(BIN) $(1) ====="
$(GO_MODULE_ENV) CGO_ENABLED=0 CGO_CFLAGS=$(CGO_FLAGS) go run \
-tags with_inputs cmd/make/make.go \
-log-level $(LOG_LEVEL) \
-release $(1) \
-archs $(2) \
-main $(ENTRY) \
-binary $(BIN) \
-name $(NAME) \
-dist-dir $(DIST_DIR) \
-race $(RACE_DETECTION) \
-brand $(BRAND) \
-docker-image-repo $(DOCKER_IMAGE_REPO) \
-helm-chart-dir $(HELM_CHART_DIR) \
-skip-helm $(SKIP_HELM) \
-only-external-inputs $(ONLY_BUILD_INPUTS_EXTENTIONS) \
-flameshot
@tree -Csh -L 3 $(DIST_DIR)
endef
# pub used to publish datakit version(for release/testing/local)
define publish
@echo "===== publishing $(1) $(NAME) ====="
$(GO_MODULE_ENV) CGO_CFLAGS=$(CGO_FLAGS) go run \
-tags with_inputs cmd/make/make.go \
-log-level $(LOG_LEVEL) \
-release $(1) \
-archs $(2) \
-pub \
-enable-upload-aws \
-aws-regions $(AWS_REGIONS) \
-dist-dir $(DIST_DIR) \
-name $(NAME) \
-brand $(BRAND) \
-helm-chart-dir $(HELM_CHART_DIR) \
-skip-helm $(SKIP_HELM) \
-docker-image-repo $(DOCKER_IMAGE_REPO)
endef
define buildx_cache_args
$(if $(DOCKER_BUILDX_CACHE_REPO),--cache-from type=registry$(comma)ref=$(DOCKER_BUILDX_CACHE_REPO)/$(1):buildcache --cache-to type=registry$(comma)ref=$(DOCKER_BUILDX_CACHE_REPO)/$(1):buildcache$(comma)mode=max$(comma)ignore-error=true)
endef
define build_docker_image
echo 'publishing to $(2)...';
@if [ $(2) = "registry.jiagouyun.com" ]; then \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,datakit) \
--build-arg DIST_DIR=$(DIST_DIR) \
--build-arg CC_HTTP_PROXY=$(CC_HTTP_PROXY) \
-t $(2)/datakit:$(VERSION) \
-f dockerfiles/Dockerfile.$(DOCKERFILE_SUFFIX) . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,datakit-elinker) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/datakit-elinker:$(VERSION) \
-f dockerfiles/Dockerfile_elinker.$(DOCKERFILE_SUFFIX) . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,logfwd) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/logfwd:$(VERSION) \
-f dockerfiles/Dockerfile_logfwd.$(DOCKERFILE_SUFFIX) . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,flameshot) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/flameshot:$(FLAMESHOT_VERSION) \
-f dockerfiles/Dockerfile_flameshot.$(DOCKERFILE_SUFFIX) . --push; \
else \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,datakit) \
--build-arg DIST_DIR=$(DIST_DIR) \
--build-arg CC_HTTP_PROXY=$(CC_HTTP_PROXY) \
-t $(2)/datakit:$(VERSION) \
-f dockerfiles/Dockerfile.$(DOCKERFILE_SUFFIX) . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,datakit-elinker) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/datakit-elinker:$(VERSION) \
-f dockerfiles/Dockerfile_elinker.$(DOCKERFILE_SUFFIX) . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,logfwd) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/logfwd:$(VERSION) \
-f dockerfiles/Dockerfile_logfwd.$(DOCKERFILE_SUFFIX) . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,flameshot) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/flameshot:$(FLAMESHOT_VERSION) \
-f dockerfiles/Dockerfile_flameshot.$(DOCKERFILE_SUFFIX) . --push; \
fi
endef
define build_uos_image
echo 'publishing to $(2)...';
sudo docker buildx build --platform $(1) $(call buildx_cache_args,datakit-uos) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/datakit:$(VERSION) \
-f dockerfiles/Dockerfile.uos . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,datakit-elinker-uos) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/datakit-elinker:$(VERSION) \
-f dockerfiles/Dockerfile_elinker.uos . --push && \
sudo docker buildx build --platform $(1) $(call buildx_cache_args,logfwd-uos) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(2)/logfwd:$(VERSION) \
-f dockerfiles/Dockerfile_logfwd.uos . --push;
endef
define show_poor_logs
# 没有传参的日志,我们认为其日志信息是不够完整的,日志的意义也相对不大
@grep --color=always \
--exclude-dir=vendor \
--exclude="*_test.go" \
--exclude-dir=.git \
--exclude=*.html \
-nr '\.Debugf(\|\.Debug(\|\.Infof(\|\.Info(\|\.Warnf(\|\.Warn(\|\.Errorf(\|\.Error(' . | grep -vE "\"|uhttp|\`" && \
{ echo "[E] some bad loggings in code"; exit -1; } || \
{ echo "all loggings ok"; exit ; }
endef
define check_golint_version
@case $(GOLINT_VERSION) in \
$(SUPPORTED_GOLINT_VERSION)) \
;; \
$(SUPPORTED_GOLINT_VERSION_ANOTHER)) \
;; \
*) \
echo '$(GOLINT_VERSION_ERR_MSG)'; \
exit 1; \
esac;
endef
define build_ip2isp
rm -rf china-operator-ip
git clone -b ip-lists https://github.com/gaoyifan/china-operator-ip.git
@$(GO_MODULE_ENV) CGO_ENABLED=0 go run -tags with_inputs cmd/make/make.go -build-isp -log-level $(LOG_LEVEL)
endef
build_external_local:
@$(MAKE) --no-print-directory -C externals build_external_local \
GO_MODULE_MODE="$(GO_MODULE_MODE)" \
EXTERNAL_NAME="$(EXTERNAL_NAME)" \
EXTERNAL_GOOS="$(EXTERNAL_GOOS)" \
EXTERNAL_ARCH="$(EXTERNAL_ARCH)" \
EXTERNAL_OUTDIR="$(EXTERNAL_OUTDIR)" \
EXTERNAL_OUTPUT="$(EXTERNAL_OUTPUT)" \
EXTERNAL_LDFLAGS="$(EXTERNAL_LDFLAGS)" \
EXTERNAL_EBPF_ARGS="$(EXTERNAL_EBPF_ARGS)" \
EXTERNAL_EBPF_TARGET="$(EXTERNAL_EBPF_TARGET)" \
DK_BPF_KERNEL_SRC_PATH="$(DK_BPF_KERNEL_SRC_PATH)" \
EXTERNAL_SYSROOT_BASE="$(EXTERNAL_SYSROOT_BASE)"
ebpf_nocgo_ci: prepare
@set -eu; \
image="$(DK_BUILD_ENV_IMAGE)"; \
test -n "$$image" || { echo "DK_BUILD_ENV_IMAGE is required"; exit 1; }; \
rm -rf .tmp/dk-ebpf-ci-* .tmp/datakit-ebpf-linux-*-nocgo; \
mkdir -p .tmp; \
for arch in $(EBPF_CI_ARCHS); do \
echo "===== build ebpf objects in dk build env: linux/$$arch ====="; \
docker run --rm --platform "$(EBPF_CI_DOCKER_PLATFORM)" \
-v "$(CURDIR):/work" -w /work "$$image" \
bash -lc "make --no-print-directory -C externals build_external_local EXTERNAL_NAME=ebpf EXTERNAL_GOOS=linux EXTERNAL_ARCH=$$arch EXTERNAL_OUTDIR=/work/.tmp/dk-ebpf-ci-$$arch EXTERNAL_OUTPUT=datakit-ebpf GO_MODULE_MODE=$(GO_MODULE_MODE) DK_BPF_KERNEL_SRC_PATH=/usr/src/linux-headers-$$arch EXTERNAL_EBPF_TARGET=bpfobjs"; \
docker run --rm --platform "$(EBPF_CI_DOCKER_PLATFORM)" \
-v "$(CURDIR):/work" -w /work "$$image" \
chown -R "$$(id -u):$$(id -g)" "/work/.tmp/dk-ebpf-ci-$$arch" "/work/internal/plugins/externals/ebpf/internal/c/elf/linux_$$arch"; \
echo "===== build datakit-ebpf locally without cgo: linux/$$arch ====="; \
GO111MODULE=on GOFLAGS=-mod=$(GO_MODULE_MODE) GOOS=linux GOARCH=$$arch CGO_ENABLED=0 \
go build -tags "ebpf netgo" -buildvcs=false \
-o ".tmp/datakit-ebpf-linux-$$arch-nocgo" \
./internal/plugins/externals/ebpf/cmd/datakit-ebpf; \
done; \
rm -rf .tmp/dk-ebpf-ci-* .tmp/datakit-ebpf-linux-*-nocgo
##############################################################################
# Rules in the Makefile
##############################################################################
local: deps
$(call build_bin,local,$(LOCAL_ARCHS))
pub_local: deps
$(call publish,local,$(LOCAL_ARCHS))
testing_notify: deps
$(call notify_build,testing,$(DEFAULT_ARCHS))
testing: deps
$(call build_bin,testing,$(DEFAULT_ARCHS))
$(call publish,testing,$(DEFAULT_ARCHS))
testing_image:
$(call build_docker_image,$(DOCKER_IMAGE_ARCHS),'registry.jiagouyun.com/datakit')
# we also publishing testing image to public image repo
$(call build_docker_image,$(DOCKER_IMAGE_ARCHS),$(DOCKER_IMAGE_REPO))
production_notify: deps
$(call notify_build,production,$(DEFAULT_ARCHS))
production: deps # stable release
$(call build_bin,production,$(DEFAULT_ARCHS))
$(call publish,production,$(DEFAULT_ARCHS))
production_image:
$(call build_docker_image,$(DOCKER_IMAGE_ARCHS),$(DOCKER_IMAGE_REPO))
uos_image_testing: deps
$(call build_uos_image,$(UOS_DOCKER_IMAGE_ARCHS),'registry.jiagouyun.com/uos-dataflux') # testing image always push to registry.jiagouyun.com
$(call build_uos_image,$(UOS_DOCKER_IMAGE_ARCHS),$(DOCKER_IMAGE_REPO)) # we also publishing testing image to public image repo
uos_image_production: deps
$(call build_uos_image,$(UOS_DOCKER_IMAGE_ARCHS),$(DOCKER_IMAGE_REPO))
production_mac: deps
$(call build_bin,production,$(MAC_ARCHS))
$(call publish,production,$(MAC_ARCHS))
ip2isp:
$(call build_ip2isp)
build_dca_web:
mkdir -p $(DIST_DIR)
cd dca && npm ci --registry=http://registry.npmmirror.com --disturl=http://npmmirror.com/dist --unsafe-perm && \
cd web && npm ci --registry=http://registry.npmmirror.com --disturl=http://npmmirror.com/dist --unsafe-perm && \
cp src/config/config.${BRAND}.ts src/config.ts && \
npm run build \
cd ../..
build_dca: deps build_dca_web
@echo "===== building $(BRAND).dca ====="
@mv dca/web/build $(DIST_DIR)/dca-web # move DCA web(build during build_dca_web) to $(DIST_DIR)
@CGO_CFLAGS=$(CGO_FLAGS) $(GO_MODULE_ENV) CGO_ENABLED=0 \
go run cmd/make/make.go -dca \
-log-level $(LOG_LEVEL) \
-archs $(DCA_BUILD_ARCH) \
-dist-dir $(DIST_DIR) \
-dca-version $(DCA_VERSION) \
-brand $(BRAND)
@echo "===== building $(BRAND).dca done ====="
build_dca_image:
sudo docker buildx build \
--platform $(DOCKER_IMAGE_ARCHS) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(DOCKER_IMAGE_REPO):$(DCA_VERSION) \
-t $(DOCKER_IMAGE_REPO):latest \
-f dca/Dockerfile.$(DOCKERFILE_SUFFIX) . --push;
build_dca_image_test:
sudo docker buildx build \
--platform $(DOCKER_IMAGE_ARCHS) \
$(call buildx_cache_args,dca) \
--build-arg DIST_DIR=$(DIST_DIR) \
-t $(DOCKER_IMAGE_REPO):$(DCA_VERSION) \
-f dca/Dockerfile.$(DOCKERFILE_SUFFIX) . --push;
deps: prepare check_go_version
check_go_version:
@if [ "$(GO_VERSION_ACTUAL)" != "$(GO_VERSION_EXPECTED)" ]; then \
echo '$(GO_VERSION_LOCK_ERR_MSG)'; \
exit 1; \
fi
# ignore files under vendor/.git/git
gofmt:
@gofmt -w -l $(shell find . -type f -name '*.go'| grep -v "/vendor/\|/.git/\|/git/\|.*_y.go\|packed-packr.go")
#golines:
# @golines -w --max-len=150 --reformat-tags -shorten-comments $(shell find . -type f -name '*.go'| grep -v "/vendor/\|/.git/\|/git/\|.*_y.go\|packed-packr.go")
vet:
@go vet ./...
ut: deps
CGO_CFLAGS=$(CGO_FLAGS) $(GO_MODULE_ENV) CGO_ENABLED=1 \
REMOTE_HOST=$(DOCKER_REMOTE_HOST) \
go run cmd/make/make.go \
--log-level $(LOG_LEVEL) \
-ut -ut-exclude $(UT_EXCLUDE) -ut-only $(UT_ONLY) -ut-impacted=$(UT_IMPACTED) -ut-base-branch "$(UT_BASE_BRANCH)" -ut-parallel $(UT_PARALLEL) \
-log-level $(LOG_LEVEL) \
-dataway-url $(DATAWAY_URL); \
if [ $$? != 0 ]; then \
exit 1; \
else \
echo "######################"; \
fi
code_lint: deps copyright_check disable_funcs
@$(GOLINT_BINARY) --version
ifeq ($(AUTO_FIX),true)
@printf "$(HL)lint with auto fix...\n$(NC)"; \
$(GOLINT_BINARY) run --fix --allow-parallel-runners -v;
else
@printf "$(HL)lint without auto fix...\n$(NC)"; \
$(GOLINT_BINARY) run --allow-parallel-runners -v;
endif
@if [ $$? != 0 ]; then \
printf "$(RED)[FAIL] lint failed\n$(NC)"; \
exit -1; \
fi
disable_funcs:
# check print/printf
go run scripts/disable-funcs/main.go -config scripts/disable-funcs/conf.toml;
@if [ $$? != 0 ]; then \
printf "$(RED)[FAIL] lint on print/printf failed\n$(NC)"; \
exit -1; \
fi
# lint code and document
lint: code_lint sample_conf_lint md_lint
prepare:
@mkdir -p internal/git
@echo "$$GIT_INFO" > internal/git/git.go
copyright_check:
@python3 copyright.py --dry-run && \
{ echo "copyright check ok"; exit 0; } || \
{ echo "copyright check failed"; exit 1; }
copyright_check_auto_fix:
@python3 copyright.py --fix
define check_docs
# check spell on docs
@echo 'version of cspell: $(shell cspell --version)'
@echo 'check markdown files under $(1)...'
# custom keys checking
if ./scripts/check-custom-key.sh $(1); then \
echo "custom key check passing..."; \
else \
exit 1; \
fi
# spell checking
cspell lint --show-suggestions \
-c scripts/cspell.json \
--no-progress $(1)/**/*.md | tee $(DIST_DIR)/cspell.lint
@if [ -s $(DIST_DIR)/cspell.lint ]; then \
printf "$(RED) [FAIL] $(DIST_DIR)/cspell.lint not empty \n$(NC)"; \
cat $(DIST_DIR)/cspell.lint; \
exit 1; \
fi
# check markdown style
# markdownlint install: https://github.com/igorshubovych/markdownlint-cli
@echo 'version of markdownlint: $(shell markdownlint --version)'
@truncate -s 0 $(DIST_DIR)/md-lint.json
@if markdownlint -c scripts/markdownlint.yml -j -o $(DIST_DIR)/md-lint.json $(1); then \
printf "markdownlint check ok\n"; \
else \
printf "$(RED) [FAIL] $(DIST_DIR)/md-lint.json not empty \n$(NC)"; \
cat $(DIST_DIR)/md-lint.json; \
exit 1; \
fi
endef
exportdir=$(DIST_DIR)/export
# only check ZH docs, EN docs too many errors
# template generated real markdown files
docs_dir=$(exportdir)/guance-doc/docs
# all markdown template files
docs_template_dir=internal/export/doc
md_lint: md_export
# Check on generated docs
# Disable autofix on checking generated documents.
# Also disable section check on generated docs(there are sections that rended in measurement name)
@$(GO_MODULE_ENV) CGO_ENABLED=0 CGO_CFLAGS=$(CGO_FLAGS) \
go run cmd/make/make.go \
--log-level $(LOG_LEVEL) \
--mdcheck $(docs_dir) \
--mdcheck-no-section-check --mdcheck-no-autofix $(AUTO_FIX)
$(call check_docs,$(docs_dir))
md_export:
@$(GO_MODULE_ENV) CGO_ENABLED=0 CGO_CFLAGS=$(CGO_FLAGS) \
go run cmd/make/make.go \
--log-level $(LOG_LEVEL) \
--mdcheck $(docs_template_dir) \
--mdcheck-no-autofix $(AUTO_FIX);
@rm -rf $(exportdir) && mkdir -p $(exportdir)
@bash export.sh -D $(exportdir) -E
sample_conf_lint:
@$(GO_MODULE_ENV) CGO_ENABLED=0 CGO_CFLAGS=$(CGO_FLAGS) go run -tags with_inputs cmd/make/make.go \
--sample-conf-check --log-level $(LOG_LEVEL)
project_words:
cspell -c cspell/cspell.json --words-only --unique internal/export/doc/zh/** | sort --ignore-case >> project-words.txt
code_stat:
cloc --exclude-dir=vendor,tests --exclude-lang=JSON,HTML .
# promlinter: show prometheuse metrics defined in Datakit.
# go install github.com/yeya24/promlinter/cmd/promlinter@latest
metrics:
@promlinter list . --add-help -o md --with-vendor --add-position > dk.metrics
clean:
@rm -rf build/*
@rm -rf internal/io/parser/gram_y.go
@rm -rf internal/io/parser/gram.y.go
@rm -rf internal/pipeline/parser/parser.y.go
@rm -rf internal/pipeline/parser/parser_y.go
@rm -rf internal/pipeline/parser/gram.y.go
@rm -rf internal/pipeline/parser/gram_y.go
@rm -rf check.err
@rm -rf $(DIST_DIR)/*
detect_mr_target_branch:
@if [ "$(MERGE_REQUEST_TARGET_BRANCH)" = master ] || [ "$(MERGE_REQUEST_TARGET_BRANCH)" = main ]; then \
case "$(MERGE_REQUEST_SOURCE_BRANCH)" in \
dev|hotfix*) \
;; \
*) \
printf "$(RED)[FAIL] merge request from branch '$(MERGE_REQUEST_SOURCE_BRANCH)' to branch '$(MERGE_REQUEST_TARGET_BRANCH)' disabled\n$(NC)"; \
exit 1; \
;; \
esac; \
fi
push_new_version:
@printf "$(HL)push new datakit version $(VERSION)...\n$(NC)"
@if ! curl -s -S -X POST \
-H 'Content-Type: application/json' \
-H "auto_devops_token: $(NEW_VERSION_PUSH_TOKEN)" \
-d '{"version":"$(VERSION)","field_code":"datakit"}' \
"$(NEW_VERSION_PUSH_URL)"; then \
printf "\n$(RED)push version $(VERSION) failed\n$(NC)"; \
exit 1; \
else \
printf "\n$(HL)push version $(VERSION) done\n$(NC)"; \
fi
coverage:
@LOGGER_PATH=nul UT_EXCLUDE_INTEGRATION_TESTING=on gocov test ./... > coverage.json
gocov report coverage.json | grep 'Total Coverage'