github.com/amplia-iiot/yutil@v1.0.1-0.20231229120411-5d96a4c5a136/Makefile (about) 1 GOCMD=go 2 GOTEST=$(GOCMD) test 3 GOVET=$(GOCMD) vet 4 GORUN=$(GOCMD) run 5 BINARY=yutil 6 VERSION?=$(shell git describe --tags --always) 7 BUILD=`git rev-parse HEAD` 8 DOCKER_REGISTRY?= #if set it should finished by / 9 EXPORT_RESULT?=true # for CI please set EXPORT_RESULT to true 10 11 LDFLAGS ?= "-X 'main.version=$(VERSION)' -X 'main.commit=$(shell git rev-parse HEAD)' -X 'main.date=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")' -X 'main.builtBy=$(shell whoami)'" 12 13 14 RED := $(shell tput -Txterm setaf 1) 15 GREEN := $(shell tput -Txterm setaf 2) 16 YELLOW := $(shell tput -Txterm setaf 3) 17 CYAN := $(shell tput -Txterm setaf 6) 18 WHITE := $(shell tput -Txterm setaf 7) 19 RESET := $(shell tput -Txterm sgr0) 20 21 .PHONY: all test build 22 23 ifndef VERBOSE 24 .SILENT: 25 endif 26 27 all: help 28 29 ############### 30 ##@ Development 31 32 deps: ## Download dependencies 33 GO111MODULE=on $(GOCMD) mod download 34 35 set-up: ## Set up development environment 36 $(GOCMD) install github.com/axw/gocov/gocov@latest 37 $(GOCMD) install github.com/AlekSi/gocov-xml@latest 38 $(GOCMD) install github.com/jstemmer/go-junit-report@latest 39 $(GOCMD) install github.com/cosmtrek/air@latest 40 $(GOCMD) install github.com/spf13/cobra-cli@latest 41 $(GOCMD) install github.com/goreleaser/goreleaser@v1.18.2 42 $(GOCMD) install github.com/git-chglog/git-chglog/cmd/git-chglog@latest 43 $(GOCMD) install github.com/caarlos0/svu@latest 44 $(GOCMD) install github.com/golangci/golangci-lint/cmd/golangci-lint@latest 45 $(GOCMD) install golang.org/x/tools/cmd/godoc@latest 46 47 clean: ## Remove build related files 48 rm -rf ./out ./tmp ./dist 49 rm -f ${BINARY} ./junit-report.xml checkstyle-report.xml ./coverage.xml ./profile.cov yamllint-checkstyle.xml 50 51 test: ## Run tests 52 ifeq ($(EXPORT_RESULT), true) 53 $(eval OUTPUT_OPTIONS = | tee /dev/tty | go-junit-report -set-exit-code > junit-report.xml) 54 endif 55 GOFLAGS="-count=1" $(GOTEST) -v -race ./... $(OUTPUT_OPTIONS) 56 57 lint: ## Run linters 58 golangci-lint run 59 60 check: ## Check the source code (test & lint) 61 ifeq ($(INCLUDE_COVERAGE), true) 62 ( ( (EXPORT_RESULT=true $(MAKE) -s coverage) && printf '${GREEN}Tests - OK${RESET}\n' ) || printf '${RED}Tests - failed${RESET}\n' ) 63 else 64 ( ( ($(MAKE) -s test) && printf '${GREEN}Tests - OK${RESET}\n' ) || printf '${RED}Tests - failed${RESET}\n' ) 65 endif 66 ( ( ($(MAKE) -s lint) && printf '${GREEN}Lint - OK${RESET}\n' ) || printf '${RED}Lint - failed${RESET}\n' ) 67 68 watch: ## Run check when a change is detected 69 air 70 71 coverage: ## Generate a coverage report 72 $(GOTEST) -cover -covermode=count -coverprofile=profile.cov ./... 73 $(GOCMD) tool cover -func profile.cov 74 ifeq ($(EXPORT_RESULT), true) 75 gocov convert profile.cov | gocov-xml > coverage.xml 76 endif 77 78 build: ## Build for current arch 79 GO111MODULE=on $(GOCMD) build -ldflags=$(LDFLAGS) -o ${BINARY} 80 81 docs: ## Serve the docs 82 @echo "module docs on http://localhost:6060/pkg/github.com/amplia-iiot/yutil" 83 @godoc -http localhost:6060 84 85 ########### 86 ##@ Release 87 88 changelog: ## Generate changelog 89 git-chglog --next-tag $(VERSION) -o CHANGELOG.md 90 91 version: VERSION=$(shell svu next || echo "v1.0.0") 92 version: changelog ## Generate version 93 git add CHANGELOG.md 94 ifdef CO_AUTHOR 95 git commit -m "chore: update changelog for $(VERSION)" -m "Co-authored-by: $(CO_AUTHOR)" 96 else 97 git commit -m "chore: update changelog for $(VERSION)" 98 endif 99 git tag -a $(VERSION) -m "$(patsubst v%,Version %,$(VERSION))" 100 101 release-notes: ## Print release notes for current version 102 git-chglog -c .chglog/release-notes.yml $(shell svu current || echo "--next-tag v1.0.0") 103 104 release: ## Build release 105 ifeq ($(EXPORT_RESULT), true) 106 goreleaser --rm-dist --release-notes <($(MAKE) -s release-notes) 107 else 108 YUTIL_NEXT="$(VERSION)" goreleaser --snapshot --skip-publish --rm-dist 109 endif 110 111 ######## 112 ##@ Help 113 114 help: ## Show this help 115 @awk ' \ 116 BEGIN { \ 117 FS = ":.*##" ; \ 118 printf "Usage:\n make ${YELLOW}<target>${RESET}\n" \ 119 } \ 120 /^[a-zA-Z_-]+:.*?##/ { \ 121 printf " ${YELLOW}%-16s${RESET}%s\n", $$1, $$2 \ 122 } \ 123 /^##@/ { \ 124 printf "\n${CYAN}%s:${RESET}\n", substr($$0, 5) \ 125 } \ 126 ' $(MAKEFILE_LIST)