github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/hack/license/header-check.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (C) 2022-2023 ApeCloud Co., Ltd 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 # Check if headers are fine: 18 # $ ./hack/header-check.sh 19 # Check and fix headers: 20 # $ ./hack/header-check.sh fix 21 22 set -e -o pipefail 23 24 # Initialize vars 25 ERR=false 26 FAIL=false 27 EXCLUDES_DIRS="vendor/\|apis/\|tools/\|externalapis/\|pkg/lorry/component/\|pkg/cli/cmd/plugin/download" 28 APACHE2_DIRS="apis/\|externalapis/" 29 30 for file in $(git ls-files | grep '\.cue\|\.go$' | grep -v ${EXCLUDES_DIRS}); do 31 echo -n "Header check: $file... " 32 if [[ -z $(cat ${file} | grep "Copyright (C) 2022-2023 ApeCloud Co., Ltd\|Code generated by") ]]; then 33 ERR=true 34 fi 35 if [ $ERR == true ]; then 36 if [[ $# -gt 0 && $1 =~ [[:upper:]fix] ]]; then 37 ext="${file##*.}" 38 cat ./hack/boilerplate."${ext}".txt "${file}" > "${file}".new 39 mv "${file}".new "${file}" 40 echo "$(tput -T xterm setaf 3)FIXING$(tput -T xterm sgr0)" 41 ERR=false 42 else 43 echo "$(tput -T xterm setaf 1)FAIL$(tput -T xterm sgr0)" 44 ERR=false 45 FAIL=true 46 fi 47 else 48 echo "$(tput -T xterm setaf 2)OK$(tput -T xterm sgr0)" 49 fi 50 done 51 52 53 for file in $(git ls-files | grep '\.go$' | grep ${APACHE2_DIRS}); do 54 echo -n "Header check: $file... " 55 if [[ -z $(cat ${file} | grep "Copyright (C) 2022-2023 ApeCloud Co., Ltd\|Code generated by") ]]; then 56 ERR=true 57 fi 58 if [ $ERR == true ]; then 59 if [[ $# -gt 0 && $1 =~ [[:upper:]fix] ]]; then 60 ext="${file##*.}" 61 cat ./hack/boilerplate_apache2."${ext}".txt "${file}" > "${file}".new 62 mv "${file}".new "${file}" 63 echo "$(tput -T xterm setaf 3)FIXING$(tput -T xterm sgr0)" 64 ERR=false 65 else 66 echo "$(tput -T xterm setaf 1)FAIL$(tput -T xterm sgr0)" 67 ERR=false 68 FAIL=true 69 fi 70 else 71 echo "$(tput -T xterm setaf 2)OK$(tput -T xterm sgr0)" 72 fi 73 done 74 75 # If we failed one check, return 1 76 [ $FAIL == true ] && exit 1 || exit 0