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

Add DTS as part of deploy_to_test. #13930

Merged
merged 6 commits into from Mar 27, 2017
Merged

Add DTS as part of deploy_to_test. #13930

merged 6 commits into from Mar 27, 2017

Conversation

ashercodeorg
Copy link
Contributor

@ashercodeorg ashercodeorg commented Mar 22, 2017

This attempts to fix an exception (example below) being seen by deploy_to_test where test contains several merge commits from staging that have not yet been merged back to staging.

EXCEPTION: PUT https://api.github.com/repos/code-dot-org/code-dot-org/pulls/13928/merge:
405 - Base branch was modified. Review and try the merge again. 
// See: https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button

if pr_number.nil?
raise Exception.new('GitHub.create_and_merge_pull_request failed.')
end
sleep 15
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is totally unclear to me whether this sleep is required. It just seems useful so as to not have a race condition with the GitHub API. Thoughts?

@islemaster
Copy link
Contributor

👀 Looking...

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

More generally, I'm not sure this is the right approach to that error message, because it's not how our manual DTT process normally works - it shouldn't be a problem for test to be ahead by a few merge commits, as long as there are no conflicts.

I've seen this error in the GitHub UI every once in a while. It seems like a race condition where the base branch changed between the mergeability check and the merge button click, and the solution is usually to run another mergeability check (reloading the page?), not necessarily backmerging. I wonder if our cronjob should sleep 10 and try again in this situation instead of attempting to backmerge.

All that said, I have no idea why this would be an issue for our overnight robo-DTT - something smells fishy here, like there's a timing problem or an incorrect API response. And it makes me wonder if we'll soon be better off moving away from pull requests for deploy merges and merging directly instead (with appropriate affordances for exploring deploy history, of course).

@@ -31,6 +31,31 @@ def main

DevelopersTopic.set_dtt TOPIC_DTT_IN_PROGRESS

unless GitHub.compare(base: 'staging', head: 'test').empty?
Copy link
Contributor

Choose a reason for hiding this comment

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

So, I wrote a helper for this yesterday and backed it out because I didn't find a compelling use case - but you've got one here. The compare API returns ahead/behind information which feels like a cleaner way to ask this question.

  "status": "behind",
  "ahead_by": 1,
  "behind_by": 2,
  "total_commits": 1,

So maybe GitHub.ahead?(base: 'staging', head: 'test')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

)
pr_number = GitHub.create_and_merge_pull_request(
base: 'staging',
head: 'head',
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be head: 'test',.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ashercodeorg ashercodeorg force-pushed the fixDeployToTest branch 2 times, most recently from e490961 to e5ad542 Compare March 23, 2017 16:56
@ashercodeorg
Copy link
Contributor Author

PTAL. Note that I intend to update other GitHub methods to use compare rather than head, where appropriate, in another PR.

base_sha = sha(base)
compare_sha = sha(compare)

response = Octokit.compare(REPO, base_sha, compare_sha)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we getting the hashes at all here? Compare should accept branch names. From the docs:

GET /repos/:owner/:repo/compare/:base...:head

Both :base and :head must be branch names in :repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. Changing...

@islemaster
Copy link
Contributor

New helpers look good, but you haven't addressed my thoughts on whether a backmerge is the right approach at all here.

@ashercodeorg
Copy link
Contributor Author

As suggested, I changed the DTS (Test > Staging) to a sleep between the create and merge. PTAL.

def self.ahead?(base:, compare:)
response = Octokit.compare(REPO, base, compare)
response.ahead_by > 0
end
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is now unused. Let me know if you would rather it remain or be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. My default instinct is to remove dead code, esp. since we have no test over this. Should be trivial to reconstruct from the behind? method below, too. Let's cut it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@islemaster islemaster left a comment

Choose a reason for hiding this comment

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

LGTM!

@ashercodeorg ashercodeorg merged commit 02bf12d into staging Mar 27, 2017
@ashercodeorg ashercodeorg deleted the fixDeployToTest branch March 27, 2017 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants