Skip to content
Permalink
Browse files
[EWS] Rebase PRs on tip of branch
https://bugs.webkit.org/show_bug.cgi?id=236389
<rdar://problem/88705147>

Reviewed by Aakash Jain.

* Tools/CISupport/ews-build/master.cfg: Add github.base.ref to properties.
* Tools/CISupport/ews-build/steps.py:
(CheckOutSource.run): Set branch from github properties, if available.
(ShowIdentifier.start): Use 'got_revision' instead of github properties.
(CheckOutPullRequest.run): Rebase PRs if we have enough information to. To support
rebasing, we need to handle conflicts in changelogs.
(RevertPullRequestChanges.run): Revert to whatever revision we rebased on.
(Trigger.propertiesToPassToTriggers): Pass github.base.ref to triggered build.
* Tools/CISupport/ews-build/steps_unittest.py:


Canonical link: https://commits.webkit.org/247164@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@289676 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JonWBedard committed Feb 11, 2022
1 parent dbe0009 commit 2abbbbd49532a1a8d0929423dfbf2dd41ba400ba
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 16 deletions.
@@ -53,6 +53,7 @@ if not is_test_mode_enabled:
'github.title',
'github.head.ref',
'github.head.sha',
'github.base.ref',
'github.base.sha',
'github.head.repo.full_name',
], 'token': load_password('GITHUB_COM_ACCESS_TOKEN'),
@@ -355,6 +355,10 @@ def getResultSummary(self):
else:
return {'step': 'Cleaned and updated working directory'}

def run(self):
self.branch = self.getProperty('github.base.ref', self.branch)
return super(CheckOutSource, self).run()


class CleanUpGitIndexLock(shell.ShellCommand):
name = 'clean-git-index-lock'
@@ -399,7 +403,7 @@ def __init__(self, **kwargs):
super(CheckOutSpecificRevision, self).__init__(logEnviron=False, **kwargs)

def doStepIf(self, step):
return self.getProperty('ews_revision', False)
return self.getProperty('ews_revision', False) and not self.getProperty('github.number', False)

def hideStepIf(self, results, step):
return not self.doStepIf(step)
@@ -450,7 +454,7 @@ def start(self):

revision = 'HEAD'
# Note that these properties are delibrately in priority order.
for property_ in ['ews_revision', 'github.base.sha', 'got_revision']:
for property_ in ['ews_revision', 'got_revision']:
candidate = self.getProperty(property_)
if candidate:
revision = candidate
@@ -622,15 +626,23 @@ def run(self):

remote = self.getProperty('github.head.repo.full_name', 'origin').split('/')[0]
project = self.getProperty('github.head.repo.full_name', self.getProperty('project'))
branch = self.getProperty('github.head.ref', 'main')
pr_branch = self.getProperty('github.head.ref', 'main')
base_hash = self.getProperty('github.base.sha')
rebase_target_hash = self.getProperty('ews_revision') or self.getProperty('got_revision')

for command in [
commands = [
['/bin/sh', '-c', 'git remote add {} {}{}.git & true'.format(remote, GITHUB_URL, project)],
['git', 'remote', 'set-url', remote, '{}{}.git'.format(GITHUB_URL, project)],
['git', 'fetch', remote],
['git', 'branch', '-f', branch, 'remotes/{}/{}'.format(remote, branch)],
['git', 'checkout', branch],
]:
['git', 'branch', '-f', pr_branch, 'remotes/{}/{}'.format(remote, pr_branch)],
['git', 'checkout', pr_branch],
]
if rebase_target_hash and base_hash and rebase_target_hash != base_hash:
commands += [
['git', 'config', 'merge.changelog.driver', 'perl Tools/Scripts/resolve-ChangeLogs --merge-driver -c %O %A %B'],
['git', 'rebase', '--onto', rebase_target_hash, base_hash, pr_branch],
]
for command in commands:
self.commands.append(util.ShellArg(command=command, logname='stdio', haltOnFailure=True))

return super(CheckOutPullRequest, self).run()
@@ -639,7 +651,7 @@ def getResultSummary(self):
if self.results == SKIPPED:
return {'step': 'No pull request to checkout'}
if self.results != SUCCESS:
return {'step': 'Failed to checkout branch from PR {}'.format(self.getProperty('github.number'))}
return {'step': 'Failed to checkout and rebase branch from PR {}'.format(self.getProperty('github.number'))}
return super(CheckOutPullRequest, self).getResultSummary()


@@ -1482,7 +1494,7 @@ def run(self):
self.commands = []
for command in [
['git', 'clean', '-f', '-d'],
['git', 'checkout', self.getProperty('github.base.sha')],
['git', 'checkout', self.getProperty('ews_revision') or self.getProperty('got_revision')],
]:
self.commands.append(util.ShellArg(command=command, logname='stdio'))
return super(RevertPullRequestChanges, self).run()
@@ -1512,7 +1524,7 @@ def propertiesToPassToTriggers(self, patch=True, pull_request=False):
property_names += ['patch_id', 'bug_id', 'owner']
if pull_request:
property_names += [
'github.base.sha', 'github.head.ref', 'github.head.sha',
'github.base.ref', 'github.base.sha', 'github.head.ref', 'github.head.sha',
'github.head.repo.full_name', 'github.number', 'github.title',
'repository', 'project', 'owners',
]
@@ -1521,7 +1533,7 @@ def propertiesToPassToTriggers(self, patch=True, pull_request=False):

properties_to_pass = {prop: properties.Property(prop) for prop in property_names}
properties_to_pass['retry_count'] = properties.Property('retry_count', default=0)
if self.include_revision and patch:
if self.include_revision:
properties_to_pass['ews_revision'] = properties.Property('got_revision')
return properties_to_pass

@@ -3896,6 +3908,7 @@ def run(self):
branch = self.getProperty('basename', self.default_branch)
self.commands = []
for command in [
['git', 'rebase', '--abort'],
['git', 'clean', '-f', '-d'], # Remove any left-over layout test results, added files, etc.
['git', 'fetch', self.git_remote], # Avoid updating the working copy to a stale revision.
['git', 'checkout', '{}/{}'.format(self.git_remote, branch), '-f'], # Checkout branch from specific remote
@@ -2924,6 +2924,14 @@ def test_skip(self):
self.expectOutcome(result=SKIPPED, state_string='Checked out required revision (skipped)')
return self.runStep()

def test_skip_pr(self):
self.setupStep(CheckOutSpecificRevision())
self.setProperty('github.number', '1234')
self.setProperty('ews_revision', '1a3425cb92dbcbca12a10aa9514f1b77c76dc26')
self.expectHidden(True)
self.expectOutcome(result=SKIPPED, state_string='Checked out required revision (skipped)')
return self.runStep()


class TestCleanWorkingDirectory(BuildStepMixinAdditions, unittest.TestCase):
def setUp(self):
@@ -3079,6 +3087,8 @@ def test_success(self):
self.setProperty('github.number', '1234')
self.setProperty('github.head.repo.full_name', 'Contributor/WebKit')
self.setProperty('github.head.ref', 'eng/pull-request-branch')
self.setProperty('github.base.sha', 'aaebef7312238f3ad1d25e8894916a1aaea45ba1')
self.setProperty('got_revision', '59dab0396721db221c264aad3c0cea37ef0d297b')
self.assertEqual(CheckOutPullRequest.flunkOnFailure, True)
self.assertEqual(CheckOutPullRequest.haltOnFailure, True)
self.expectRemoteCommands(
@@ -3107,6 +3117,16 @@ def test_success(self):
timeout=600,
logEnviron=False,
command=['git', 'checkout', 'eng/pull-request-branch'],
) + 0, ExpectShell(
workdir='wkdir',
timeout=600,
logEnviron=False,
command=['git', 'config', 'merge.changelog.driver', 'perl Tools/Scripts/resolve-ChangeLogs --merge-driver -c %O %A %B'],
) + 0, ExpectShell(
workdir='wkdir',
timeout=600,
logEnviron=False,
command=['git', 'rebase', '--onto', '59dab0396721db221c264aad3c0cea37ef0d297b', 'aaebef7312238f3ad1d25e8894916a1aaea45ba1', 'eng/pull-request-branch'],
) + 0,
)
self.expectOutcome(result=SUCCESS, state_string='Checked out pull request')
@@ -3117,6 +3137,8 @@ def test_failure(self):
self.setProperty('github.number', '1234')
self.setProperty('github.head.repo.full_name', 'Contributor/WebKit')
self.setProperty('github.head.ref', 'eng/pull-request-branch')
self.setProperty('github.base.sha', 'aaebef7312238f3ad1d25e8894916a1aaea45ba1')
self.setProperty('got_revision', '59dab0396721db221c264aad3c0cea37ef0d297b')
self.assertEqual(CheckOutPullRequest.flunkOnFailure, True)
self.assertEqual(CheckOutPullRequest.haltOnFailure, True)
self.expectRemoteCommands(
@@ -3137,7 +3159,7 @@ def test_failure(self):
command=['git', 'fetch', 'Contributor'],
) + 1,
)
self.expectOutcome(result=FAILURE, state_string='Failed to checkout branch from PR 1234')
self.expectOutcome(result=FAILURE, state_string='Failed to checkout and rebase branch from PR 1234')
return self.runStep()

def test_skipped(self):
@@ -3201,7 +3223,7 @@ def tearDown(self):

def test_success(self):
self.setupStep(RevertPullRequestChanges())
self.setProperty('github.base.sha', 'b2db8d1da7b74b5ddf075e301370e64d914eef7c')
self.setProperty('got_revision', 'b2db8d1da7b74b5ddf075e301370e64d914eef7c')
self.setProperty('github.number', 1234)
self.expectHidden(False)
self.expectRemoteCommands(
@@ -3222,7 +3244,7 @@ def test_success(self):

def test_failure(self):
self.setupStep(RevertPullRequestChanges())
self.setProperty('github.base.sha', 'b2db8d1da7b74b5ddf075e301370e64d914eef7c')
self.setProperty('ews_revision', 'b2db8d1da7b74b5ddf075e301370e64d914eef7c')
self.setProperty('github.number', 1234)
self.expectHidden(False)
self.expectRemoteCommands(
@@ -4535,6 +4557,8 @@ def test_success(self):
self.setProperty('buildername', 'Style-EWS')

self.expectRemoteCommands(
ExpectShell(command=['git', 'rebase', '--abort'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'clean', '-f', '-d'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'fetch', 'origin'], workdir='wkdir', timeout=300, logEnviron=False) + 0
@@ -4554,6 +4578,8 @@ def test_success_master(self):
self.setProperty('buildername', 'Commit-Queue')

self.expectRemoteCommands(
ExpectShell(command=['git', 'rebase', '--abort'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'clean', '-f', '-d'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'fetch', 'origin'], workdir='wkdir', timeout=300, logEnviron=False) + 0
@@ -4573,6 +4599,8 @@ def test_failure(self):
self.setProperty('buildername', 'Commit-Queue')

self.expectRemoteCommands(
ExpectShell(command=['git', 'rebase', '--abort'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'clean', '-f', '-d'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'fetch', 'origin'], workdir='wkdir', timeout=300, logEnviron=False) + 128
@@ -4593,6 +4621,8 @@ def test_branch(self):
self.setProperty('basename', 'safari-612-branch')

self.expectRemoteCommands(
ExpectShell(command=['git', 'rebase', '--abort'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'clean', '-f', '-d'], workdir='wkdir', timeout=300, logEnviron=False) + 0
+ ExpectShell.log('stdio', stdout=''),
ExpectShell(command=['git', 'fetch', 'origin'], workdir='wkdir', timeout=300, logEnviron=False) + 0
@@ -5063,7 +5093,7 @@ def test_success(self):

def test_success_pull_request(self):
self.setupStep(ShowIdentifier())
self.setProperty('github.base.sha', '51a6aec9f664')
self.setProperty('got_revision', '51a6aec9f664')
self.expectRemoteCommands(
ExpectShell(workdir='wkdir',
timeout=300,
@@ -5080,7 +5110,7 @@ def test_success_pull_request(self):
def test_prioritized(self):
self.setupStep(ShowIdentifier())
self.setProperty('ews_revision', '51a6aec9f664')
self.setProperty('github.base.sha', '9f66451a6aec')
self.setProperty('got_revision', '9f66451a6aec')
self.expectRemoteCommands(
ExpectShell(workdir='wkdir',
timeout=300,
@@ -1,3 +1,21 @@
2022-02-09 Jonathan Bedard <jbedard@apple.com>

[EWS] Rebase PRs on tip of branch
https://bugs.webkit.org/show_bug.cgi?id=236389
<rdar://problem/88705147>

Reviewed by Aakash Jain.

* CISupport/ews-build/master.cfg: Add github.base.ref to properties.
* CISupport/ews-build/steps.py:
(CheckOutSource.run): Set branch from github properties, if available.
(ShowIdentifier.start): Use 'got_revision' instead of github properties.
(CheckOutPullRequest.run): Rebase PRs if we have enough information to. To support
rebasing, we need to handle conflicts in changelogs.
(RevertPullRequestChanges.run): Revert to whatever revision we rebased on.
(Trigger.propertiesToPassToTriggers): Pass github.base.ref to triggered build.
* CISupport/ews-build/steps_unittest.py:

2022-02-02 Jonathan Bedard <jbedard@apple.com>

[git-webkit] Handle local commit on production branch

0 comments on commit 2abbbbd

Please sign in to comment.