Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Fix check-line-width CI script #6326

Merged
merged 4 commits into from
Jun 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .maintain/gitlab/check_line_width.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ BASE_BRANCH_NAME="master"
LINE_WIDTH="120"
GOOD_LINE_WIDTH="100"
BASE_BRANCH="${BASE_ORIGIN}/${BASE_BRANCH_NAME}"
git fetch ${BASE_ORIGIN} ${BASE_BRANCH_NAME} --depth 100
BASE_HASH=$(git merge-base ${BASE_BRANCH} HEAD)

git fetch ${BASE_ORIGIN} ${BASE_BRANCH_NAME} --depth 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is definitely required as the master branch to compare with is not always available.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if $CI_COMMIT_BEFORE_SHA would be working as that commit would be part of the history of the current branch, too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not if the pull request contains more than 100 commits:
https://github.com/paritytech/substrate/blob/master/.gitlab-ci.yml#L35

(that limit had been raised because of such scenarios, but it's safer to just make sure what is compared with is present)

git diff --name-only ${BASE_BRANCH} -- \*.rs | ( while read file
git diff --name-only ${BASE_HASH} -- \*.rs | ( while read file
do
if [ ! -f ${file} ];
then
echo "Skipping removed file."
elif git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}"
elif git diff ${BASE_HASH} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}"
then
if [ -z "${FAIL}" ]
then
Expand All @@ -29,11 +30,11 @@ do
FAIL="true"
fi
echo "| file: ${file}"
git diff ${BASE_BRANCH} -- ${file} \
git diff ${BASE_HASH} -- ${file} \
| grep -n "^+.\{$(( $LINE_WIDTH + 1))\}"
echo "|"
else
if git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
if git diff ${BASE_HASH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
then
if [ -z "${FAIL}" ]
then
Expand All @@ -44,7 +45,7 @@ do
echo "|"
fi
echo "| file: ${file}"
git diff ${BASE_BRANCH} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
git diff ${BASE_HASH} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
echo "|"
fi
fi
Expand Down