blob: 482608a29ec0c57d4f0f8f05792be4f8547dcda5 [file] [log] [blame]
Rico Windb873c642019-04-15 11:07:39 +02001#!/usr/bin/env python
2# Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6# Convenience script for triggering bots on specific commits.
7
8import json
Rico Wind1cd21b02019-08-14 13:26:21 +02009import git_utils
Rico Windb873c642019-04-15 11:07:39 +020010import optparse
11import os
12import re
13import subprocess
14import sys
15import urllib
16
17import utils
18
19LUCI_SCHEDULE = os.path.join(utils.REPO_ROOT, 'infra', 'config', 'global',
20 'luci-scheduler.cfg')
21# Trigger lines have the format:
22# triggers: "BUILDER_NAME"
23TRIGGERS_RE = r'^ triggers: "(\w.*)"'
24
Rico Wind1cd21b02019-08-14 13:26:21 +020025DESUGAR_BOT = 'archive_lib_desugar'
26
Rico Windb873c642019-04-15 11:07:39 +020027def ParseOptions():
28 result = optparse.OptionParser()
29 result.add_option('--release',
30 help='Run on the release branch builders.',
31 default=False, action='store_true')
Rico Winde11f71d2019-04-24 13:18:15 +020032 result.add_option('--cl',
33 help='Run the specified cl on the bots. This should be '
34 'the full url, e.g., '
35 'https://r8-review.googlesource.com/c/r8/+/37420/1')
Rico Wind1cd21b02019-08-14 13:26:21 +020036 result.add_option('--desugar',
37 help='Run the library desugar and archiving bot.',
38 default=False, action='store_true')
Rico Windb873c642019-04-15 11:07:39 +020039 result.add_option('--builder', help='Trigger specific builder')
40 return result.parse_args()
41
42def get_builders():
Rico Wind1cd21b02019-08-14 13:26:21 +020043
Rico Windb873c642019-04-15 11:07:39 +020044 is_release = False
45 master_builders = []
46 release_builders = []
47 with open(LUCI_SCHEDULE, 'r') as fp:
48 lines = fp.readlines()
49 for line in lines:
50 if 'branch-gitiles-trigger' in line:
51 is_release = True
52 match = re.match(TRIGGERS_RE, line)
53 if match:
54 builder = match.group(1)
55 if is_release:
56 assert 'release' in builder
57 release_builders.append(builder)
58 else:
59 assert 'release' not in builder
60 master_builders.append(builder)
Rico Wind1cd21b02019-08-14 13:26:21 +020061 assert DESUGAR_BOT in master_builders
62 print 'Desugar builder:\n ' + DESUGAR_BOT
63 master_builders.remove(DESUGAR_BOT)
Rico Windb873c642019-04-15 11:07:39 +020064 print 'Master builders:\n ' + '\n '.join(master_builders)
65 print 'Release builders:\n ' + '\n '.join(release_builders)
66 return (master_builders, release_builders)
67
68def sanity_check_url(url):
69 a = urllib.urlopen(url)
70 if a.getcode() != 200:
71 raise Exception('Url: %s \n returned %s' % (url, a.getcode()))
72
73def trigger_builders(builders, commit):
74 commit_url = 'https://r8.googlesource.com/r8/+/%s' % commit
75 sanity_check_url(commit_url)
76 for builder in builders:
77 cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-commit', commit_url]
78 subprocess.check_call(cmd)
79
Rico Winde11f71d2019-04-24 13:18:15 +020080def trigger_cl(builders, cl_url):
81 for builder in builders:
82 cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-cl', cl_url]
83 subprocess.check_call(cmd)
84
Rico Windb873c642019-04-15 11:07:39 +020085def Main():
86 (options, args) = ParseOptions()
Rico Wind1cd21b02019-08-14 13:26:21 +020087 if len(args) != 1 and not options.cl and not options.desugar:
Rico Windb873c642019-04-15 11:07:39 +020088 print 'Takes exactly one argument, the commit to run'
89 return 1
Rico Winde11f71d2019-04-24 13:18:15 +020090
91 if options.cl and options.release:
92 print 'You can\'t run cls on the release bots'
93 return 1
94
Rico Wind1cd21b02019-08-14 13:26:21 +020095 if options.cl and options.desugar:
96 print 'You can\'t run cls on the desugar bot'
97 return 1
98
99 commit = None if (options.cl or options.desugar) else args[0]
Rico Windb873c642019-04-15 11:07:39 +0200100 (master_builders, release_builders) = get_builders()
Rico Winde11f71d2019-04-24 13:18:15 +0200101 builders = release_builders if options.release else master_builders
Rico Windb873c642019-04-15 11:07:39 +0200102 if options.builder:
103 builder = options.builder
104 assert builder in master_builders or builder in release_builders
Rico Winde11f71d2019-04-24 13:18:15 +0200105 builders = [options.builder]
Rico Wind1cd21b02019-08-14 13:26:21 +0200106 if options.desugar:
107 builders = [DESUGAR_BOT]
Rico Wind5986fb02019-08-15 08:57:25 +0200108 commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_master=True)
Rico Winde11f71d2019-04-24 13:18:15 +0200109 if options.cl:
110 trigger_cl(builders, options.cl)
Rico Windb873c642019-04-15 11:07:39 +0200111 else:
Rico Winde11f71d2019-04-24 13:18:15 +0200112 assert commit
113 trigger_builders(builders, commit)
Rico Windb873c642019-04-15 11:07:39 +0200114
115if __name__ == '__main__':
116 sys.exit(Main())