Skip to content
Snippets Groups Projects
Commit 3ed463b8 authored by Eoin Clerkin's avatar Eoin Clerkin
Browse files

Fixes Bugs in automated licence header check

Corrects a variable typo which leads to some false positives

Allows passthrough of all files before trigger error code, to allow to see all files which don't obey header format.

Allows checking of individual files.
parent 43f19846
No related branches found
No related tags found
No related merge requests found
...@@ -3,36 +3,47 @@ ...@@ -3,36 +3,47 @@
# SPDX-License-Identifier: GPL-3.0-only # SPDX-License-Identifier: GPL-3.0-only
# First commited by Eoin Clerkin # First commited by Eoin Clerkin
RETURN_CODE="0"
licenceHeaderCheck () { licenceHeaderCheck () {
sed -n '2p' $1 | grep -L ' SPDX-License-Identifier: GPL-3.0-only'
FILE_CODE="0";
sed -n '2p' $1 | grep -q ' SPDX-License-Identifier: GPL-3.0-only'
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "[ERROR] Missing or Malformated licence header for file $FILE" echo "[ERROR] $1, line 2 missing spdx licence header declaration."
exit 11 ((RETURN_CODE++))
FILE_CODE="1"
fi fi
head -n 1 $1 | grep -L '\/\* Copyright (C) [0-9-]* .[a-zA-Z ]*, [a-zA-Z]*' head -n 1 $1 | grep -q '\/\* Copyright (C) [0-9-]* [a-zA-Z -]*, [a-zA-Z]*'
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "[ERROR] $FILE; line 2 has syntax errors in its licence header." echo "[ERROR] $1; line 1 has syntax errors in its licence header."
exit 12 ((RETURN_CODE++))
FILE_CODE="1"
fi fi
sed -n '3p' $1 | grep -L ' Authors: .[^\*\/]*\*/' sed -n '3p' $1 | grep -q ' Authors: .[^\*\/]*\*/'
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "[ERROR] $FILE; line 3 has syntax errors in its licence header." echo "[ERROR] $1; line 3 has syntax errors in its licence header."
exit 13 ((RETURN_CODE++))
FILE_CODE="1"
fi fi
sed -n '3p' $FILE | grep -L '\[committer\]' sed -n '3p' $1 | grep -q '\[committer\]'
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "[ERROR] $FILE; line 3 has missing first commiter information." echo "[ERROR] $1; line 3 has missing first commiter information."
exit 14 ((RETURN_CODE++))
FILE_CODE="1"
fi
if [[ ${FILE_CODE} -eq 0 ]]; then
echo "[OK] File: $1 passes licence header check."
fi fi
echo "[OK] File: $1 passes licence header check."; }
}
if [ $# -eq 1 ]; then if [ $# -eq 1 ]; then
UPSTREAM=$1 UPSTREAM=$1
else else
if [ -z $UPSTREAM ]; then if [ -z $UPSTREAM ]; then
UPSTREAM=$(git remote -v | grep git.cbm.gsi.de[:/]computing/cbmroot | cut -f1 | uniq) UPSTREAM=$(git remote -v | grep git.cbm.gsi.de[:/]computing/cbmroot | cut -f1 | uniq)
...@@ -45,15 +56,28 @@ else ...@@ -45,15 +56,28 @@ else
fi fi
fi fi
echo "See wikipage https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Licence for information regarding the correct syntax used in the licence header."
echo "Upstream name is :" $UPSTREAM
if [ -f $1 ]; then
CHANGED_FILES="$1"
echo "LICENCE HEADER CHECK FOR FILE: $1"
else
echo "Upstream name is :" $UPSTREAM
BASE_COMMIT=$UPSTREAM/master BASE_COMMIT=$UPSTREAM/master
CHANGED_FILES=$(git diff --name-only $BASE_COMMIT | egrep '\.cxx$|\.h|\.C$') CHANGED_FILES=$(git diff --name-only $BASE_COMMIT | egrep '\.cxx$|\.h|\.C$')
fi
for FILE in $CHANGED_FILES; do for FILE in $CHANGED_FILES; do
licenceHeaderCheck $FILE licenceHeaderCheck $FILE
done done
echo "[OK] Licence header passes automatic checks." if [ $RETURN_CODE -eq "0" ]; then
exit 0; echo "[OK] Licence header passes automatic checks."
else
echo "[FAIL] Visit https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Licence for information on correct syntax for licence header."
fi
exit $RETURN_CODE;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment