diff --git a/Makefile b/Makefile index 6107f847ff3a5153e48b1c937fb201e824d0c295..83d9266fe4eb50f17b77a60cf43e75a38bb24df6 100644 --- a/Makefile +++ b/Makefile @@ -29,3 +29,8 @@ lint: golangci GOFLAGS="-buildvcs=false" ;\ go work edit -json | jq -r '.Use[].DiskPath' | xargs -I{} $(GOLANGCILINT) run {}/... ;\ } +# check-license-header: Check license header +check-license-header: + ./scripts/licence/header-check.sh +fix-license-header: + ./scripts/licence/header-check.sh fix diff --git a/scripts/licence/boilerplate.go.txt b/scripts/licence/boilerplate.go.txt new file mode 100644 index 0000000000000000000000000000000000000000..866ed880f639346d7de05a7e3678ba7fddedb64f --- /dev/null +++ b/scripts/licence/boilerplate.go.txt @@ -0,0 +1,19 @@ +/****************************************************************************** + * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved. + * PilotGo is licensed under the Mulan PSL v2. + * You can use this software accodring to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: yangzhao1 + * Date: 2022-04-06 13:27:45 + * LastEditTime: 2023-09-04 16:16:36 + * Description: provide agent log manager of pilotgo + ******************************************************************************/ + + + + + \ No newline at end of file diff --git a/scripts/licence/header-check.sh b/scripts/licence/header-check.sh new file mode 100755 index 0000000000000000000000000000000000000000..4d00930a53514df68a7289f484dfbf8a62c3c1c4 --- /dev/null +++ b/scripts/licence/header-check.sh @@ -0,0 +1,28 @@ +#!/bin/bash +set -e -o pipefail +ERR=false +FAIL=false + +for file in $(git ls-files | grep "\.go$" | grep -v vendor/); do + echo -n "Header check: $file... " + if [[ -z $(cat ${file} | grep "Copyright (c) KylinSoft Co., Ltd.") && -z $(cat ${file} | grep "PilotGo is licensed under the Mulan PSL v2.") ]]; then + ERR=true + fi + if [ $ERR == true ]; then + if [[ $# -gt 0 && $1 =~ [[:upper:]fix] ]]; then + cat ./scripts/licence/boilerplate.go.txt "${file}" > "${file}".new + mv "${file}".new "${file}" + echo "$(tput -T xterm setaf 3)FIXING$(tput -T xterm sgr0)" + ERR=false + else + echo "$(tput -T xterm setaf 1)FAIL$(tput -T xterm sgr0)" + ERR=false + FAIL=true + fi + else + echo "$(tput -T xterm setaf 2)OK$(tput -T xterm sgr0)" + fi +done + +# If we failed one check, return 1 +[ $FAIL == true ] && exit 1 || exit 0 \ No newline at end of file