Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
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
19 changes: 10 additions & 9 deletions .maintain/gitlab/check_line_width.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
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}"

git fetch ${BASE_ORIGIN} ${BASE_BRANCH_NAME} --depth 1

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
if [ -z $CI_COMMIT_BEFORE_SHA ]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

since this is not a merge request on gitlab it won't be set.

@athei athei Jun 11, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I thought a merge request on github counts as that because it is all mirrored. So you say this is expected? If you say so we can work with git merge-base to determine the most recent common ancestor. For that we need to fetch the full master, though.

@gabreal gabreal Jun 11, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it is expected, yes. pull requests are only branches on gitlab (not merge requests due to the nature of the mirroring).

i'm also not finding it easy to understand the meaning of:

The previous latest commit present on a branch before a merge request.

which would be the "a branch"?
basically the ... do the right thing and that variable would probably in the best case do the same.

@athei athei Jun 11, 2020

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

i'm also not finding it easy to understand the meaning of:

A PR branched off a branch at some point of time (lets call this branch master). Then both add commits. Then after some time you start at the latest commit of master and PR and go backwards following all their parents until you hit a common hash. This is what $CI_COMMIT_BEFORE_SHA is. Basically the hash on master where you started your PR from.

basically the ... do the right thing and that variable would probably in the best case do the same.

  1. You can just omit the right side of the .... This is equivalent to left...HEAD. This is what I am doing here.

  2. I cannot to "just" do the same thing because I do not know the left side. This is what this PR is all about. $CI_COMMIT_BEFORE_SHA would give me this left side. However, this is not working. I need to resort to other measures to determine it then.

echo "No ancestor commit set in \$CI_COMMIT_BEFORE_SHA"
exit -1;
fi

git diff --name-only ${CI_COMMIT_BEFORE_SHA} -- \*.rs | ( while read file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i assume it shouldn't be compared with the current master ${BASE_BRANCH} but with that point when that pr forked off from master i.e.

git diff --name-only ${BASE_BRANCH}...${CI_COMMIT_SHA} -- \*.rs | ( while read file

(three dots)
compare with
https://github.com/paritytech/substrate/blob/master/.maintain/gitlab/check_runtime.sh#L60

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. And I expect $CI_COMMIT_BEFORE_SHA to be that point. $CI_COMMIT_SHA is implicit because that is the current HEAD. So no need to mention it here.

do
if [ ! -f ${file} ];
then
echo "Skipping removed file."
elif git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $LINE_WIDTH + 1 ))\}"
elif git diff ${CI_COMMIT_BEFORE_SHA} -- ${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 ${CI_COMMIT_BEFORE_SHA} -- ${file} \
| grep -n "^+.\{$(( $LINE_WIDTH + 1))\}"
echo "|"
else
if git diff ${BASE_BRANCH} -- ${file} | grep -q "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
if git diff ${CI_COMMIT_BEFORE_SHA} -- ${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 ${CI_COMMIT_BEFORE_SHA} -- ${file} | grep -n "^+.\{$(( $GOOD_LINE_WIDTH + 1 ))\}"
echo "|"
fi
fi
Expand Down