1 Star 0 Fork 1

Sam皮皮/brm

forked from enmotech/brm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Makefile 10.28 KB
一键复制 编辑 原始数据 按行查看 历史
travelliu 提交于 2024-07-19 11:24 . init commit
BINARY_PATH := $(CURDIR)/bin
PACKAGE_NAME =brm
BRM_BINARY_NAME =brm
BRM_TEST_BINARY_NAME = brm-test
BRM_MEDIA_SERVER_BINARY_NAME = brm-media-server
VERSION_PATH = pkg/version
V = 0
Q = $(if $(filter 1,$V),,@)
M = $(shell printf "\033[34;1m▶\033[0m")
DOCKER_USERNAME=mogdb
PKGS = $(or $(PKG),$(shell $(GO) list ./...|grep -v obs|grep -v oraxml))
TESTPKGS = $(shell $(GO) list -f '{{ if or .TestGoFiles .XTestGoFiles }}{{ .ImportPath }}{{ end }}' $(PKGS))
DEFAULT_GORELEASER_FILE=.goreleaser.yaml
### ################################################
### tools
### ################################################
# xgo https://github.com/techknowlogick/xgo
#
GO = go
GOLINT = golangci-lint
GOCOVMERGE = gocovmerge
GOCOV = gocov
GOCOVXML = gocov-xml
GO2XUNIT = go2xunit
CHGLOG = git-chglog
BUILD_DATE = $(shell date '+%Y-%m-%d %H:%M:%S')
GIT_COMMIT = $(shell git rev-parse HEAD)
GIT_SHA = $(shell git rev-parse --short HEAD)
GIT_BRANCH = $(shell git describe --tags --always 2>/dev/null)
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean")
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null)
BASE_VERSION = $(shell grep 'var version' ${VERSION_PATH}/version.go | sed -E 's/.*"(.+)"$$/v\1/')
# 判断是否指定版本
ifdef VERSION
BINARY_VERSION = ${VERSION}
endif
# 没有则用git tag
BINARY_VERSION ?= ${GIT_TAG}
# 如果没有指定版本和git tag 没有信息.则用代码内嵌版本
ifeq ($(BINARY_VERSION),)
BINARY_VERSION = ${BASE_VERSION}
endif
# docker 版本标签
DOCKER_IMAGE_VERSION=${BINARY_VERSION}
# 发布文件版本
RELEASE_FILE_VERSION=${BINARY_VERSION}
# 测试版本或者发布版本
VERSION_METADATA = beta
# Clear the "beta" string in BuildMetadata
ifneq ($(GIT_TAG),)
VERSION_METADATA =
endif
ifneq ($(VERSION_METADATA),)
DOCKER_IMAGE_VERSION:=${DOCKER_IMAGE_VERSION}-${VERSION_METADATA}
RELEASE_FILE_VERSION:=${RELEASE_FILE_VERSION}-${VERSION_METADATA}
endif
ifdef TAGS
BUILD_TAGS = ${TAGS}
endif
BUILD_TAGS ?= codes
LDFLAGS += -X "${PACKAGE_NAME}/$(VERSION_PATH).version=${BINARY_VERSION}"
LDFLAGS += -X "${PACKAGE_NAME}/$(VERSION_PATH).metadata=${VERSION_METADATA}"
LDFLAGS += -X "${PACKAGE_NAME}/$(VERSION_PATH).buildTimestamp=${BUILD_DATE}"
LDFLAGS += -X "${PACKAGE_NAME}/$(VERSION_PATH).gitCommit=${GIT_COMMIT}"
LDFLAGS += -X "${PACKAGE_NAME}/$(VERSION_PATH).gitTagInfo=${GIT_BRANCH}"
LDFLAGS += $(EXT_LDFLAGS)
GOLDFLAGS = -ldflags '$(LDFLAGS)'
ifeq ("$(WITH_RACE)", "1")
GOLDFLAGS += -race
endif
ifdef GORELEASER_FILE
DEFAULT_GORELEASER_FILE = ${GORELEASER_FILE}
endif
GOPROXY ?= https://goproxy.cn
GONOPROXY ?= gitee.com
.PHONY: fmt lint info
fmt: ; $(info $(M) running gofmt) @ ## Run go fmt on all source files
$Q go fmt ./...
lint: fmt ; $(info $(M) running golangci-lint) @ ## Run golangci-lint
$Q golangci-lint run
info:
@echo "Version: \"${VERSION}\""
@echo "Binary Version: \"${BINARY_VERSION}\""
@echo "Release File Version: \"${RELEASE_FILE_VERSION}\""
@echo "Docker Image Version: \"${DOCKER_IMAGE_VERSION}\""
@echo "Release Or Beta: \"${VERSION_METADATA}\""
@echo "Build Timestamp: \"${BUILD_DATE}\""
@echo "Git Hash: \"${GIT_COMMIT}\""
@echo "Git Branch: \"${GIT_TAG}\""
#################################################
# build
#################################################
.PHONY: build brm_build brm_test_build brm_media_server_build
build: clean fmt bin/${BRM_BINARY_NAME} bin/${BRM_MEDIA_SERVER_BINARY_NAME}; @ ## Run build
bin/%: cmd/%/main.go; $(info $(M) running build)
$(GO) build $(GOLDFLAGS) -tags ${BUILD_TAGS} -o $@ $<
brm_build: bin/${BRM_BINARY_NAME}; @ ## Run Brm build
brm_media_server_build: bin/${BRM_MEDIA_SERVER_BINARY_NAME}; @ ## Run Brm-media-server build
brm_test_build: bin/${BRM_TEST_BINARY_NAME}; @ ## Run Brm-test build
#################################################
# Release
#################################################
#--------------------
# goreleaser build
#--------------------
GORELEASER_TARGET := goreleaser_build goreleaser_beta goreleaser_releaser
.PHONY: ${GORELEASER_TARGET}
goreleaser_releaser: GORELEASER_BUILD=release ## Run goreleaser release package
goreleaser_build: GORELEASER_BUILD=build ## Run goreleaser build
goreleaser_build: GORELEASER_SNAPSHOT=--snapshot
goreleaser_beta: GORELEASER_SNAPSHOT=--snapshot ## Run goreleaser Beta package
${GORELEASER_TARGET}: ; $(info $(M) cleaning)
goreleaser ${GORELEASER_BUILD} ${GORELEASER_SNAPSHOT} --debug --clean --parallelism 2 -f ${DEFAULT_GORELEASER_FILE}
#--------------------
# goreleaser build in xgo docker
#--------------------
GORELEASER_DOCKER_TARGETS := goreleaser_build_docker goreleaser_beta_docker goreleaser_releaser_docker
${GORELEASER_DOCKER_TARGETS}: GORELEASER_DOCKER_BUILD_FILE=scripts/goreleaser_in_xgo.yaml
${GORELEASER_DOCKER_TARGETS}: BUILD_CMD=$(MAKECMDGOALS:%_docker=%) # build_cmd 从build target 名称中取docker前缀
${GORELEASER_DOCKER_TARGETS}: goreleaser_docker_build
goreleaser_docker_build:
docker run --rm -v `pwd`/scripts/build.sh:/build.sh \
-v `pwd`:/build \
-v `pwd`/conf/brm.yaml:/etc/brm/brm.yaml \
-e GORELEASER_FILE_NAME=${GORELEASER_DOCKER_BUILD_FILE} \
-e GOPROXY=${GOPROXY} \
-e GOINSECURE=${GOINSECURE} \
-e GOPRIVATE=${GOPRIVATE} \
-e GONOPROXY=${GONOPROXY}\
-e BUILD_CMD=${BUILD_CMD} \
-v `go env GOMODCACHE`:/go/pkg/mod \
--workdir /build registry.cn-hangzhou.aliyuncs.com/travelliu/xgo:go-1.20
#################################################
# Cleaning
#################################################
.PHONY: clean
clean: dist_clean ; $(info $(M) cleaning) @ ## Run cleanup everything
rm -rf test/coverage.* ${COVERAGE_PROFILE}
rm -rf ${TEST_REPORT_OUTPUT} ${TEST_REPORT_JSON} ${TEST_REPORT_XML}
rm -rf ${TEST_REPORT_GOSEC_JSON} ${TEST_REPORT_GOSEC_YML}
dist_clean:
rm -rf build dist html data
find test -name '*.log' -exec rm -rf {} \;
find test -name '*.txt' -exec rm -rf {} \;
find test -name '*.warring' -exec rm -rf {} \;
find test -name '*.err' -exec rm -rf {} \;
##################################################
## Docker
##################################################
#docker: clean ; $(info) @ ## Run Docker Build Release
# docker build -t ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:${DOCKER_IMAGE_VERSION} docker/Dockerfile
#ifeq ($(VERSION_METADATA),)
# docker tag ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:${DOCKER_IMAGE_VERSION} ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:latest
#endif
#
#
#docker_debug: clean ; $(info) @ ## Run Docker Build Release
# docker build -t ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:${DOCKER_IMAGE_VERSION} -f docker/Dockerfile.debug .
#ifeq ($(VERSION_METADATA),)
# docker tag ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:${DOCKER_IMAGE_VERSION} ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:latest
#endif
#
#docker-push: docker ; $(info) @ ## Run Docker Build Release And Push Docker Hub
# docker push ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:${DOCKER_IMAGE_VERSION}
#ifeq ($(VERSION_METADATA),)
# docker push ${DOCKER_USERNAME}/${BRM_BINARY_NAME}:latest
#endif
# ################################################
# Tests
# ################################################
TEST_DIR = $(CURDIR)/test
TEST_REPORT_OUTPUT = ${TEST_DIR}/test_output.out
TEST_REPORT_JSON = ${TEST_DIR}/test_report.json
TEST_REPORT_XML = ${TEST_DIR}/test_report.xml
TEST_REPORT_GOSEC_JSON = ${TEST_DIR}/gosec_report.json
TEST_REPORT_GOSEC_YML = ${TEST_DIR}/gosec_report.yaml
COVERAGE_MODE = atomic
COVERAGE_PROFILE = test/profile.out
COVERAGE_XML = $(COVERAGE_DIR)/coverage.xml
COVERAGE_HTML = $(COVERAGE_DIR)/index.html
TEST_TARGETS := test-default test-bench test-short test-verbose test-race
.PHONY: $(TEST_TARGETS) test-xml check test tests test-coverage
test-bench: ARGS=-run=__absolutelynothing__ -bench=. ## Run benchmarks
test-short: ARGS=-short ## Run only short tests
test-verbose: ARGS=-v ## Run tests in verbose mode with coverage reporting
test-race: ARGS=-race ## Run tests with race detector
$(TEST_TARGETS): NAME=$(MAKECMDGOALS:test-%=%)
$(TEST_TARGETS): test
check test tests: fmt ; $(info $(M) running $(NAME:%=% )tests) @ ## Run tests
$Q $(GO) test $(ARGS) $(TESTPKGS)
test-xml: fmt ; $(info $(M) running $(NAME:%=% )tests) @ ## Run tests with xUnit output
$Q mkdir -p test
$Q 2>&1 $(GO) test -v $(TESTPKGS) | tee ${TEST_REPORT_OUTPUT}
$(GO2XUNIT) -fail -input ${TEST_REPORT_OUTPUT} -output ${TEST_REPORT_XML}
test-json: fmt ; $(info $(M) running $(NAME:%=% )tests) @ ## Run tests with json
$Q mkdir -p test
$Q 2>&1 $(GO) test -json -timeout 120s -v $(TESTPKGS) > ${TEST_REPORT_JSON}
test-coverage: COVERAGE_DIR := $(CURDIR)/test/coverage.$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
test-coverage: fmt ; $(info $(M) running coverage tests) @ ## Run coverage tests
$Q mkdir -p $(COVERAGE_DIR)/coverage
$Q for pkg in $(TESTPKGS); do \
$(GO) test \
-coverpkg=$$($(GO) list -f '{{ join .Deps "\n" }}' $$pkg | \
grep '^$(PACKAGE)/' | \
tr '\n' ',')$$pkg \
-covermode=$(COVERAGE_MODE) \
-coverprofile="$(COVERAGE_DIR)/coverage/`echo $$pkg | tr "/" "-"`.cover" $$pkg ;\
done
$Q $(GOCOVMERGE) $(COVERAGE_DIR)/coverage/*.cover > $(COVERAGE_PROFILE)
$Q $(GO) tool cover -html=$(COVERAGE_PROFILE) -o $(COVERAGE_HTML)
$Q $(GOCOV) convert $(COVERAGE_PROFILE) | $(GOCOVXML) > $(COVERAGE_XML)
sonar: test-json test-coverage; $(info $(M) running SonarQube) @ ## Run SonarQube:
sonar-scanner -Dsonar.projectVersion=`date +%FT%T%z`
# ################################################
# Change Log
# ################################################
.PHONY: changelog
changelog: ; $(info $(M) updating changelog...) @ ## Run updating changelog
$(CHGLOG) --output CHANGELOG.md v0.0.4..
#################################################
# help
#################################################
.PHONY: help
help: ; $(info) @ ## Print help info
@grep -E '^[ a-zA-Z1-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sam-pippi/brm.git
git@gitee.com:sam-pippi/brm.git
sam-pippi
brm
brm
master

搜索帮助