jenkins: improve checklicense to be more explicit and friendly
authorJean Privat <jean@pryen.org>
Wed, 19 Aug 2015 06:55:14 +0000 (02:55 -0400)
committerJean Privat <jean@pryen.org>
Wed, 19 Aug 2015 18:34:13 +0000 (14:34 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

misc/jenkins/checklicense.sh

index 3fcd8af..16f5260 100755 (executable)
 # limitations under the License.
 
 # Check missing "This file is part of NIT…" comment in committed scripts.
+#
+# Usage: checklicense.sh from to
 
-if test "$#" -lt 2; then
-       echo "Usage: checklicense from to"
-       echo ""
-       exit
-fi
+set -e
 
-from=$1
-to=$2
+from=${1:-origin/master}
+to=${2:-HEAD}
 
 err=0
 
+cd `git rev-parse --show-toplevel`
+
+echo "checklicense $from (`git rev-parse "$from"`) .. $to (`git rev-parse "$to"`)"
 git diff --name-status $from..$to -- "*.nit" "*.sh" | sed -n 's/^A\s*//p' > checklicense_new_files.out
-test -s checklicense_new_files.out || exit 0
-grep -L '\(^\|\b\)# [Tt]his file is part of NIT ' `cat checklicense_new_files.out` 2>/dev/null | tee checklicense_missing.out
-test \! -s checklicense_missing.out
+if test \! -s checklicense_new_files.out; then
+       echo "No new files"
+       exit 0
+fi
+grep -L '\(^\|\b\)# [Tt]his file is part of NIT ' `cat checklicense_new_files.out` 2>/dev/null > checklicense_missing.out || true
+if test -s checklicense_missing.out; then
+       echo "These files are missing their licence:"
+       echo ""
+       cat checklicense_missing.out
+       echo ""
+       echo "Please double check that the licence text (i.e. \`This file is part of NIT...\`) is included at the begin of these files."
+       exit 1
+else
+       echo "All `cat checklicense_new_files.out | wc -l` checked new files have a correct license."
+       exit 0
+fi