github.com/oam-dev/kubevela@v1.9.11/hack/licence/header-check.sh (about) 1 #!/bin/bash 2 # Easy & Dumb header check for CI jobs, currently checks ".go" files only. 3 # 4 # This will be called by the CI system (with no args) to perform checking and 5 # fail the job if headers are not correctly set. It can also be called with the 6 # 'fix' argument to automatically add headers to the missing files. 7 # 8 # Check if headers are fine: 9 # $ ./hack/header-check.sh 10 # Check and fix headers: 11 # $ ./hack/header-check.sh fix 12 13 set -e -o pipefail 14 15 # Initialize vars 16 ERR=false 17 FAIL=false 18 19 for file in $(git ls-files | grep "\.go$" | grep -v vendor/); do 20 echo -n "Header check: $file... " 21 if [[ -z $(cat ${file} | grep "Copyright [0-9]\{4\}\(-[0-9]\{4\}\)\?.\? The KubeVela Authors") && -z $(cat ${file} | grep "Copyright [0-9]\{4\} The Crossplane Authors") ]]; then 22 ERR=true 23 fi 24 if [ $ERR == true ]; then 25 if [[ $# -gt 0 && $1 =~ [[:upper:]fix] ]]; then 26 cat ../boilerplate.go.txt "${file}" > "${file}".new 27 mv "${file}".new "${file}" 28 echo "$(tput -T xterm setaf 3)FIXING$(tput -T xterm sgr0)" 29 ERR=false 30 else 31 echo "$(tput -T xterm setaf 1)FAIL$(tput -T xterm sgr0)" 32 ERR=false 33 FAIL=true 34 fi 35 else 36 echo "$(tput -T xterm setaf 2)OK$(tput -T xterm sgr0)" 37 fi 38 done 39 40 # If we failed one check, return 1 41 [ $FAIL == true ] && exit 1 || exit 0