提交 32d7cc13 编写于 作者: martianzhang's avatar martianzhang

update version.go

上级 fedefa55
bin/
release/
test/tmp/
common/version.go
doc/blueprint/
*.iml
*.swp
......
......@@ -11,7 +11,13 @@ ifeq "$(GOPATH)" ""
endif
PATH := ${GOPATH}/bin:$(PATH)
GCFLAGS=-gcflags "all=-trimpath=${GOPATH}"
LDFLAGS=-ldflags="-s -w"
VERSION_TAG := $(shell git describe --tags --always)
VERSION_VERSION := $(shell git log --date=iso --pretty=format:"%cd" -1) $(VERSION_TAG)
VERSION_COMPILE := $(shell date +"%F %T %z") by $(shell go version)
VERSION_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
VERSION_GIT_DIRTY := $(shell git diff --no-ext-diff 2>/dev/null | wc -l)
VERSION_DEV_PATH:= $(shell pwd)
LDFLAGS=-ldflags="-s -w -X 'github.com/XiaoMi/soar/common.Version=$(VERSION_VERSION)' -X 'github.com/XiaoMi/soar/common.Compile=$(VERSION_COMPILE)' -X 'github.com/XiaoMi/soar/common.Branch=$(VERSION_BRANCH)' -X github.com/XiaoMi/soar/common.GitDirty=$(VERSION_GIT_DIRTY) -X github.com/XiaoMi/soar/common.DevPath=$(VERSION_DEV_PATH)"
# These are the values we want to pass for VERSION and BUILD
BUILD_TIME=`date +%Y%m%d%H%M`
......@@ -69,14 +75,14 @@ fmt: go_version_check
.PHONY: test
test:
@echo "$(CGREEN)Run all test cases ...$(CEND)"
go test -timeout 10m -race ./...
@go test $(LDFLAGS) -timeout 10m -race ./...
@echo "test Success!"
# Rule golang test cases with `-update` flag
.PHONY: test-update
test-update:
@echo "$(CGREEN)Run all test cases with -update flag ...$(CEND)"
go test ./... -update
@go test $(LDFLAGS) ./... -update
@echo "test-update Success!"
# Using bats test framework run all cli test cases
......@@ -92,9 +98,9 @@ test-cli: build
.PHONY: cover
cover: test
@echo "$(CGREEN)Run test cover check ...$(CEND)"
go test -coverpkg=./... -coverprofile=coverage.data ./... | column -t
go tool cover -html=coverage.data -o coverage.html
go tool cover -func=coverage.data -o coverage.txt
@go test $(LDFLAGS) -coverpkg=./... -coverprofile=coverage.data ./... | column -t
@go tool cover -html=coverage.data -o coverage.html
@go tool cover -func=coverage.data -o coverage.txt
@tail -n 1 coverage.txt | awk '{sub(/%/, "", $$NF); \
if($$NF < 80) \
{print "$(CRED)"$$0"%$(CEND)"} \
......@@ -107,10 +113,9 @@ cover: test
build: fmt
@echo "$(CGREEN)Building ...$(CEND)"
@mkdir -p bin
@bash ./genver.sh
@ret=0 && for d in $$(go list -f '{{if (eq .Name "main")}}{{.ImportPath}}{{end}}' ./...); do \
b=$$(basename $${d}) ; \
go build ${GCFLAGS} -o bin/$${b} $$d || ret=$$? ; \
go build ${LDFLAGS} ${GCFLAGS} -o bin/$${b} $$d || ret=$$? ; \
done ; exit $$ret
@echo "build Success!"
......
......@@ -549,7 +549,7 @@ func init() {
Item: "COL.016",
Severity: "L1",
Summary: "整型定义建议采用 INT(10) 或 BIGINT(20)",
Content: `INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。`,
Content: `INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。高版本 MySQL 已经不推荐设置整数显示宽度。`,
Case: "CREATE TABLE tab (a INT(1));",
Func: (*Query4Audit).RuleIntPrecision,
},
......
package common
// -version输出信息
var (
Version = "No Version Provided"
Compile = ""
Branch = ""
GitDirty = ""
DevPath = ""
)
......@@ -506,7 +506,7 @@ CREATE TABLE `tbl` (`c` blob DEFAULT NULL);
* **Item**:COL.016
* **Severity**:L1
* **Content**:INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。
* **Content**:INT(M) 在 integer 数据类型中,M 表示最大显示宽度。 在 INT(M) 中,M 的值跟 INT(M) 所占多少存储空间并无任何关系。 INT(3)、INT(4)、INT(8) 在磁盘上都是占用 4 bytes 的存储空间。高版本 MySQL 已经不推荐设置整数显示宽度。
* **Case**:
```sql
......
#!/bin/bash
## Generate Repository Version
tag="$(git describe --tags --always)"
version="$(git log --date=iso --pretty=format:"%cd" -1) ${tag}"
if [ "X${version}" == "X" ]; then
version="not a git repo"
tag="not a git repo"
fi
git_dirty=$(git diff --no-ext-diff 2>/dev/null | wc -l)
compile="$(date +"%F %T %z") by $(go version)"
branch=$(git rev-parse --abbrev-ref HEAD)
dev_path=$(
cd "$(dirname "$0")" || exit
pwd
)
cat <<EOF | gofmt >common/version.go
package common
// -version输出信息
const (
Version = "${version}"
Compile = "${compile}"
Branch = "${branch}"
GitDirty= ${git_dirty}
DevPath = "${dev_path}"
)
EOF
XIAOMI=$(git ls-remote --get-url | grep XiaoMi)
if [ "x${XIAOMI}" != "x" ]; then
echo "${tag}" | awk -F '-' '{print $1}' > VERSION
fi
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册