blob: 1a337958a51318fc64c1bfee3e3e4b351859c597 [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
9import optparse
10import os
11import re
12import subprocess
13import sys
14import urllib
15
16import utils
17
18LUCI_SCHEDULE = os.path.join(utils.REPO_ROOT, 'infra', 'config', 'global',
19 'luci-scheduler.cfg')
20# Trigger lines have the format:
21# triggers: "BUILDER_NAME"
22TRIGGERS_RE = r'^ triggers: "(\w.*)"'
23
24def ParseOptions():
25 result = optparse.OptionParser()
26 result.add_option('--release',
27 help='Run on the release branch builders.',
28 default=False, action='store_true')
Rico Winde11f71d2019-04-24 13:18:15 +020029 result.add_option('--cl',
30 help='Run the specified cl on the bots. This should be '
31 'the full url, e.g., '
32 'https://r8-review.googlesource.com/c/r8/+/37420/1')
Rico Windb873c642019-04-15 11:07:39 +020033 result.add_option('--builder', help='Trigger specific builder')
34 return result.parse_args()
35
36def get_builders():
37 is_release = False
38 master_builders = []
39 release_builders = []
40 with open(LUCI_SCHEDULE, 'r') as fp:
41 lines = fp.readlines()
42 for line in lines:
43 if 'branch-gitiles-trigger' in line:
44 is_release = True
45 match = re.match(TRIGGERS_RE, line)
46 if match:
47 builder = match.group(1)
48 if is_release:
49 assert 'release' in builder
50 release_builders.append(builder)
51 else:
52 assert 'release' not in builder
53 master_builders.append(builder)
54 print 'Master builders:\n ' + '\n '.join(master_builders)
55 print 'Release builders:\n ' + '\n '.join(release_builders)
56 return (master_builders, release_builders)
57
58def sanity_check_url(url):
59 a = urllib.urlopen(url)
60 if a.getcode() != 200:
61 raise Exception('Url: %s \n returned %s' % (url, a.getcode()))
62
63def trigger_builders(builders, commit):
64 commit_url = 'https://r8.googlesource.com/r8/+/%s' % commit
65 sanity_check_url(commit_url)
66 for builder in builders:
67 cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-commit', commit_url]
68 subprocess.check_call(cmd)
69
Rico Winde11f71d2019-04-24 13:18:15 +020070def trigger_cl(builders, cl_url):
71 for builder in builders:
72 cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-cl', cl_url]
73 subprocess.check_call(cmd)
74
Rico Windb873c642019-04-15 11:07:39 +020075def Main():
76 (options, args) = ParseOptions()
Rico Winde11f71d2019-04-24 13:18:15 +020077 if len(args) != 1 and not options.cl:
Rico Windb873c642019-04-15 11:07:39 +020078 print 'Takes exactly one argument, the commit to run'
79 return 1
Rico Winde11f71d2019-04-24 13:18:15 +020080
81 if options.cl and options.release:
82 print 'You can\'t run cls on the release bots'
83 return 1
84
85 commit = None if options.cl else args[0]
Rico Windb873c642019-04-15 11:07:39 +020086 (master_builders, release_builders) = get_builders()
Rico Winde11f71d2019-04-24 13:18:15 +020087 builders = release_builders if options.release else master_builders
Rico Windb873c642019-04-15 11:07:39 +020088 if options.builder:
89 builder = options.builder
90 assert builder in master_builders or builder in release_builders
Rico Winde11f71d2019-04-24 13:18:15 +020091 builders = [options.builder]
92 if options.cl:
93 trigger_cl(builders, options.cl)
Rico Windb873c642019-04-15 11:07:39 +020094 else:
Rico Winde11f71d2019-04-24 13:18:15 +020095 assert commit
96 trigger_builders(builders, commit)
Rico Windb873c642019-04-15 11:07:39 +020097
98if __name__ == '__main__':
99 sys.exit(Main())