From d3b39189a1cde1a0bbf6c522e9103ccb25165674 Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Mon, 8 Feb 2021 12:00:36 +0100 Subject: [PATCH] Check if the last line is terminated by a <newline> character According to the Posix standard a line of a text is defined as follows: 3.206 Line A sequence of zero or more non- <newline> characters plus a terminating <newline> character. The test checks if this is valid for all newly added or changed text files. I stumbeled over the issue when adding a new header file the list of header files used to generate a ROOT dictionary. The previous last file of the list did not have a proper file ending and attaching the new header file results in a ROOT dictionary source code with the following line '#endif#ifdef' which could be properly parsed and compiled by the compiler but results in an error at run time when loading the library. To avoid such problems in future the test was added. --- .gitlab-ci.yml | 18 +++++++++++++ scripts/check-file-ending.sh | 49 ++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100755 scripts/check-file-ending.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 677fc1756a..f8631d704c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -111,6 +111,24 @@ FileFormatCheck: - git fetch upstream - scripts/check-file-format.sh upstream +FileEndCheck: + 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-file-ending.sh upstream + CbmRoot_Continuous: stage: build tags: diff --git a/scripts/check-file-ending.sh b/scripts/check-file-ending.sh new file mode 100755 index 0000000000..775f2be86c --- /dev/null +++ b/scripts/check-file-ending.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +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 "Upstream name is :" $UPSTREAM + + +# If one wants to find all files in the CbmRoot and not only the changed ones +# uncomment the follwing line and comment the next two +#CHANGED_FILES=$(find . -type f -not \( -path "./.git/*" -o -path "./geometry/*" -o -path "./input/*" -o -path "./external/*" -o -path "./parameters/*" -prune \)) + +BASE_COMMIT=$UPSTREAM/master +CHANGED_FILES=$(git diff --name-only $BASE_COMMIT) + +echo "" +for file in $CHANGED_FILES; do + + # First check for text files and only do the further test on line endings + # for text files + result=$(file $file | grep -v text) + if [[ -z $result ]]; then + if [[ $(tail -c 1 $file) ]]; then + echo "File $file does not finish with end of line" + okay=false + fi + fi +done + +if [[ "$okay" = "false" ]]; then + echo "" + echo "Not all files have the correct file ending" + echo "Test failed" + echo "" + exit 1 +else + exit 0 +fi + -- GitLab