提交 b1b87474 编写于 作者: Q quicksilver 提交者: yefu.chen

Add logic of incremental check for go code

Signed-off-by: Nquicksilver <zhifeng.zhang@zilliz.com>
上级 24334624
......@@ -39,10 +39,15 @@ check-proto-product: generated-proto-go
@(env bash $(PWD)/scripts/check_proto_product.sh)
fmt:
ifdef GO_DIFF_FILES
@echo "Running $@ check"
@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh $(GO_DIFF_FILES)
else
@echo "Running $@ check"
@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh cmd/
@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh internal/
@GO111MODULE=on env bash $(PWD)/scripts/gofmt.sh tests/go/
endif
#TODO: Check code specifications by golangci-lint
lint:
......@@ -53,10 +58,15 @@ lint:
@GO111MODULE=on ${GOPATH}/bin/golangci-lint run --timeout=30m --config ./.golangci.yml ./tests/go/...
ruleguard:
ifdef GO_DIFF_FILES
@echo "Running $@ check"
@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go $(GO_DIFF_FILES)
else
@echo "Running $@ check"
@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./internal/...
@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./cmd/...
@${GOPATH}/bin/ruleguard -rules ruleguard.rules.go ./tests/go/...
endif
verifiers: getdeps cppcheck fmt lint ruleguard
......
#! /bin/bash
export GO_DIFF_FILES=$(git diff --name-only --diff-filter=d HEAD "*.go")
make fmt
......@@ -130,7 +130,7 @@ func ValidateDimension(dim int64, isBinary bool) error {
}
func ValidateVectorFieldMetricType(field *schemapb.FieldSchema) error {
if field.DataType != schemapb.DataType_VECTOR_FLOAT {
if (field.DataType != schemapb.DataType_VECTOR_FLOAT) && (field.DataType != schemapb.DataType_VECTOR_BINARY) {
return nil
}
for _, params := range field.IndexParams {
......
......@@ -107,7 +107,7 @@ func TestValidateVectorFieldMetricType(t *testing.T) {
field1.DataType = schemapb.DataType_VECTOR_FLOAT
assert.NotNil(t, ValidateVectorFieldMetricType(field1))
field1.IndexParams = []*commonpb.KeyValuePair{
&commonpb.KeyValuePair{
{
Key: "abcdefg",
Value: "",
},
......
#!/usr/bin/env bash
SCRIPTS_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
## green to echo
function green(){
echo -e "\033[32m $1 \033[0m"
}
GO_SRC_DIR="${SCRIPTS_DIR}/$1"
if test -z "$(gofmt -d $GO_SRC_DIR)"; then
exit 0
## Error
function bred(){
echo -e "\033[31m\033[01m $1 \033[0m"
}
files=()
files_need_gofmt=()
if [ -f "$1" ];then
files+=("$1")
fi
if [ -d "$1" ];then
for file in `find $1 -type f | grep "\.go$"`; do
files+=("$file")
done
fi
# Check for files that fail gofmt.
if [[ "${#files[@]}" -ne 0 ]]; then
for file in "${files[@]}"; do
diff="$(gofmt -s -d ${file} 2>&1)"
if [[ -n "$diff" ]]; then
files_need_gofmt+=("${file}")
fi
done
fi
if [[ "${#files_need_gofmt[@]}" -ne 0 ]]; then
bred "ERROR!"
for file in "${files_need_gofmt[@]}"; do
gofmt -s -d ${file} 2>&1
done
echo ""
bred "Some files have not been gofmt'd. To fix these errors, "
bred "copy and paste the following:"
for file in "${files_need_gofmt[@]}"; do
bred " gofmt -s -w ${file}"
done
exit 1
else
gofmt -d $GO_SRC_DIR
echo "Please format your code by gofmt!"
exit 1
green "OK"
exit 0
fi
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册