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' |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 28 | SMALI_BOT = 'smali' |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 29 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 30 | def ParseOptions(): |
| 31 | result = optparse.OptionParser() |
| 32 | result.add_option('--release', |
| 33 | help='Run on the release branch builders.', |
| 34 | default=False, action='store_true') |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 35 | result.add_option('--cl', |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 36 | metavar=('<url>'), |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 37 | help='Run the specified cl on the bots. This should be ' |
| 38 | 'the full url, e.g., ' |
| 39 | 'https://r8-review.googlesource.com/c/r8/+/37420/1') |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 40 | result.add_option('--desugar-jdk11', |
| 41 | help='Run the jdk11 library desugar and archiving bot.', |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 42 | default=False, action='store_true') |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 43 | result.add_option('--desugar-jdk11-legacy', |
| 44 | help='Run the jdk11 legacy library desugar and archiving bot.', |
| 45 | default=False, action='store_true') |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 46 | result.add_option('--desugar-jdk8', |
| 47 | help='Run the jdk8 library desugar and archiving bot.', |
| 48 | default=False, action='store_true') |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 49 | result.add_option('--smali', |
| 50 | metavar=('<version>'), |
| 51 | help='Build smali version <version>.') |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 52 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 53 | result.add_option('--builder', help='Trigger specific builder') |
| 54 | return result.parse_args() |
| 55 | |
| 56 | def get_builders(): |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 57 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 58 | is_release = False |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 59 | main_builders = [] |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 60 | release_builders = [] |
| 61 | with open(LUCI_SCHEDULE, 'r') as fp: |
| 62 | lines = fp.readlines() |
| 63 | for line in lines: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 64 | if 'branch-gitiles' in line: |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 65 | is_release = True |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 66 | if 'main-gitiles-trigger' in line: |
| 67 | is_release = False |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 68 | match = re.match(TRIGGERS_RE, line) |
| 69 | if match: |
| 70 | builder = match.group(1) |
| 71 | if is_release: |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 72 | assert 'release' in builder, builder |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 73 | release_builders.append(builder) |
| 74 | else: |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 75 | assert 'release' not in builder, builder |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 76 | main_builders.append(builder) |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 77 | print('Desugar jdk11 builder:\n ' + DESUGAR_JDK11_BOT) |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 78 | print('Desugar jdk11 legacy builder:\n ' + DESUGAR_JDK11_LEGACY_BOT) |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 79 | print('Desugar jdk8 builder:\n ' + DESUGAR_JDK8_BOT) |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 80 | print('Smali builder:\n ' + SMALI_BOT) |
Morten Krogh-Jespersen | 6aa4ea3 | 2021-11-02 14:25:56 +0100 | [diff] [blame] | 81 | print('Main builders:\n ' + '\n '.join(main_builders)) |
| 82 | print('Release builders:\n ' + '\n '.join(release_builders)) |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 83 | return (main_builders, release_builders) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 84 | |
| 85 | def sanity_check_url(url): |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 86 | a = urlopen(url) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 87 | if a.getcode() != 200: |
| 88 | raise Exception('Url: %s \n returned %s' % (url, a.getcode())) |
| 89 | |
| 90 | def trigger_builders(builders, commit): |
| 91 | commit_url = 'https://r8.googlesource.com/r8/+/%s' % commit |
| 92 | sanity_check_url(commit_url) |
| 93 | for builder in builders: |
| 94 | cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-commit', commit_url] |
| 95 | subprocess.check_call(cmd) |
| 96 | |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 97 | def trigger_smali_builder(version): |
| 98 | utils.check_basic_semver_version( |
| 99 | version, |
| 100 | 'use semantic version of the smali version to built (pre-releases are not supported)', |
| 101 | allowPrerelease = False) |
| 102 | cmd = [ |
| 103 | 'bb', |
| 104 | 'add', |
| 105 | 'r8/ci/%s' % SMALI_BOT, |
| 106 | '-p', |
Søren Gjesse | dab0e8f | 2023-04-26 11:10:40 +0200 | [diff] [blame] | 107 | 'test_options=["--version", "%s"]' % version |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 108 | ] |
| 109 | subprocess.check_call(cmd) |
| 110 | |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 111 | def trigger_cl(builders, cl_url): |
| 112 | for builder in builders: |
| 113 | cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-cl', cl_url] |
| 114 | subprocess.check_call(cmd) |
| 115 | |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 116 | def Main(): |
| 117 | (options, args) = ParseOptions() |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 118 | desugar = options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8 |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 119 | requires_commit = not options.cl and not desugar and not options.smali |
| 120 | if len(args) != 1 and requires_commit: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 121 | print('Takes exactly one argument, the commit to run') |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 122 | return 1 |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 123 | |
| 124 | if options.cl and options.release: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 125 | print('You can\'t run cls on the release bots') |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 126 | return 1 |
| 127 | |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 128 | if options.cl and desugar: |
Rico Wind | b12a44a | 2022-03-31 12:17:00 +0200 | [diff] [blame] | 129 | print('You can\'t run cls on the desugar bot') |
Rico Wind | 1cd21b0 | 2019-08-14 13:26:21 +0200 | [diff] [blame] | 130 | return 1 |
| 131 | |
Søren Gjesse | ceb85a8 | 2023-04-26 09:58:03 +0200 | [diff] [blame] | 132 | if options.cl and options.smali: |
| 133 | print('You can\'t run cls on the smali bot') |
| 134 | return 1 |
| 135 | |
| 136 | if options.smali: |
| 137 | if not options.release: |
| 138 | print('Only release versions of smali can be built') |
| 139 | return 1 |
| 140 | |
| 141 | trigger_smali_builder(options.smali) |
| 142 | return |
| 143 | |
| 144 | commit = None if not requires_commit else args[0] |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 145 | (main_builders, release_builders) = get_builders() |
| 146 | builders = release_builders if options.release else main_builders |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 147 | if options.builder: |
| 148 | builder = options.builder |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 149 | assert builder in main_builders or builder in release_builders |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 150 | builders = [options.builder] |
Rico Wind | 8cc810a | 2022-06-24 09:33:34 +0200 | [diff] [blame] | 151 | if desugar: |
Søren Gjesse | f637d9d | 2022-08-24 15:32:55 +0200 | [diff] [blame] | 152 | assert options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8 |
| 153 | if options.desugar_jdk11: |
| 154 | builders = [DESUGAR_JDK11_BOT] |
| 155 | elif options.desugar_jdk11_legacy: |
| 156 | builders = [DESUGAR_JDK11_LEGACY_BOT] |
| 157 | else: |
| 158 | builders = [DESUGAR_JDK8_BOT] |
Rico Wind | 1b52acf | 2021-03-21 12:36:55 +0100 | [diff] [blame] | 159 | commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_main=True) |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 160 | if options.cl: |
| 161 | trigger_cl(builders, options.cl) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 162 | else: |
Rico Wind | e11f71d | 2019-04-24 13:18:15 +0200 | [diff] [blame] | 163 | assert commit |
| 164 | trigger_builders(builders, commit) |
Rico Wind | b873c64 | 2019-04-15 11:07:39 +0200 | [diff] [blame] | 165 | |
| 166 | if __name__ == '__main__': |
| 167 | sys.exit(Main()) |