From 1a6f12c88ef745d5605c23d78088f4b3b70c3952 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Wed, 26 Jul 2023 10:24:37 +0200 Subject: [PATCH] Build target for "make tidy" (#2378) The make tidy target runs "go mod tidy" in the root directory and all plugins. --- Makefile | 18 ++++++++++++++---- cmd/crowdsec-cli/Makefile | 6 +++--- cmd/crowdsec/Makefile | 6 +++--- docker/test/tests/test_capi_whitelists.py | 2 +- plugins/notifications/dummy/Makefile | 4 ++-- plugins/notifications/email/Makefile | 4 ++-- plugins/notifications/http/Makefile | 4 ++-- plugins/notifications/sentinel/Makefile | 4 ++-- plugins/notifications/slack/Makefile | 4 ++-- plugins/notifications/splunk/Makefile | 4 ++-- 10 files changed, 33 insertions(+), 23 deletions(-) diff --git a/Makefile b/Makefile index 543f60177..7a8fa68c7 100644 --- a/Makefile +++ b/Makefile @@ -31,8 +31,8 @@ BUILD_REQUIRE_GO_MINOR ?= 20 #-------------------------------------- -GOCMD = go -GOTEST = $(GOCMD) test +GO = go +GOTEST = $(GO) test BUILD_CODENAME ?= alphaga @@ -209,12 +209,21 @@ PLUGIN_VENDOR = $(foreach plugin,$(PLUGINS),$(shell if [ -f $(PLUGINS_DIR)/$(plu vendor: $(foreach plugin_dir,$(PLUGIN_VENDOR), \ cd $(plugin_dir) >/dev/null && \ - $(GOCMD) mod vendor && \ + $(GO) mod vendor && \ cd - >/dev/null; \ ) - $(GOCMD) mod vendor + $(GO) mod vendor tar -czf vendor.tgz vendor $(foreach plugin_dir,$(PLUGIN_VENDOR),$(plugin_dir)/vendor) +.PHONY: tidy +tidy: + $(GO) mod tidy + $(foreach plugin_dir,$(PLUGIN_VENDOR), \ + cd $(plugin_dir) >/dev/null && \ + $(GO) mod tidy && \ + cd - >/dev/null; \ + ) + # remove vendor directories and vendor.tgz .PHONY: vendor-remove vendor-remove: @@ -223,6 +232,7 @@ vendor-remove: ) $(RM) vendor vendor.tgz + .PHONY: package package: @echo "Building Release to dir $(RELDIR)" diff --git a/cmd/crowdsec-cli/Makefile b/cmd/crowdsec-cli/Makefile index f4d66157f..cd7eedff6 100644 --- a/cmd/crowdsec-cli/Makefile +++ b/cmd/crowdsec-cli/Makefile @@ -5,9 +5,9 @@ ifeq ($(OS), Windows_NT) endif # Go parameters -GOCMD = go -GOBUILD = $(GOCMD) build -GOTEST = $(GOCMD) test +GO = go +GOBUILD = $(GO) build +GOTEST = $(GO) test BINARY_NAME = cscli$(EXT) PREFIX ?= "/" diff --git a/cmd/crowdsec/Makefile b/cmd/crowdsec/Makefile index 8242f1b49..2513873e8 100644 --- a/cmd/crowdsec/Makefile +++ b/cmd/crowdsec/Makefile @@ -5,9 +5,9 @@ ifeq ($(OS), Windows_NT) endif # Go parameters -GOCMD = go -GOBUILD = $(GOCMD) build -GOTEST = $(GOCMD) test +GO = go +GOBUILD = $(GO) build +GOTEST = $(GO) test CROWDSEC_BIN = crowdsec$(EXT) # names longer than 15 chars break 'pgrep' diff --git a/docker/test/tests/test_capi_whitelists.py b/docker/test/tests/test_capi_whitelists.py index f8e3c17c0..19378ba86 100644 --- a/docker/test/tests/test_capi_whitelists.py +++ b/docker/test/tests/test_capi_whitelists.py @@ -25,7 +25,7 @@ def test_capi_whitelists(crowdsec, tmp_path_factory, flavor,): with crowdsec(flavor=flavor, environment=env, volumes=volumes) as cs: cs.wait_for_log("*Starting processing data*") cs.wait_for_http(8080, '/health', want_status=HTTPStatus.OK) - res = cs.cont.exec_run(f'cscli config show-yaml') + res = cs.cont.exec_run('cscli config show-yaml') assert res.exit_code == 0 stdout = res.output.decode() y = yaml.safe_load(stdout) diff --git a/plugins/notifications/dummy/Makefile b/plugins/notifications/dummy/Makefile index d45d6f198..e6081de49 100644 --- a/plugins/notifications/dummy/Makefile +++ b/plugins/notifications/dummy/Makefile @@ -7,8 +7,8 @@ endif PLUGIN = dummy BINARY_NAME = notification-$(PLUGIN)$(EXT) -GOCMD = go -GOBUILD = $(GOCMD) build +GO = go +GOBUILD = $(GO) build build: clean $(GOBUILD) $(LD_OPTS) $(BUILD_VENDOR_FLAGS) -o $(BINARY_NAME) diff --git a/plugins/notifications/email/Makefile b/plugins/notifications/email/Makefile index ae548af0a..096b0c40c 100644 --- a/plugins/notifications/email/Makefile +++ b/plugins/notifications/email/Makefile @@ -7,8 +7,8 @@ endif PLUGIN = email BINARY_NAME = notification-$(PLUGIN)$(EXT) -GOCMD = go -GOBUILD = $(GOCMD) build +GO = go +GOBUILD = $(GO) build build: clean $(GOBUILD) $(LD_OPTS) $(BUILD_VENDOR_FLAGS) -o $(BINARY_NAME) diff --git a/plugins/notifications/http/Makefile b/plugins/notifications/http/Makefile index 56f490772..4545b6910 100644 --- a/plugins/notifications/http/Makefile +++ b/plugins/notifications/http/Makefile @@ -7,8 +7,8 @@ endif PLUGIN=http BINARY_NAME = notification-$(PLUGIN)$(EXT) -GOCMD = go -GOBUILD = $(GOCMD) build +GO = go +GOBUILD = $(GO) build build: clean $(GOBUILD) $(LD_OPTS) $(BUILD_VENDOR_FLAGS) -o $(BINARY_NAME) diff --git a/plugins/notifications/sentinel/Makefile b/plugins/notifications/sentinel/Makefile index 4f44a3e19..df2a23fe6 100644 --- a/plugins/notifications/sentinel/Makefile +++ b/plugins/notifications/sentinel/Makefile @@ -5,8 +5,8 @@ ifeq ($(OS), Windows_NT) endif # Go parameters -GOCMD = go -GOBUILD = $(GOCMD) build +GO = go +GOBUILD = $(GO) build BINARY_NAME = notification-sentinel$(EXT) diff --git a/plugins/notifications/slack/Makefile b/plugins/notifications/slack/Makefile index f43303eb8..bd7ea8146 100644 --- a/plugins/notifications/slack/Makefile +++ b/plugins/notifications/slack/Makefile @@ -7,8 +7,8 @@ endif PLUGIN=slack BINARY_NAME = notification-$(PLUGIN)$(EXT) -GOCMD = go -GOBUILD = $(GOCMD) build +GO = go +GOBUILD = $(GO) build build: clean $(GOBUILD) $(LD_OPTS) $(BUILD_VENDOR_FLAGS) -o $(BINARY_NAME) diff --git a/plugins/notifications/splunk/Makefile b/plugins/notifications/splunk/Makefile index a7f04f4d0..669779ff3 100644 --- a/plugins/notifications/splunk/Makefile +++ b/plugins/notifications/splunk/Makefile @@ -7,8 +7,8 @@ endif PLUGIN=splunk BINARY_NAME = notification-$(PLUGIN)$(EXT) -GOCMD = go -GOBUILD = $(GOCMD) build +GO = go +GOBUILD = $(GO) build build: clean $(GOBUILD) $(LD_OPTS) $(BUILD_VENDOR_FLAGS) -o $(BINARY_NAME)