Fix gitlab line-width CI check (#5994)

* Run script in strict mode

* Add proper seperator between revision and file

* Fix copy paste error

* Do not repeat limit number in error text

* Fix bad revision error

* Do not mask pipe errors

* Fix typo

* Remove unnecessary ... syntax

* Do not fetch all commits of master

* Fetching one commit is enough
This commit is contained in:
Alexander Theißen
2020-05-13 10:47:27 +02:00
committed by GitHub
parent b718c45dbd
commit 8110205820
+17 -15
View File
@@ -2,47 +2,49 @@
#
# check if line width of rust source files is not beyond x characters
#
set -e
set -o pipefail
BASE_ORIGIN="origin"
BASE_BRANCH_NAME="master"
LINE_WIDTH="120"
GOOD_LINE_WIDTH="100"
BASE_BRANCH="${BASE_ORIGIN}/${BASE_BRANCH_NAME}"
BASE_BRANCH="origin/master"
LINE_WIDTH="121"
GOOD_LINE_WIDTH="101"
git diff --name-only ${BASE_BRANCH}...${CI_COMMIT_SHA} \*.rs | ( while read file
git fetch ${BASE_ORIGIN} ${BASE_BRANCH_NAME} --depth 1
git diff --name-only ${BASE_BRANCH} -- \*.rs | ( while read file
do
if [ ! -f ${file} ];
then
echo "Skipping removed file."
elif git diff ${BASE_BRANCH}...${CI_COMMIT_SHA} ${file} | grep -q "^+.\{${LINE_WIDTH}\}"
elif git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}"
then
if [ -z "${FAIL}" ]
then
echo "| warning!"
echo "| Lines should not be longer than 120 characters."
echo "| error!"
echo "| Lines must not be longer than ${LINE_WIDTH} characters."
echo "| "
echo "| see more https://wiki.parity.io/Substrate-Style-Guide"
echo "|"
FAIL="true"
fi
echo "| file: ${file}"
git diff ${BASE_BRANCH}...${CI_COMMIT_SHA} ${file} \
| grep -n "^+.\{${LINE_WIDTH}\}"
git diff ${BASE_BRANCH} -- ${file} \
| grep -n "^+.\{$(( $LINE_WIDTH + 1))\}"
echo "|"
else
if git diff ${BASE_BRANCH}...${CI_COMMIT_SHA} ${file} | grep -q "^+.\{${GOOD_LINE_WIDTH}\}"
if git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
then
if [ -z "${FAIL}" ]
then
echo "| warning!"
echo "| Lines should be longer than 100 characters only in exceptional circumstances!"
echo "| Lines should be longer than ${GOOD_LINE_WIDTH} characters only in exceptional circumstances!"
echo "| "
echo "| see more https://wiki.parity.io/Substrate-Style-Guide"
echo "|"
fi
echo "| file: ${file}"
git diff ${BASE_BRANCH}...${CI_COMMIT_SHA} ${file} \
| grep -n "^+.\{${LINE_WIDTH}\}"
git diff ${BASE_BRANCH} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
echo "|"
fi
fi