github.com/infraboard/keyauth@v0.8.1/Makefile (about)

     1  PROJECT_NAME=keyauth
     2  MAIN_FILE=main.go
     3  PKG := "github.com/infraboard/$(PROJECT_NAME)"
     4  PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
     5  GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
     6  
     7  BUILD_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
     8  BUILD_COMMIT := ${shell git rev-parse HEAD}
     9  BUILD_TIME := ${shell date '+%Y-%m-%d %H:%M:%S'}
    10  BUILD_GO_VERSION := $(shell go version | grep -o  'go[0-9].[0-9].*')
    11  VERSION_PATH := "${PKG}/version"
    12  
    13  .PHONY: all dep lint vet test test-coverage build clean
    14  
    15  all: build
    16  
    17  dep: ## Get the dependencies
    18  	@go mod tidy
    19  
    20  lint: ## Lint Golang files
    21  	@golint -set_exit_status ${PKG_LIST}
    22  
    23  vet: ## Run go vet
    24  	@go vet ${PKG_LIST}
    25  
    26  test: ## Run unittests
    27  	@go test -short ${PKG_LIST}
    28  
    29  test-coverage: ## Run tests with coverage
    30  	@go test -short -coverprofile cover.out -covermode=atomic ${PKG_LIST} 
    31  	@cat cover.out >> coverage.txt
    32  
    33  build: dep ## Build the binary file
    34  	@go build -a -o dist/${PROJECT_NAME} -ldflags "-s -w" -ldflags "-X '${VERSION_PATH}.GIT_BRANCH=${BUILD_BRANCH}' -X '${VERSION_PATH}.GIT_COMMIT=${BUILD_COMMIT}' -X '${VERSION_PATH}.BUILD_TIME=${BUILD_TIME}' -X '${VERSION_PATH}.GO_VERSION=${BUILD_GO_VERSION}'" ${MAIN_FILE}
    35  
    36  linux: dep ## Build the binary file
    37  	@GOOS=linux GOARCH=amd64 go build -a -o dist/${PROJECT_NAME} -ldflags "-s -w" -ldflags "-X '${VERSION_PATH}.GIT_BRANCH=${BUILD_BRANCH}' -X '${VERSION_PATH}.GIT_COMMIT=${BUILD_COMMIT}' -X '${VERSION_PATH}.BUILD_TIME=${BUILD_TIME}' -X '${VERSION_PATH}.GO_VERSION=${BUILD_GO_VERSION}'" ${MAIN_FILE}
    38  
    39  run: # Run Develop server
    40  	@go run $(MAIN_FILE) start
    41  
    42  init: # Init Service
    43  	@go run $(MAIN_FILE) init
    44  
    45  clean: ## Remove previous build
    46  	@rm -f dist/*
    47  
    48  push: # push git to multi repo
    49  	@git push -u gitee
    50  	@git push -u origin
    51  
    52  gen: # Init Service
    53  	@protoc -I=. -I=/usr/local/include --go_out=. --go_opt=module=${PKG} --go-grpc_out=. --go-grpc_opt=module=${PKG} common/types/*.proto
    54  	@protoc -I=. -I=/usr/local/include --go_out=. --go_opt=module=${PKG} --go-grpc_out=. --go-grpc_opt=module=${PKG} apps/*/pb/*.proto
    55  	@protoc-go-inject-tag -input=common/types/*.pb.go
    56  	@protoc-go-inject-tag -input=apps/*/*.pb.go
    57  
    58  install: dep# Install depence go package
    59  	@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
    60  	@go install github.com/infraboard/mcube/cmd/mcube@latest
    61  
    62  help: ## Display this help screen
    63  	@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'