github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/scripts/check-diff-line-width.sh (about) 1 #!/bin/bash 2 # Copyright 2022 PingCAP, Inc. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # Run this scripts via `make limit-line-width`. 16 17 set -e 18 19 # The hash of the latest commit with a commit message matching 20 # the pattern `\(#[0-9]+\)$`. It's usually a master branch commit. 21 BASE_HASH=$(git --no-pager log -E --grep='\(#[0-9]+\)$' -n 1 --format=format:%H) 22 # Please contact TiFlow maintainers before changing following settings. 23 WARN_THRESHOLD=100 24 ERROR_THRESHOLD=140 25 26 git --no-pager diff $BASE_HASH -U0 -- cdc pkg cmd \ 27 -- ':(exclude)*_gen.go' \ 28 -- ':(exclude)*_gen_test.go' \ 29 -- ':(exclude)*_mock.go' \ 30 -- ':(exclude)*_test_data.go' \ 31 -- ':(exclude)*_test.go' \ 32 -- ':(exclude)*.pb.go' | 33 grep -E '^\+' | grep -vE '^\+\+\+' | grep -vE 'json:' | grep -vE 'toml:' | 34 sed 's/\t/ /g' | 35 awk " 36 { 37 # Minus 1 for '+' 38 width = length(\$0) - 1; 39 if (width > $ERROR_THRESHOLD) { 40 print \"\033[0;31m[ERROR]\033[0m width too long, \" length \": \" \$0 ; 41 fail=1 ; 42 } 43 } 44 END { 45 if (fail != 0) { 46 printf \"\033[0;33mNote\033[0m please keep line width with in $WARN_THRESHOLD, \" ; 47 print \"and must not be larger than $ERROR_THRESHOLD.\" ; 48 exit 1; 49 } 50 }"