Commit be5fccd4 authored by Greg Guterman's avatar Greg Guterman Committed by LUCI CQ

[rts] Add -q flag to git cl try, upload, and set_commit

Quick run is only set when the -q flag is passed. It is not set to 0 by
other flags because only Chromium has Quick run and there are other
depot_tools users. We rely on the CQ to set the flag back to 0.

Bug: 1192827
Change-Id: I3310c9f005343f7d3eea56eaad5f19c7ba751921
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2927818
Commit-Queue: Gregory Guterman <guterman@google.com>
Reviewed-by: 's avatarEdward Lesmes <ehmaldonado@chromium.org>
parent ef579a11
...@@ -836,10 +836,11 @@ class Settings(object): ...@@ -836,10 +836,11 @@ class Settings(object):
class _CQState(object): class _CQState(object):
"""Enum for states of CL with respect to CQ.""" """Enum for states of CL with respect to CQ."""
NONE = 'none' NONE = 'none'
QUICK_RUN = 'quick_run'
DRY_RUN = 'dry_run' DRY_RUN = 'dry_run'
COMMIT = 'commit' COMMIT = 'commit'
ALL_STATES = [NONE, DRY_RUN, COMMIT] ALL_STATES = [NONE, QUICK_RUN, DRY_RUN, COMMIT]
class _ParsedIssueNumberArgument(object): class _ParsedIssueNumberArgument(object):
...@@ -1527,17 +1528,25 @@ class Changelist(object): ...@@ -1527,17 +1528,25 @@ class Changelist(object):
def SetCQState(self, new_state): def SetCQState(self, new_state):
"""Updates the CQ state for the latest patchset. """Updates the CQ state for the latest patchset.
Issue must have been already uploaded and known. Issue must have been already uploaded and known. Optionally allows for
updating Quick-Run (QR) state.
""" """
assert new_state in _CQState.ALL_STATES assert new_state in _CQState.ALL_STATES
assert self.GetIssue() assert self.GetIssue()
try: try:
vote_map = { vote_map = {
_CQState.NONE: 0, _CQState.NONE: 0,
_CQState.QUICK_RUN: 1,
_CQState.DRY_RUN: 1, _CQState.DRY_RUN: 1,
_CQState.COMMIT: 2, _CQState.COMMIT: 2,
} }
labels = {'Commit-Queue': vote_map[new_state]} if new_state == _CQState.QUICK_RUN:
labels = {
'Commit-Queue': vote_map[_CQState.DRY_RUN],
'Quick-Run': vote_map[_CQState.QUICK_RUN],
}
else:
labels = {'Commit-Queue': vote_map[new_state]}
notify = False if new_state == _CQState.DRY_RUN else None notify = False if new_state == _CQState.DRY_RUN else None
gerrit_util.SetReview( gerrit_util.SetReview(
self.GetGerritHost(), self._GerritChangeIdentifier(), self.GetGerritHost(), self._GerritChangeIdentifier(),
...@@ -2460,6 +2469,9 @@ class Changelist(object): ...@@ -2460,6 +2469,9 @@ class Changelist(object):
refspec_opts.append('l=Commit-Queue+2') refspec_opts.append('l=Commit-Queue+2')
elif options.cq_dry_run: elif options.cq_dry_run:
refspec_opts.append('l=Commit-Queue+1') refspec_opts.append('l=Commit-Queue+1')
elif options.cq_quick_run:
refspec_opts.append('l=Commit-Queue+1')
refspec_opts.append('l=Quick-Run+1')
if change_desc.get_reviewers(tbr_only=True): if change_desc.get_reviewers(tbr_only=True):
score = gerrit_util.GetCodeReviewTbrScore( score = gerrit_util.GetCodeReviewTbrScore(
...@@ -4216,6 +4228,14 @@ def CMDupload(parser, args): ...@@ -4216,6 +4228,14 @@ def CMDupload(parser, args):
action='store_true', default=False, action='store_true', default=False,
help='Send the patchset to do a CQ dry run right after ' help='Send the patchset to do a CQ dry run right after '
'upload.') 'upload.')
parser.add_option(
'-q',
'--cq-quick-run',
action='store_true',
default=False,
help='Send the patchset to do a CQ quick run right after '
'upload (https://source.chromium.org/chromium/chromium/src/+/main:do'
'cs/cq_quick_run.md) (chromium only).')
parser.add_option('--set-bot-commit', action='store_true', parser.add_option('--set-bot-commit', action='store_true',
help=optparse.SUPPRESS_HELP) help=optparse.SUPPRESS_HELP)
parser.add_option('--preserve-tryjobs', action='store_true', parser.add_option('--preserve-tryjobs', action='store_true',
...@@ -4293,10 +4313,11 @@ def CMDupload(parser, args): ...@@ -4293,10 +4313,11 @@ def CMDupload(parser, args):
options.message = gclient_utils.FileRead(options.message_file) options.message = gclient_utils.FileRead(options.message_file)
if ([options.cq_dry_run, if ([options.cq_dry_run,
options.cq_quick_run,
options.use_commit_queue, options.use_commit_queue,
options.retry_failed].count(True) > 1): options.retry_failed].count(True) > 1):
parser.error('Only one of --use-commit-queue, --cq-dry-run, or ' parser.error('Only one of --use-commit-queue, --cq-dry-run, --cq-quick-run '
'--retry-failed is allowed.') 'or --retry-failed is allowed.')
if options.skip_title and options.title: if options.skip_title and options.title:
parser.error('Only one of --title and --skip-title allowed.') parser.error('Only one of --title and --skip-title allowed.')
...@@ -4571,6 +4592,14 @@ def CMDtry(parser, args): ...@@ -4571,6 +4592,14 @@ def CMDtry(parser, args):
'-c', '--clobber', action='store_true', default=False, '-c', '--clobber', action='store_true', default=False,
help='Force a clobber before building; that is don\'t do an ' help='Force a clobber before building; that is don\'t do an '
'incremental build') 'incremental build')
group.add_option(
'-q',
'--quick-run',
action='store_true',
default=False,
help='trigger in quick run mode '
'(https://source.chromium.org/chromium/chromium/src/+/main:docs/cq_q'
'uick_run.md) (chromium only).')
group.add_option( group.add_option(
'--category', default='git_cl_try', help='Specify custom build category.') '--category', default='git_cl_try', help='Specify custom build category.')
group.add_option( group.add_option(
...@@ -4652,6 +4681,9 @@ def CMDtry(parser, args): ...@@ -4652,6 +4681,9 @@ def CMDtry(parser, args):
if num_builders > 10: if num_builders > 10:
confirm_or_exit('There are %d builders with failed builds.' confirm_or_exit('There are %d builders with failed builds.'
% num_builders, action='continue') % num_builders, action='continue')
elif options.quick_run:
print('Scheduling CQ quick run on: %s' % cl.GetIssueURL())
return cl.SetCQState(_CQState.QUICK_RUN)
else: else:
if options.verbose: if options.verbose:
print('git cl try with no bots now defaults to CQ dry run.') print('git cl try with no bots now defaults to CQ dry run.')
...@@ -4774,6 +4806,13 @@ def CMDset_commit(parser, args): ...@@ -4774,6 +4806,13 @@ def CMDset_commit(parser, args):
"""Sets the commit bit to trigger the CQ.""" """Sets the commit bit to trigger the CQ."""
parser.add_option('-d', '--dry-run', action='store_true', parser.add_option('-d', '--dry-run', action='store_true',
help='trigger in dry run mode') help='trigger in dry run mode')
parser.add_option(
'-q',
'--quick-run',
action='store_true',
help='trigger in quick run mode '
'(https://source.chromium.org/chromium/chromium/src/+/main:docs/cq_qu'
'ick_run.md) (chromium only).')
parser.add_option('-c', '--clear', action='store_true', parser.add_option('-c', '--clear', action='store_true',
help='stop CQ run, if any') help='stop CQ run, if any')
parser.add_option( parser.add_option(
...@@ -4783,18 +4822,21 @@ def CMDset_commit(parser, args): ...@@ -4783,18 +4822,21 @@ def CMDset_commit(parser, args):
options, args = parser.parse_args(args) options, args = parser.parse_args(args)
if args: if args:
parser.error('Unrecognized args: %s' % ' '.join(args)) parser.error('Unrecognized args: %s' % ' '.join(args))
if options.dry_run and options.clear: if [options.dry_run, options.quick_run, options.clear].count(True) > 1:
parser.error('Only one of --dry-run and --clear are allowed.') parser.error('Only one of --dry-run, --quick-run, and --clear are allowed.')
cl = Changelist(issue=options.issue) cl = Changelist(issue=options.issue)
if not cl.GetIssue():
parser.error('Must upload the issue first.')
if options.clear: if options.clear:
state = _CQState.NONE state = _CQState.NONE
elif options.quick_run:
state = _CQState.QUICK_RUN
elif options.dry_run: elif options.dry_run:
state = _CQState.DRY_RUN state = _CQState.DRY_RUN
else: else:
state = _CQState.COMMIT state = _CQState.COMMIT
if not cl.GetIssue():
parser.error('Must upload the issue first.')
cl.SetCQState(state) cl.SetCQState(state)
return 0 return 0
......
...@@ -2116,6 +2116,18 @@ class TestGitCl(unittest.TestCase): ...@@ -2116,6 +2116,18 @@ class TestGitCl(unittest.TestCase):
{'Commit-Queue': vote}, notify, None), ''), {'Commit-Queue': vote}, notify, None), ''),
] ]
def _cmd_set_quick_run_gerrit(self):
self.mockGit.config['branch.master.gerritissue'] = '123'
self.mockGit.config['branch.master.gerritserver'] = (
'https://chromium-review.googlesource.com')
self.mockGit.config['remote.origin.url'] = (
'https://chromium.googlesource.com/infra/infra')
self.calls = [
(('SetReview', 'chromium-review.googlesource.com',
'infra%2Finfra~123', None,
{'Commit-Queue': 1, 'Quick-Run': 1}, None, None), ''),
]
def test_cmd_set_commit_gerrit_clear(self): def test_cmd_set_commit_gerrit_clear(self):
self._cmd_set_commit_gerrit_common(0) self._cmd_set_commit_gerrit_common(0)
self.assertEqual(0, git_cl.main(['set-commit', '-c'])) self.assertEqual(0, git_cl.main(['set-commit', '-c']))
...@@ -2128,6 +2140,10 @@ class TestGitCl(unittest.TestCase): ...@@ -2128,6 +2140,10 @@ class TestGitCl(unittest.TestCase):
self._cmd_set_commit_gerrit_common(2) self._cmd_set_commit_gerrit_common(2)
self.assertEqual(0, git_cl.main(['set-commit'])) self.assertEqual(0, git_cl.main(['set-commit']))
def test_cmd_set_quick_run_gerrit(self):
self._cmd_set_quick_run_gerrit()
self.assertEqual(0, git_cl.main(['set-commit', '-q']))
def test_description_display(self): def test_description_display(self):
mock.patch('git_cl.Changelist', ChangelistMock).start() mock.patch('git_cl.Changelist', ChangelistMock).start()
ChangelistMock.desc = 'foo\n' ChangelistMock.desc = 'foo\n'
...@@ -3578,6 +3594,16 @@ class CMDTryTestCase(CMDTestCaseBase): ...@@ -3578,6 +3594,16 @@ class CMDTryTestCase(CMDTestCaseBase):
'Scheduling CQ dry run on: ' 'Scheduling CQ dry run on: '
'https://chromium-review.googlesource.com/123456\n') 'https://chromium-review.googlesource.com/123456\n')
@mock.patch('git_cl.Changelist.SetCQState')
def testSetCQQuickRunByDefault(self, mockSetCQState):
mockSetCQState.return_value = 0
self.assertEqual(0, git_cl.main(['try', '-q']))
git_cl.Changelist.SetCQState.assert_called_with(git_cl._CQState.QUICK_RUN)
self.assertEqual(
sys.stdout.getvalue(),
'Scheduling CQ quick run on: '
'https://chromium-review.googlesource.com/123456\n')
@mock.patch('git_cl._call_buildbucket') @mock.patch('git_cl._call_buildbucket')
def testScheduleOnBuildbucket(self, mockCallBuildbucket): def testScheduleOnBuildbucket(self, mockCallBuildbucket):
mockCallBuildbucket.return_value = {} mockCallBuildbucket.return_value = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment