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