Commit 43f19846 authored by Eoin Clerkin's avatar Eoin Clerkin Committed by Florian Uhlig
Browse files

Automated licence header check

Ensures that modified .cpp, .C and .h files follow basic licence header guidelines.

Check line 1 for a copyright declaration with correct numerial and character placements for a date followed by institute and city.
Check line 2 for SPDX licence identifier.
Check line 3 for author and committer information.
parent 227650d5
......@@ -130,6 +130,26 @@ FileEndCheck:
- git fetch upstream
- scripts/check-file-ending.sh upstream
FileLicenceCheck:
stage: checkFormat
image: alpine
tags:
- docker
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_PROJECT_PATH == "computing/cbmroot" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
script:
# Get the upstream repository manually. I did not find any other way to have it for
# comparison
- apk update && apk add git bash file
- scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
- git fetch upstream
- scripts/check-licence-header.sh upstream
#
# job template
#
......
#!/bin/bash
# Copyright (C) 2021 Facility for Antiproton and Ion Research in Europe, Darmstadt
# SPDX-License-Identifier: GPL-3.0-only
# First commited by Eoin Clerkin
licenceHeaderCheck () {
sed -n '2p' $1 | grep -L ' SPDX-License-Identifier: GPL-3.0-only'
if [ $? -ne 0 ]; then
echo "[ERROR] Missing or Malformated licence header for file $FILE"
exit 11
fi
head -n 1 $1 | grep -L '\/\* 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
fi
sed -n '3p' $1 | grep -L ' Authors: .[^\*\/]*\*/'
if [ $? -ne 0 ]; then
echo "[ERROR] $FILE; line 3 has syntax errors in its licence header."
exit 13
fi
sed -n '3p' $FILE | grep -L '\[committer\]'
if [ $? -ne 0 ]; then
echo "[ERROR] $FILE; line 3 has missing first commiter information."
exit 14
fi
echo "[OK] File: $1 passes licence header check.";
}
if [ $# -eq 1 ]; then
UPSTREAM=$1
else
if [ -z $UPSTREAM ]; then
UPSTREAM=$(git remote -v | grep git.cbm.gsi.de[:/]computing/cbmroot | cut -f1 | uniq)
if [ -z $UPSTREAM ]; then
echo "Error: Name of upstream repository not provided and not found by automatic means"
echo 'Please provide if by checking your remotes with "git remote -v" and exporting UPSTREAM'
echo "or passing as an argument"
exit -1
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
BASE_COMMIT=$UPSTREAM/master
CHANGED_FILES=$(git diff --name-only $BASE_COMMIT | egrep '\.cxx$|\.h|\.C$')
for FILE in $CHANGED_FILES; do
licenceHeaderCheck $FILE
done
echo "[OK] Licence header passes automatic checks."
exit 0;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment