mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Add boilerplate checking to hook
This commit is contained in:
parent
b850d36166
commit
756ba6958d
13
hooks/boilerplate.sh
Executable file
13
hooks/boilerplate.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Print 1 if the file in $1 has the correct boilerplate header, 0 otherwise.
|
||||||
|
FILE=$1
|
||||||
|
LINES=$(cat "$(dirname $0)/boilerplate.txt" | wc -l)
|
||||||
|
DIFFER=$(head -$LINES "${FILE}" | diff -q - "$(dirname $0)/boilerplate.txt")
|
||||||
|
|
||||||
|
if [[ -z "${DIFFER}" ]]; then
|
||||||
|
echo "1"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "0"
|
16
hooks/boilerplate.txt
Normal file
16
hooks/boilerplate.txt
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
@ -1,5 +1,7 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
KUBE_HOOKS_DIR="$(dirname "$(test -L "$0" && echo "$(dirname $0)/$(readlink "$0")" || echo "$0")")"
|
||||||
|
|
||||||
errors=0
|
errors=0
|
||||||
for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v "third_party"); do
|
for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | grep -v "third_party"); do
|
||||||
diff="$(git show ":${file}" | gofmt -s -d)"
|
diff="$(git show ":${file}" | gofmt -s -d)"
|
||||||
@ -7,6 +9,11 @@ for file in $(git diff --cached --name-only --diff-filter ACM | grep "\.go" | gr
|
|||||||
echo "# *** ERROR: *** File ${file} has not been gofmt'd." >> $1
|
echo "# *** ERROR: *** File ${file} has not been gofmt'd." >> $1
|
||||||
errors=1
|
errors=1
|
||||||
fi
|
fi
|
||||||
|
boilerplate="$(${KUBE_HOOKS_DIR}/boilerplate.sh ${file})"
|
||||||
|
if [[ "$boilerplate" -eq "0" ]]; then
|
||||||
|
echo "# *** ERROR: *** File ${file} needs the boilerplate header in hooks/boilerplate.txt." >> $1
|
||||||
|
errors=1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $errors == "1" ]]; then
|
if [[ $errors == "1" ]]; then
|
||||||
|
Loading…
Reference in New Issue
Block a user