From 260af3017ba7fe20ac3a837e6620a25d45741d41 Mon Sep 17 00:00:00 2001 From: Daniel Smith Date: Wed, 25 Jun 2014 17:11:48 -0700 Subject: [PATCH] Make boilerplate hook work for .sh files, too. --- cluster/config-default.sh | 2 ++ cluster/config-test.sh | 2 ++ cluster/templates/download-release.sh | 2 ++ cluster/templates/salt-master.sh | 2 ++ cluster/templates/salt-minion.sh | 2 ++ cluster/util.sh | 2 ++ hack/config-go.sh | 2 ++ hack/verify-boilerplate.sh | 28 ++++++++++++++++++- hooks/{boilerplate.txt => boilerplate.go.txt} | 0 hooks/boilerplate.sh | 27 ++++++++++++++++-- hooks/boilerplate.sh.txt | 16 +++++++++++ hooks/prepare-commit-msg | 9 ++++++ 12 files changed, 91 insertions(+), 3 deletions(-) rename hooks/{boilerplate.txt => boilerplate.go.txt} (100%) create mode 100644 hooks/boilerplate.sh.txt diff --git a/cluster/config-default.sh b/cluster/config-default.sh index 428b9126dc..4a25ccc024 100755 --- a/cluster/config-default.sh +++ b/cluster/config-default.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cluster/config-test.sh b/cluster/config-test.sh index aceef0482f..8d3e51aec5 100755 --- a/cluster/config-test.sh +++ b/cluster/config-test.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cluster/templates/download-release.sh b/cluster/templates/download-release.sh index 2a35511000..e1a61f4fe5 100755 --- a/cluster/templates/download-release.sh +++ b/cluster/templates/download-release.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cluster/templates/salt-master.sh b/cluster/templates/salt-master.sh index 83e715af97..310e64d55b 100755 --- a/cluster/templates/salt-master.sh +++ b/cluster/templates/salt-master.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cluster/templates/salt-minion.sh b/cluster/templates/salt-minion.sh index d099345a41..13dd82f056 100755 --- a/cluster/templates/salt-minion.sh +++ b/cluster/templates/salt-minion.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/cluster/util.sh b/cluster/util.sh index 2a8d28414d..1189292257 100755 --- a/cluster/util.sh +++ b/cluster/util.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/hack/config-go.sh b/hack/config-go.sh index de43ef5f68..988952b42a 100755 --- a/hack/config-go.sh +++ b/hack/config-go.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2014 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/hack/verify-boilerplate.sh b/hack/verify-boilerplate.sh index 3eeb0fb506..22155b0256 100755 --- a/hack/verify-boilerplate.sh +++ b/hack/verify-boilerplate.sh @@ -1,12 +1,26 @@ #!/bin/bash +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + REPO_ROOT="$(realpath "$(dirname $0)/..")" result=0 dirs=("pkg" "cmd") -for dir in ${dirs}; do +for dir in ${dirs[@]}; do for file in $(grep -r -l "" "${REPO_ROOT}/${dir}/" | grep "[.]go"); do if [[ "$(${REPO_ROOT}/hooks/boilerplate.sh "${file}")" -eq "0" ]]; then echo "Boilerplate header is wrong for: ${file}" @@ -15,4 +29,16 @@ for dir in ${dirs}; do done done +dirs=("cluster" "hack" "hooks") + +for dir in ${dirs[@]}; do + for file in $(grep -r -l "" "${REPO_ROOT}/${dir}/" | grep "[.]sh"); do + if [[ "$(${REPO_ROOT}/hooks/boilerplate.sh "${file}")" -eq "0" ]]; then + echo "Boilerplate header is wrong for: ${file}" + result=1 + fi + done +done + + exit ${result} diff --git a/hooks/boilerplate.txt b/hooks/boilerplate.go.txt similarity index 100% rename from hooks/boilerplate.txt rename to hooks/boilerplate.go.txt diff --git a/hooks/boilerplate.sh b/hooks/boilerplate.sh index cfe2af7b6b..1e68a9f7f0 100755 --- a/hooks/boilerplate.sh +++ b/hooks/boilerplate.sh @@ -1,9 +1,32 @@ #!/bin/bash +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + # Print 1 if the file in $1 has the correct boilerplate header, 0 otherwise. FILE=$1 -LINES=$(cat "$(dirname $0)/boilerplate.txt" | wc -l | tr -d ' ') -DIFFER=$(head "-${LINES}" "${FILE}" | diff -q - "$(dirname $0)/boilerplate.txt") +EXT=${FILE#*.} + +REF_FILE="$(dirname $0)/boilerplate.${EXT}.txt" + +if [[ ! -e "${REF_FILE}" ]]; then + echo "1" + exit 0 +fi + +LINES=$(cat "${REF_FILE}" | wc -l | tr -d ' ') +DIFFER=$(head "-${LINES}" "${FILE}" | diff -q - "${REF_FILE}") if [[ -z "${DIFFER}" ]]; then echo "1" diff --git a/hooks/boilerplate.sh.txt b/hooks/boilerplate.sh.txt new file mode 100644 index 0000000000..26e095ec18 --- /dev/null +++ b/hooks/boilerplate.sh.txt @@ -0,0 +1,16 @@ +#!/bin/bash + +# Copyright 2014 Google Inc. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/hooks/prepare-commit-msg b/hooks/prepare-commit-msg index 594ddcce0e..01b9a51415 100755 --- a/hooks/prepare-commit-msg +++ b/hooks/prepare-commit-msg @@ -18,6 +18,15 @@ for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | gr fi done +# Check sh files for boilerplate +for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.sh" | grep -v "third_party"); do + # Check for files without the required boilerplate. + boilerplate="$(${KUBE_HOOKS_DIR}/boilerplate.sh ${file})" + if [[ "$boilerplate" -eq "0" ]]; then + files_need_boilerplate="${files_need_boilerplate} ${file}" + fi +done + if [[ -n "${files_need_gofmt}" ]]; then ( echo