diff --git a/script/githooks/commit-msg b/script/githooks/commit-msg index 86721115f..6ca3048b3 100644 --- a/script/githooks/commit-msg +++ b/script/githooks/commit-msg @@ -56,9 +56,12 @@ test "" = "$(grep '^Signed-off-by: ' "$1" | exit 1 } -./tools/go-gitlint \ - --msg-file=$1 \ - --subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test)(.*)?:\s?.*" \ +# TODO: go-gitlint dir set +GITLINT_DIR="./_output/tools/go-gitlint" + +$GITLINT_DIR \ + --msg-file=$1 \ + --subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test)(.*)?:\s?.*" \ --subject-maxlen=150 \ --subject-minlen=10 \ --body-regex=".*" \ @@ -66,7 +69,10 @@ test "" = "$(grep '^Signed-off-by: ' "$1" | if [ $? -ne 0 ] then - printError "Please fix your commit message to match OpenIM coding standards" + if ! command -v go-gitlint &>/dev/null; then + printError "go-gitlint not found. Please run 'make tools' OR 'make tools.verify.go-gitlint' make verto install it." + fi + printError "Please fix your commit message to match kubecub coding standards" printError "https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694#file-githook-md" exit 1 fi \ No newline at end of file diff --git a/script/make-rules/common.mk b/script/make-rules/common.mk index cfe3adf95..baffba01c 100644 --- a/script/make-rules/common.mk +++ b/script/make-rules/common.mk @@ -48,13 +48,13 @@ endif # TOOLS_DIR: The directory where tools are stored for build and testing. ifeq ($(origin TOOLS_DIR),undefined) -TOOLS_DIR := $(ROOT_DIR)/tools +TOOLS_DIR := $(OUTPUT_DIR)/tools $(shell mkdir -p $(TOOLS_DIR)) endif # TMP_DIR: directory where temporary files are stored. ifeq ($(origin TMP_DIR),undefined) -TMP_DIR := $(ROOT_DIR)/tmp +TMP_DIR := $(OUTPUT_DIR)/tmp $(shell mkdir -p $(TMP_DIR)) endif diff --git a/script/make-rules/copyright.mk b/script/make-rules/copyright.mk index d38c710ba..d01ad7d0f 100644 --- a/script/make-rules/copyright.mk +++ b/script/make-rules/copyright.mk @@ -23,14 +23,14 @@ LICENSE_TEMPLATE ?= $(ROOT_DIR)/script/LICENSE_TEMPLATES .PHONY: copyright.verify copyright.verify: tools.verify.addlicense @echo "===========> Validate boilerplate headers for assign files starting in the $(ROOT_DIR) directory" - @$(GOBIN)/addlicense -v -check -ignore **/test/** -f $(LICENSE_TEMPLATE) $(CODE_DIRS) + @$(TOOLS_DIR)/addlicense -v -check -ignore **/test/** -f $(LICENSE_TEMPLATE) $(CODE_DIRS) @echo "===========> End of boilerplate headers check..." ## copyright.add: Add the boilerplate headers for all files .PHONY: copyright.add copyright.add: tools.verify.addlicense @echo "===========> Adding $(LICENSE_TEMPLATE) the boilerplate headers for all files" - @$(GOBIN)/addlicense -y $(shell date +"%Y") -v -c "OpenIM." -f $(LICENSE_TEMPLATE) $(CODE_DIRS) + @$(TOOLS_DIR)/addlicense -y $(shell date +"%Y") -v -c "OpenIM." -f $(LICENSE_TEMPLATE) $(CODE_DIRS) @echo "===========> End the copyright is added..." # Addlicense Flags: diff --git a/script/make-rules/golang.mk b/script/make-rules/golang.mk index 46ed55129..715a8e328 100644 --- a/script/make-rules/golang.mk +++ b/script/make-rules/golang.mk @@ -136,7 +136,7 @@ go.test: # .PHONY: go.test.junit-report # go.test.junit-report: tools.verify.go-junit-report # @echo "===========> Run unit test > $(TMP_DIR)/report.xml" -# @$(GO) test -v -coverprofile=$(TMP_DIR)/coverage.out 2>&1 $(GO_BUILD_FLAGS) ./... | $(BIN_DIR)/go-junit-report -set-exit-code > $(TMP_DIR)/report.xml +# @$(GO) test -v -coverprofile=$(TMP_DIR)/coverage.out 2>&1 $(GO_BUILD_FLAGS) ./... | $(TOOLS_DIR)/go-junit-report -set-exit-code > $(TMP_DIR)/report.xml # @sed -i '/mock_.*.go/d' $(TMP_DIR)/coverage.out # @echo "===========> Test coverage of Go code is reported to $(TMP_DIR)/coverage.html by generating HTML" # @$(GO) tool cover -html=$(TMP_DIR)/coverage.out -o $(TMP_DIR)/coverage.html @@ -144,11 +144,11 @@ go.test: ## go.test.junit-report: Run unit test .PHONY: go.test.junit-report go.test.junit-report: tools.verify.go-junit-report - @echo "===========> Run unit test > $(OUTPUT_DIR)/report.xml" - @$(GO) test -v -coverprofile=$(OUTPUT_DIR)/coverage.out 2>&1 ./... | $(BIN_DIR)/go-junit-report -set-exit-code > $(OUTPUT_DIR)/report.xml - @sed -i '/mock_.*.go/d' $(OUTPUT_DIR)/coverage.out + @echo "===========> Run unit test > $(TMP_DIR)/report.xml" + @$(GO) test -v -coverprofile=$(TMP_DIR)/coverage.out 2>&1 ./... | $(TOOLS_DIR)/go-junit-report -set-exit-code > $(OUTPUT_DIR)/report.xml + @sed -i '/mock_.*.go/d' $(TMP_DIR)/coverage.out @echo "===========> Test coverage of Go code is reported to $(OUTPUT_DIR)/coverage.html by generating HTML" - @$(GO) tool cover -html=$(OUTPUT_DIR)/coverage.out -o $(OUTPUT_DIR)/coverage.html + @$(GO) tool cover -html=$(TMP_DIR)/coverage.out -o $(TMP_DIR)/coverage.html ## go.test.cover: Run unit test with coverage .PHONY: go.test.cover @@ -162,14 +162,14 @@ go.test.cover: go.test.junit-report go.format: tools.verify.golines tools.verify.goimports @echo "===========> Formating codes" @$(FIND) -type f -name '*.go' | $(XARGS) gofmt -s -w - @$(FIND) -type f -name '*.go' | $(XARGS) $(BIN_DIR)/goimports -w -local $(ROOT_PACKAGE) - @$(FIND) -type f -name '*.go' | $(XARGS) $(BIN_DIR)/golines -w --max-len=120 --reformat-tags --shorten-comments --ignore-generated . + @$(FIND) -type f -name '*.go' | $(XARGS) $(TOOLS_DIR)/goimports -w -local $(ROOT_PACKAGE) + @$(FIND) -type f -name '*.go' | $(XARGS) $(TOOLS_DIR)/golines -w --max-len=120 --reformat-tags --shorten-comments --ignore-generated . @$(GO) mod edit -fmt ## imports: task to automatically handle import packages in Go files using goimports tool .PHONY: go.imports go.imports: tools.verify.goimports - @$(BIN_DIR)/goimports -l -w $(SRC) + @$(TOOLS_DIR)/goimports -l -w $(SRC) ## go.updates: Check for updates to go.mod dependencies .PHONY: go.updates @@ -179,8 +179,8 @@ go.updates: tools.verify.go-mod-outdated ## go.clean: Clean all builds directories and files .PHONY: go.clean go.clean: - @echo "===========> Cleaning all builds OUTPUT_DIR($(OUTPUT_DIR)) AND BIN_DIR($(BIN_DIR))" - @-rm -vrf $(OUTPUT_DIR) $(BIN_DIR) + @echo "===========> Cleaning all builds TMP_DIR($(TMP_DIR)) AND BIN_DIR($(BIN_DIR))" + @-rm -vrf $(TMP_DIR) $(BIN_DIR) @echo "===========> End clean..." ## copyright.help: Show copyright help diff --git a/script/make-rules/tools.mk b/script/make-rules/tools.mk index dda14e5aa..b5c19c778 100644 --- a/script/make-rules/tools.mk +++ b/script/make-rules/tools.mk @@ -58,11 +58,11 @@ tools.install-all.%: .PHONY: tools.verify.% tools.verify.%: @echo "===========> Verifying $* is installed" - @if [ ! -f $(BIN_DIR)/$* ]; then GOBIN=$(BIN_DIR) $(MAKE) tools.install.$*; fi - @echo "===========> $* is install in $(BIN_DIR)/$*" + @if [ ! -f $(TOOLS_DIR)/$* ]; then GOBIN=$(TOOLS_DIR) $(MAKE) tools.install.$*; fi + @echo "===========> $* is install in $(TOOLS_DIR)/$*" -.PHONY: ## install.golangci-lint: Install golangci-lint +.PHONY: install.golangci-lint install.golangci-lint: @$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest