54 lines
1.6 KiB
Makefile
54 lines
1.6 KiB
Makefile
# set package name and path
|
|
package_name = datart
|
|
|
|
# set package path
|
|
package_path = .
|
|
|
|
# ==================================================================================== #
|
|
# DEFAULT
|
|
# ==================================================================================== #
|
|
|
|
default: help
|
|
|
|
.PHONY: help
|
|
help: ## list makefile function
|
|
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
|
|
|
# ==================================================================================== #
|
|
# QUALITY
|
|
# ==================================================================================== #
|
|
|
|
.PHONY: tidy
|
|
tidy: ## tidy modfiles and format .go files
|
|
@go mod tidy -v
|
|
@go fmt ./...
|
|
|
|
.PHONY: test
|
|
test: ## run all tests
|
|
go test -v -race -buildvcs ./...
|
|
|
|
.PHONY: cover
|
|
cover: ## run all tests and display coverage
|
|
go test -v -race -buildvcs -coverprofile=${package_path}/coverage.out ./...
|
|
go tool cover -func=coverage.out | sort -rnk3
|
|
|
|
# ==================================================================================== #
|
|
# DEVELOPMENT
|
|
# ==================================================================================== #
|
|
|
|
.PHONY: build
|
|
build: ## build the application
|
|
@go mod download
|
|
@go build -ldflags "-X main.version=$(shell git describe --abbrev=0 --tags 2>/dev/null || echo 0.0.0)" -o=${package_path}/${package_name}
|
|
|
|
.PHONY: run
|
|
run: build ## run the application after build
|
|
@chmod +x ${package_path}/${package_name}
|
|
${package_path}/${package_name}
|
|
|
|
.PHONY: clean
|
|
clean: ## clean up environment
|
|
@go clean
|
|
@rm -f ${package_path}/${package_name}
|
|
@rm -f ${package_path}/coverage.out
|