2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
SHELL := /bin/bash
|
|
|
|
CURRENT_PATH = $(shell pwd)
|
|
|
|
APP_NAME = bitxhub
|
2020-12-17 20:11:21 +08:00
|
|
|
export GODEBUG=x509ignoreCN=0
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
# build with verison infos
|
|
|
|
VERSION_DIR = github.com/meshplus/${APP_NAME}
|
|
|
|
BUILD_DATE = $(shell date +%FT%T)
|
|
|
|
GIT_COMMIT = $(shell git log --pretty=format:'%h' -n 1)
|
|
|
|
GIT_BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
|
2021-04-26 11:07:57 +08:00
|
|
|
ifeq (${GIT_BRANCH},HEAD)
|
|
|
|
APP_VERSION = $(shell git describe --tags HEAD)
|
|
|
|
else
|
|
|
|
APP_VERSION = dev
|
|
|
|
endif
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-04-26 22:20:52 +08:00
|
|
|
GOLDFLAGS += -X "${VERSION_DIR}.BuildDate=${BUILD_DATE}"
|
|
|
|
GOLDFLAGS += -X "${VERSION_DIR}.CurrentCommit=${GIT_COMMIT}"
|
|
|
|
GOLDFLAGS += -X "${VERSION_DIR}.CurrentBranch=${GIT_BRANCH}"
|
|
|
|
GOLDFLAGS += -X "${VERSION_DIR}.CurrentVersion=${APP_VERSION}"
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
GO = GO111MODULE=on go
|
2021-02-07 16:04:17 +08:00
|
|
|
TEST_PKGS := $(shell $(GO) list ./... | grep -v 'mock_*' | grep -v 'tester' | grep -v 'proto' | grep -v 'cmd'| grep -v 'api')
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
RED=\033[0;31m
|
|
|
|
GREEN=\033[0;32m
|
|
|
|
BLUE=\033[0;34m
|
|
|
|
NC=\033[0m
|
|
|
|
|
2020-12-08 16:07:26 +08:00
|
|
|
MODS = $(shell sed -e ':a' -e 'N' -e '$$!ba' -e 's/\n/@/g' goent.diff)
|
2020-12-01 15:19:18 +08:00
|
|
|
|
2020-03-29 21:32:01 +08:00
|
|
|
help: Makefile
|
|
|
|
@printf "${BLUE}Choose a command run:${NC}\n"
|
|
|
|
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'
|
|
|
|
|
|
|
|
## make prepare: Preparation before development
|
|
|
|
prepare:
|
2020-04-01 02:06:24 +08:00
|
|
|
@cd scripts && bash prepare.sh
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
## make test: Run go unittest
|
|
|
|
test:
|
|
|
|
go generate ./...
|
2021-02-04 13:52:25 +08:00
|
|
|
@$(GO) test -timeout 300s ${TEST_PKGS} -count=1
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
## make test-coverage: Test project with cover
|
|
|
|
test-coverage:
|
2020-04-01 02:06:24 +08:00
|
|
|
go generate ./...
|
2021-02-04 13:52:25 +08:00
|
|
|
@go test -timeout 300s -short -coverprofile cover.out -covermode=atomic ${TEST_PKGS}
|
2020-10-20 14:07:43 +08:00
|
|
|
@cat cover.out | grep -v "pb.go" >> coverage.txt
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
## make tester: Run integration test
|
|
|
|
tester:
|
2021-02-05 10:27:02 +08:00
|
|
|
go generate ./...
|
2020-03-29 21:32:01 +08:00
|
|
|
cd tester && $(GO) test -v -run TestTester
|
|
|
|
|
|
|
|
## make install: Go install the project
|
2020-10-22 22:16:41 +08:00
|
|
|
install:
|
2020-03-29 21:32:01 +08:00
|
|
|
cd internal/repo && packr
|
2020-12-01 15:19:18 +08:00
|
|
|
rm -f imports/imports.go
|
2020-10-23 10:37:08 +08:00
|
|
|
$(GO) install -ldflags '${GOLDFLAGS}' ./cmd/${APP_NAME}
|
|
|
|
@printf "${GREEN}Install bitxhub successfully!${NC}\n"
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-10-22 22:16:41 +08:00
|
|
|
build:
|
2020-03-30 12:59:22 +08:00
|
|
|
cd internal/repo && packr
|
|
|
|
@mkdir -p bin
|
2020-12-01 15:19:18 +08:00
|
|
|
rm -f imports/imports.go
|
2020-10-23 10:37:08 +08:00
|
|
|
$(GO) build -ldflags '${GOLDFLAGS}' ./cmd/${APP_NAME}
|
2020-03-30 12:59:22 +08:00
|
|
|
@mv ./bitxhub bin
|
|
|
|
@printf "${GREEN}Build bitxhub successfully!${NC}\n"
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-10-23 10:37:08 +08:00
|
|
|
installent:
|
|
|
|
cd internal/repo && packr
|
2020-12-01 15:19:18 +08:00
|
|
|
cp imports/imports.go.template imports/imports.go
|
2020-12-08 16:07:26 +08:00
|
|
|
@sed "s?)?$(MODS)@)?" go.mod | tr '@' '\n' > goent.mod
|
2020-10-23 10:37:08 +08:00
|
|
|
$(GO) install -tags ent -ldflags '${GOLDFLAGS}' -modfile goent.mod ./cmd/${APP_NAME}
|
|
|
|
@printf "${GREEN}Install bitxhub ent successfully!${NC}\n"
|
|
|
|
|
|
|
|
buildent:
|
|
|
|
cd internal/repo && packr
|
|
|
|
@mkdir -p bin
|
2020-12-01 15:19:18 +08:00
|
|
|
cp imports/imports.go.template imports/imports.go
|
2020-12-08 16:07:26 +08:00
|
|
|
@sed "s?)?$(MODS)@)?" go.mod | tr '@' '\n' > goent.mod
|
2020-10-23 10:37:08 +08:00
|
|
|
$(GO) build -tags ent -ldflags '${GOLDFLAGS}' -modfile goent.mod ./cmd/${APP_NAME}
|
|
|
|
@mv ./bitxhub bin
|
|
|
|
@printf "${GREEN}Build bitxhub ent successfully!${NC}\n"
|
|
|
|
|
2021-04-06 15:30:35 +08:00
|
|
|
## make release: Build release before push
|
|
|
|
release-binary:
|
2021-04-26 11:07:57 +08:00
|
|
|
@cd scripts && bash release_binary.sh
|
2021-04-06 15:30:35 +08:00
|
|
|
|
2020-12-01 15:19:18 +08:00
|
|
|
mod:
|
|
|
|
sed "s?)?$(MODS)\n)?" go.mod
|
|
|
|
|
2020-03-29 21:32:01 +08:00
|
|
|
## make linter: Run golanci-lint
|
|
|
|
linter:
|
2020-03-31 14:00:16 +08:00
|
|
|
golangci-lint run
|
2020-03-29 21:32:01 +08:00
|
|
|
|
|
|
|
## make cluster: Run cluster including 4 nodes
|
2020-10-23 10:37:08 +08:00
|
|
|
cluster:install${TAGS}
|
2020-12-08 16:32:06 +08:00
|
|
|
@cd scripts && bash cluster.sh TAGS=${TAGS}
|
2020-03-29 21:32:01 +08:00
|
|
|
|
2020-11-18 22:31:51 +08:00
|
|
|
## make solo: Run one node in solo mode
|
|
|
|
solo:install${TAGS}
|
2020-12-08 16:32:06 +08:00
|
|
|
@cd scripts && bash solo.sh TAGS=${TAGS}
|
2020-11-18 22:31:51 +08:00
|
|
|
|
2020-06-09 16:52:00 +08:00
|
|
|
.PHONY: tester build
|