Ian Zerny | dcb172e | 2022-02-22 15:36:45 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 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 |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 16 | from urllib.request import urlopen |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 17 | import utils |
| 18 | |
| 19 | LUCI_SCHEDULE = os.path.join(utils.REPO_ROOT, 'infra', 'config', 'global', |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 20 | 'generated', 'luci-scheduler.cfg') |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 21 | # Trigger lines have the format: |
| 22 | # triggers: "BUILDER_NAME" |
| 23 | TRIGGERS_RE = r'^ triggers: "(\w.*)"' |
| 24 | |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 25 | DESUGAR_JDK11_BOT = 'lib_desugar-archive-jdk11' |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 26 | DESUGAR_JDK11_LEGACY_BOT = 'lib_desugar-archive-jdk11-legacy' |
Søren Gjesse | 45c7038 | 2022-06-24 10:37:07 +0200 | [diff] [blame] | 27 | DESUGAR_JDK8_BOT = 'lib_desugar-archive-jdk8' |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 28 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 29 | def ParseOptions(): |
| 30 | result = optparse.OptionParser() |
| 31 | result.add_option('--release', |
| 32 | help='Run on the release branch builders.', |
| 33 | default=False, action='store_true') |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 34 | result.add_option('--cl', |
| 35 | help='Run the specified cl on the bots. This should be ' |
| 36 | 'the full url, e.g., ' |
| 37 | 'https://r8-review.googlesource.com/c/r8/+/37420/1') |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 38 | result.add_option('--desugar-jdk11', |
| 39 | help='Run the jdk11 library desugar and archiving bot.', |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 40 | default=False, action='store_true') |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 41 | result.add_option('--desugar-jdk11-legacy', |
| 42 | help='Run the jdk11 legacy library desugar and archiving bot.', |
| 43 | default=False, action='store_true') |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 44 | result.add_option('--desugar-jdk8', |
| 45 | help='Run the jdk8 library desugar and archiving bot.', |
| 46 | default=False, action='store_true') |
| 47 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 48 | result.add_option('--builder', help='Trigger specific builder') |
| 49 | return result.parse_args() |
| 50 | |
| 51 | def get_builders(): |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 52 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 53 | is_release = False |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 54 | main_builders = [] |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 55 | release_builders = [] |
| 56 | with open(LUCI_SCHEDULE, 'r') as fp: |
| 57 | lines = fp.readlines() |
| 58 | for line in lines: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 59 | if 'branch-gitiles' in line: |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 60 | is_release = True |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 61 | if 'main-gitiles-trigger' in line: |
| 62 | is_release = False |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 63 | match = re.match(TRIGGERS_RE, line) |
| 64 | if match: |
| 65 | builder = match.group(1) |
| 66 | if is_release: |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 67 | assert 'release' in builder, builder |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 68 | release_builders.append(builder) |
| 69 | else: |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 70 | assert 'release' not in builder, builder |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 71 | main_builders.append(builder) |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 72 | print('Desugar jdk11 builder:\n ' + DESUGAR_JDK11_BOT) |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 73 | print('Desugar jdk11 legacy builder:\n ' + DESUGAR_JDK11_LEGACY_BOT) |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 74 | print('Desugar jdk8 builder:\n ' + DESUGAR_JDK8_BOT) |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 75 | print('Main builders:\n ' + '\n '.join(main_builders)) |
| 76 | print('Release builders:\n ' + '\n '.join(release_builders)) |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 77 | return (main_builders, release_builders) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 78 | |
| 79 | def sanity_check_url(url): |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 80 | a = urlopen(url) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 81 | if a.getcode() != 200: |
| 82 | raise Exception('Url: %s \n returned %s' % (url, a.getcode())) |
| 83 | |
| 84 | def trigger_builders(builders, commit): |
| 85 | commit_url = 'https://r8.googlesource.com/r8/+/%s' % commit |
| 86 | sanity_check_url(commit_url) |
| 87 | for builder in builders: |
| 88 | cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-commit', commit_url] |
| 89 | subprocess.check_call(cmd) |
| 90 | |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 91 | def trigger_cl(builders, cl_url): |
| 92 | for builder in builders: |
| 93 | cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-cl', cl_url] |
| 94 | subprocess.check_call(cmd) |
| 95 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 96 | def Main(): |
| 97 | (options, args) = ParseOptions() |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 98 | desugar = options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8 |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 99 | if len(args) != 1 and not options.cl and not desugar: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 100 | print('Takes exactly one argument, the commit to run') |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 101 | return 1 |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 102 | |
| 103 | if options.cl and options.release: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 104 | print('You can\'t run cls on the release bots') |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 105 | return 1 |
| 106 | |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 107 | if options.cl and desugar: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 108 | print('You can\'t run cls on the desugar bot') |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 109 | return 1 |
| 110 | |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 111 | commit = None if (options.cl or desugar) else args[0] |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 112 | (main_builders, release_builders) = get_builders() |
| 113 | builders = release_builders if options.release else main_builders |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 114 | if options.builder: |
| 115 | builder = options.builder |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 116 | assert builder in main_builders or builder in release_builders |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 117 | builders = [options.builder] |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 118 | if desugar: |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 119 | assert options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8 |
| 120 | if options.desugar_jdk11: |
| 121 | builders = [DESUGAR_JDK11_BOT] |
| 122 | elif options.desugar_jdk11_legacy: |
| 123 | builders = [DESUGAR_JDK11_LEGACY_BOT] |
| 124 | else: |
| 125 | builders = [DESUGAR_JDK8_BOT] |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 126 | commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_main=True) |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 127 | if options.cl: |
| 128 | trigger_cl(builders, options.cl) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 129 | else: |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 130 | assert commit |
| 131 | trigger_builders(builders, commit) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 132 | |
| 133 | if __name__ == '__main__': |
| 134 | sys.exit(Main()) |