Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix changed file detection on travis when the PR commits predate master commits. #3129

Merged
merged 3 commits into from
Jan 27, 2018

Conversation

ammaraskar
Copy link
Member

See python/core-workflow#14 for my investigation into this.

I got the command for the pull request file detection from http://eng.localytics.com/best-practices-and-common-mistakes-with-travis-ci/ though there's is hardcoded to only work for master

CHANGES=$(git --no-pager diff --name-only FETCH_HEAD $(git merge-base FETCH_HEAD master))  
[ -n "$(grep '^rails' <<< "$CHANGES")" ] && testRails

additionally I found the exact same command here: https://stackoverflow.com/a/41159710
and here: https://stackoverflow.com/questions/25071579/list-all-files-changed-in-a-pull-request-in-git-github

I've also made the script print out what files changed so this is easier to debug if it becomes an issue again in the future.

@ammaraskar
Copy link
Member Author

This can be labelled with both skip news and skip issue

@zware
Copy link
Member

zware commented Jan 26, 2018

@ammaraskar Would you mind rebasing this?

…er commits.

Travis when merging changes from a pull request onto the target branch
does not perform a rebase, instead it does a simple merge which causes
the PR commits to retain their commit dates. This means that the commit
log can potentially look like:

PR merge <-- HEAD
normal master commit <- master
more commits from normal workflow
PR commit 1
another master commit
PR commit 2

Performing a git diff from PR commit 2 to master will accidentally
include
files that should not be there.

Closes python/core-workflow#14
@ammaraskar
Copy link
Member Author

@zware done

Copy link
Member

@berkerpeksag berkerpeksag left a comment

Choose a reason for hiding this comment

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

Sorry for my very late response. This looks good to me and I agree with Ammar's analysis at python/core-workflow#14 (comment). I just left two minor comments.

.travis.yml Outdated
files_changed=$(git diff --name-only HEAD $(git merge-base HEAD $TRAVIS_BRANCH))
fi

echo "files_changed: "
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a comment saying that this is for debugging purposes and rename "files_changed:" to "Files changed:" to follow the current style?

.travis.yml Outdated
# Pull requests are slightly complicated because merging the PR commit without
# rebasing causes it to retain its old commit date. Meaning in history if any
# commits have been made on master that post-date it, they will be accidentally
# included in the diff if we use the simple TRAVIS_COMMIT_RANGE method
Copy link
Member

Choose a reason for hiding this comment

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

Can we just say "if we use TRAVIS_COMMIT_RANGE" or "if we use the TRAVIS_COMMIT_RANGE environment variable" to make it clearer? Perhaps it's just me but I got confused by the "method" part of that sentence :)

(Also, style nit: Can you finish the sentence with a full stop?)

@ammaraskar
Copy link
Member Author

Fixed up the comment style.

@jayyyin
Copy link
Contributor

jayyyin commented Jan 27, 2018

everything looks good to me too, also tested the regex, this should be good to go.

@berkerpeksag berkerpeksag merged commit b2ec361 into python:master Jan 27, 2018
@miss-islington
Copy link
Contributor

Thanks @ammaraskar for the PR, and @berkerpeksag for merging it 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖

@berkerpeksag
Copy link
Member

Thanks!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 27, 2018
Travis when merging changes from a pull request onto the target branch
does not perform a rebase, instead it does a simple merge which causes
the PR commits to retain their commit dates. This means that the commit
log can potentially look like:

PR merge <-- HEAD
normal master commit <- master
more commits from normal workflow
PR commit 1
another master commit
PR commit 2

Performing a git diff from PR commit 2 to master will accidentally
include files that should not be there.

Closes python/core-workflowGH-14
(cherry picked from commit b2ec361)
@bedevere-bot
Copy link

GH-5365 is a backport of this pull request to the 3.6 branch.

berkerpeksag pushed a commit that referenced this pull request Jan 27, 2018
Travis when merging changes from a pull request onto the target branch
does not perform a rebase, instead it does a simple merge which causes
the PR commits to retain their commit dates. This means that the commit
log can potentially look like:

PR merge <-- HEAD
normal master commit <- master
more commits from normal workflow
PR commit 1
another master commit
PR commit 2

Performing a git diff from PR commit 2 to master will accidentally
include files that should not be there.

Closes python/core-workflow#14

(cherry picked from commit b2ec361)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants