github.com/polarismesh/polaris@v1.17.8/vert.sh (about) 1 #!/bin/bash 2 # Tencent is pleased to support the open source community by making Polaris available. 3 # 4 # Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 # 6 # Licensed under the BSD 3-Clause License (the "License"); 7 # you may not use this file except in compliance with the License. 8 # You may obtain a copy of the License at 9 # 10 # https://opensource.org/licenses/BSD-3-Clause 11 # 12 # Unless required by applicable law or agreed to in writing, software distributed 13 # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 # CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 # specific language governing permissions and limitations under the License. 16 17 18 19 set -ex # Exit on error; debugging enabled. 20 set -o pipefail # Fail a pipe if any sub-command fails. 21 22 # not makes sure the command passed to it does not exit with a return code of 0. 23 not() { 24 # This is required instead of the earlier (! $COMMAND) because subshells and 25 # pipefail don't work the same on Darwin as in Linux. 26 ! "$@" 27 } 28 29 die() { 30 echo "$@" >&2 31 exit 1 32 } 33 34 fail_on_output() { 35 tee /dev/stderr | not read 36 } 37 38 # Check to make sure it's safe to modify the user's git repo. 39 git status --porcelain | fail_on_output 40 41 # Undo any edits made by this script. 42 cleanup() { 43 git reset --hard HEAD 44 } 45 trap cleanup EXIT 46 47 PATH="${HOME}/go/bin:${GOROOT}/bin:${PATH}" 48 go version 49 50 if [[ "$1" = "-install" ]]; then 51 # Install the pinned versions as defined in module tools. 52 pushd ./test/tools 53 go install \ 54 golang.org/x/lint/golint \ 55 golang.org/x/tools/cmd/goimports \ 56 honnef.co/go/tools/cmd/staticcheck \ 57 github.com/client9/misspell/cmd/misspell 58 popd 59 exit 0 60 elif [[ "$#" -ne 0 ]]; then 61 die "Unknown argument(s): $*" 62 fi 63 64 # - Ensure all source files contain a copyright message. 65 not git grep -L "\(Copyright (C) [0-9]\{4,\} THL A29 Limited, a Tencent company. All rights reserved.\)\|DO NOT EDIT" -- '*.go' 66 67 ## - Make sure all tests use leakcheck via Teardown. 68 #not grep -r 'func Test[^(]' test/*.go 69 70 # - Do not import x/net/context. 71 #git grep -l 'x/net/context' -- "*.go" 72 73 misspell -error . 74 75 # - gofmt, goimports, golint (with exceptions for generated code), go vet, 76 # go mod tidy. 77 # Perform these checks on each module inside polaris-go. 78 # for MOD_FILE in $(find . -name 'go.mod'); do 79 # MOD_DIR=$(dirname ${MOD_FILE}) 80 # pushd ${MOD_DIR} 81 # go vet -all ./... | fail_on_output 82 # gofmt -s -d -l . 2>&1 | fail_on_output 83 # goimports -l . 2>&1 | not grep -vE "\.pb\.go" | not grep -vE "mock\.go" 84 # golint ./... 2>&1 | not grep -vE "\.pb\.go"| not grep -vE "test" 85 86 # go mod tidy 87 # git status --porcelain 2>&1 | fail_on_output || 88 # ( 89 # git status 90 # git --no-pager diff 91 # exit 1 92 # ) 93 # popd 94 # done 95 96 # - Collection of static analysis checks 97 # 98 # TODO(dfawley): don't use deprecated functions in examples or first-party 99 # plugins. 100 #SC_OUT="$(mktemp)" 101 #staticcheck -go 1.9 -checks 'inherit,-ST1015' ./... > "${SC_OUT}" || true 102 ## Error if anything other than deprecation warnings are printed. 103 #not grep -v "is deprecated:.*SA1019" "${SC_OUT}" 104 105 ## - special golint on package comments. 106 #lint_package_comment_per_package() { 107 # # Number of files in this go package. 108 # fileCount=$(go list -f '{{len .GoFiles}}' $1) 109 # if [ ${fileCount} -eq 0 ]; then 110 # return 0 111 # fi 112 # # Number of package errors generated by golint. 113 # lintPackageCommentErrorsCount=$(golint --min_confidence 0 $1 | grep -c "should have a package comment") 114 # # golint complains about every file that's missing the package comment. If the 115 # # number of files for this package is greater than the number of errors, there's 116 # # at least one file with package comment, good. Otherwise, fail. 117 # if [ ${fileCount} -le ${lintPackageCommentErrorsCount} ]; then 118 # echo "Package $1 (with ${fileCount} files) is missing package comment" 119 # return 1 120 # fi 121 #} 122 #lint_package_comment() { 123 # set +ex 124 # 125 # count=0 126 # for i in $(go list ./...); do 127 # lint_package_comment_per_package "$i" 128 # ((count += $?)) 129 # done 130 # 131 # set -ex 132 # return $count 133 #} 134 #lint_package_comment 135 136 echo SUCCESS