Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 1 | #!/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 | |
| 8 | import json |
| 9 | import optparse |
| 10 | import os |
| 11 | import re |
| 12 | import subprocess |
| 13 | import sys |
| 14 | import urllib |
| 15 | |
| 16 | import utils |
| 17 | |
| 18 | LUCI_SCHEDULE = os.path.join(utils.REPO_ROOT, 'infra', 'config', 'global', |
| 19 | 'luci-scheduler.cfg') |
| 20 | # Trigger lines have the format: |
| 21 | # triggers: "BUILDER_NAME" |
| 22 | TRIGGERS_RE = r'^ triggers: "(\w.*)"' |
| 23 | |
| 24 | def 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 Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 29 | 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 Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 33 | result.add_option('--builder', help='Trigger specific builder') |
| 34 | return result.parse_args() |
| 35 | |
| 36 | def 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 | |
| 58 | def 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 | |
| 63 | def 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 Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 70 | def 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 Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 75 | def Main(): |
| 76 | (options, args) = ParseOptions() |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 77 | if len(args) != 1 and not options.cl: |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 78 | print 'Takes exactly one argument, the commit to run' |
| 79 | return 1 |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 80 | |
| 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 Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 86 | (master_builders, release_builders) = get_builders() |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 87 | builders = release_builders if options.release else master_builders |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 88 | if options.builder: |
| 89 | builder = options.builder |
| 90 | assert builder in master_builders or builder in release_builders |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 91 | builders = [options.builder] |
| 92 | if options.cl: |
| 93 | trigger_cl(builders, options.cl) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 94 | else: |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 95 | assert commit |
| 96 | trigger_builders(builders, commit) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 97 | |
| 98 | if __name__ == '__main__': |
| 99 | sys.exit(Main()) |