From 8110205820f5cb4d26169c3fb17d6bbdb32ac37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Thei=C3=9Fen?= Date: Wed, 13 May 2020 10:47:27 +0200 Subject: [PATCH] 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 --- .../.maintain/gitlab/check_line_width.sh | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/substrate/.maintain/gitlab/check_line_width.sh b/substrate/.maintain/gitlab/check_line_width.sh index f382d630b1..85092260b6 100755 --- a/substrate/.maintain/gitlab/check_line_width.sh +++ b/substrate/.maintain/gitlab/check_line_width.sh @@ -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