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 |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 9 | import git_utils |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 10 | import optparse |
| 11 | import os |
| 12 | import re |
| 13 | import subprocess |
| 14 | import sys |
| 15 | import urllib |
| 16 | |
| 17 | import utils |
| 18 | |
| 19 | LUCI_SCHEDULE = os.path.join(utils.REPO_ROOT, 'infra', 'config', 'global', |
| 20 | 'luci-scheduler.cfg') |
| 21 | # Trigger lines have the format: |
| 22 | # triggers: "BUILDER_NAME" |
| 23 | TRIGGERS_RE = r'^ triggers: "(\w.*)"' |
| 24 | |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 25 | DESUGAR_BOT = 'archive_lib_desugar' |
| 26 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 27 | def 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 Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 32 | 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 Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 36 | result.add_option('--desugar', |
| 37 | help='Run the library desugar and archiving bot.', |
| 38 | default=False, action='store_true') |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 39 | result.add_option('--builder', help='Trigger specific builder') |
| 40 | return result.parse_args() |
| 41 | |
| 42 | def get_builders(): |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 43 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 44 | 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 Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 61 | assert DESUGAR_BOT in master_builders |
| 62 | print 'Desugar builder:\n ' + DESUGAR_BOT |
| 63 | master_builders.remove(DESUGAR_BOT) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 64 | print 'Master builders:\n ' + '\n '.join(master_builders) |
| 65 | print 'Release builders:\n ' + '\n '.join(release_builders) |
| 66 | return (master_builders, release_builders) |
| 67 | |
| 68 | def 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 | |
| 73 | def 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 Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 80 | def 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 Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 85 | def Main(): |
| 86 | (options, args) = ParseOptions() |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 87 | if len(args) != 1 and not options.cl and not options.desugar: |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 88 | print 'Takes exactly one argument, the commit to run' |
| 89 | return 1 |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 90 | |
| 91 | if options.cl and options.release: |
| 92 | print 'You can\'t run cls on the release bots' |
| 93 | return 1 |
| 94 | |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 95 | 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 Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 100 | (master_builders, release_builders) = get_builders() |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 101 | builders = release_builders if options.release else master_builders |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 102 | if options.builder: |
| 103 | builder = options.builder |
| 104 | assert builder in master_builders or builder in release_builders |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 105 | builders = [options.builder] |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 106 | if options.desugar: |
| 107 | builders = [DESUGAR_BOT] |
Rico Wind | 5986fb0 | 2019-08-15 08:57:25 +0200 | [diff] [blame] | 108 | commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_master=True) |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 109 | if options.cl: |
| 110 | trigger_cl(builders, options.cl) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 111 | else: |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 112 | assert commit |
| 113 | trigger_builders(builders, commit) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 114 | |
| 115 | if __name__ == '__main__': |
| 116 | sys.exit(Main()) |