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 @@
# SPDX-License-Identifier: GPL-3.0-only
# First commited by Eoin Clerkin
RETURN_CODE="0"
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
echo "[ERROR] Missing or Malformated licence header for file $FILE"
exit 11
echo "[ERROR] $1, line 2 missing spdx licence header declaration."
((RETURN_CODE++))
FILE_CODE="1"
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
echo "[ERROR] $FILE; line 2 has syntax errors in its licence header."
exit 12
echo "[ERROR] $1; line 1 has syntax errors in its licence header."
((RETURN_CODE++))
FILE_CODE="1"
fi
sed -n '3p' $1 | grep -L ' Authors: .[^\*\/]*\*/'
sed -n '3p' $1 | grep -q ' Authors: .[^\*\/]*\*/'
if [ $? -ne 0 ]; then
echo "[ERROR] $FILE; line 3 has syntax errors in its licence header."
exit 13
echo "[ERROR] $1; line 3 has syntax errors in its licence header."
((RETURN_CODE++))
FILE_CODE="1"
fi
sed -n '3p' $FILE | grep -L '\[committer\]'
sed -n '3p' $1 | grep -q '\[committer\]'
if [ $? -ne 0 ]; then
echo "[ERROR] $FILE; line 3 has missing first commiter information."
exit 14
echo "[ERROR] $1; line 3 has missing first commiter information."
((RETURN_CODE++))
FILE_CODE="1"
fi
if [[ ${FILE_CODE} -eq 0 ]]; then
echo "[OK] File: $1 passes licence header check."
fi
echo "[OK] File: $1 passes licence header check.";
}
}
if [ $# -eq 1 ]; then
UPSTREAM=$1
UPSTREAM=$1
else
if [ -z $UPSTREAM ]; then
UPSTREAM=$(git remote -v | grep git.cbm.gsi.de[:/]computing/cbmroot | cut -f1 | uniq)
......@@ -45,15 +56,28 @@ else
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
CHANGED_FILES=$(git diff --name-only $BASE_COMMIT | egrep '\.cxx$|\.h|\.C$')
fi
for FILE in $CHANGED_FILES; do
licenceHeaderCheck $FILE
licenceHeaderCheck $FILE
done
echo "[OK] Licence header passes automatic checks."
exit 0;
if [ $RETURN_CODE -eq "0" ]; then
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