feat(main): optimized scripts and makefile

Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
pull/428/head
Xinwei Xiong(cubxxw) 2 years ago
parent c3a3c523b3
commit 078ac197ab

@ -56,7 +56,10 @@ test "" = "$(grep '^Signed-off-by: ' "$1" |
exit 1 exit 1
} }
./tools/go-gitlint \ # TODO: go-gitlint dir set
GITLINT_DIR="./_output/tools/go-gitlint"
$GITLINT_DIR \
--msg-file=$1 \ --msg-file=$1 \
--subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test)(.*)?:\s?.*" \ --subject-regex="^(build|chore|ci|docs|feat|feature|fix|perf|refactor|revert|style|test)(.*)?:\s?.*" \
--subject-maxlen=150 \ --subject-maxlen=150 \
@ -66,7 +69,10 @@ test "" = "$(grep '^Signed-off-by: ' "$1" |
if [ $? -ne 0 ] if [ $? -ne 0 ]
then 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" printError "https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694#file-githook-md"
exit 1 exit 1
fi fi

@ -48,13 +48,13 @@ endif
# TOOLS_DIR: The directory where tools are stored for build and testing. # TOOLS_DIR: The directory where tools are stored for build and testing.
ifeq ($(origin TOOLS_DIR),undefined) ifeq ($(origin TOOLS_DIR),undefined)
TOOLS_DIR := $(ROOT_DIR)/tools TOOLS_DIR := $(OUTPUT_DIR)/tools
$(shell mkdir -p $(TOOLS_DIR)) $(shell mkdir -p $(TOOLS_DIR))
endif endif
# TMP_DIR: directory where temporary files are stored. # TMP_DIR: directory where temporary files are stored.
ifeq ($(origin TMP_DIR),undefined) ifeq ($(origin TMP_DIR),undefined)
TMP_DIR := $(ROOT_DIR)/tmp TMP_DIR := $(OUTPUT_DIR)/tmp
$(shell mkdir -p $(TMP_DIR)) $(shell mkdir -p $(TMP_DIR))
endif endif

@ -23,14 +23,14 @@ LICENSE_TEMPLATE ?= $(ROOT_DIR)/script/LICENSE_TEMPLATES
.PHONY: copyright.verify .PHONY: copyright.verify
copyright.verify: tools.verify.addlicense copyright.verify: tools.verify.addlicense
@echo "===========> Validate boilerplate headers for assign files starting in the $(ROOT_DIR) directory" @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..." @echo "===========> End of boilerplate headers check..."
## copyright.add: Add the boilerplate headers for all files ## copyright.add: Add the boilerplate headers for all files
.PHONY: copyright.add .PHONY: copyright.add
copyright.add: tools.verify.addlicense copyright.add: tools.verify.addlicense
@echo "===========> Adding $(LICENSE_TEMPLATE) the boilerplate headers for all files" @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..." @echo "===========> End the copyright is added..."
# Addlicense Flags: # Addlicense Flags:

@ -136,7 +136,7 @@ go.test:
# .PHONY: go.test.junit-report # .PHONY: go.test.junit-report
# go.test.junit-report: tools.verify.go-junit-report # go.test.junit-report: tools.verify.go-junit-report
# @echo "===========> Run unit test > $(TMP_DIR)/report.xml" # @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 # @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" # @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 # @$(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 ## go.test.junit-report: Run unit test
.PHONY: go.test.junit-report .PHONY: go.test.junit-report
go.test.junit-report: tools.verify.go-junit-report go.test.junit-report: tools.verify.go-junit-report
@echo "===========> Run unit test > $(OUTPUT_DIR)/report.xml" @echo "===========> Run unit test > $(TMP_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 @$(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' $(OUTPUT_DIR)/coverage.out @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" @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 ## go.test.cover: Run unit test with coverage
.PHONY: go.test.cover .PHONY: go.test.cover
@ -162,14 +162,14 @@ go.test.cover: go.test.junit-report
go.format: tools.verify.golines tools.verify.goimports go.format: tools.verify.golines tools.verify.goimports
@echo "===========> Formating codes" @echo "===========> Formating codes"
@$(FIND) -type f -name '*.go' | $(XARGS) gofmt -s -w @$(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) $(TOOLS_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)/golines -w --max-len=120 --reformat-tags --shorten-comments --ignore-generated .
@$(GO) mod edit -fmt @$(GO) mod edit -fmt
## imports: task to automatically handle import packages in Go files using goimports tool ## imports: task to automatically handle import packages in Go files using goimports tool
.PHONY: go.imports .PHONY: go.imports
go.imports: tools.verify.goimports 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 ## go.updates: Check for updates to go.mod dependencies
.PHONY: go.updates .PHONY: go.updates
@ -179,8 +179,8 @@ go.updates: tools.verify.go-mod-outdated
## go.clean: Clean all builds directories and files ## go.clean: Clean all builds directories and files
.PHONY: go.clean .PHONY: go.clean
go.clean: go.clean:
@echo "===========> Cleaning all builds OUTPUT_DIR($(OUTPUT_DIR)) AND BIN_DIR($(BIN_DIR))" @echo "===========> Cleaning all builds TMP_DIR($(TMP_DIR)) AND BIN_DIR($(BIN_DIR))"
@-rm -vrf $(OUTPUT_DIR) $(BIN_DIR) @-rm -vrf $(TMP_DIR) $(BIN_DIR)
@echo "===========> End clean..." @echo "===========> End clean..."
## copyright.help: Show copyright help ## copyright.help: Show copyright help

@ -58,11 +58,11 @@ tools.install-all.%:
.PHONY: tools.verify.% .PHONY: tools.verify.%
tools.verify.%: tools.verify.%:
@echo "===========> Verifying $* is installed" @echo "===========> Verifying $* is installed"
@if [ ! -f $(BIN_DIR)/$* ]; then GOBIN=$(BIN_DIR) $(MAKE) tools.install.$*; fi @if [ ! -f $(TOOLS_DIR)/$* ]; then GOBIN=$(TOOLS_DIR) $(MAKE) tools.install.$*; fi
@echo "===========> $* is install in $(BIN_DIR)/$*" @echo "===========> $* is install in $(TOOLS_DIR)/$*"
.PHONY:
## install.golangci-lint: Install golangci-lint ## install.golangci-lint: Install golangci-lint
.PHONY: install.golangci-lint
install.golangci-lint: install.golangci-lint:
@$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest @$(GO) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

Loading…
Cancel
Save