blob: d716a55371474c412e680b4a8404aae8a3ca8fe6 [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Rico Windb873c642019-04-15 11:07:39 +02002# 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
8import json
Rico Wind1cd21b02019-08-14 13:26:21 +02009import git_utils
Rico Windb873c642019-04-15 11:07:39 +020010import optparse
11import os
12import re
13import subprocess
14import sys
15import urllib
Rico Windb12a44a2022-03-31 12:17:00 +020016from urllib.request import urlopen
Rico Windb873c642019-04-15 11:07:39 +020017import utils
18
19LUCI_SCHEDULE = os.path.join(utils.REPO_ROOT, 'infra', 'config', 'global',
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010020 'generated', 'luci-scheduler.cfg')
Rico Windb873c642019-04-15 11:07:39 +020021# Trigger lines have the format:
22# triggers: "BUILDER_NAME"
23TRIGGERS_RE = r'^ triggers: "(\w.*)"'
24
Rico Wind8cc810a2022-06-24 09:33:34 +020025DESUGAR_JDK11_BOT = 'lib_desugar-archive-jdk11'
Søren Gjessef637d9d2022-08-24 15:32:55 +020026DESUGAR_JDK11_LEGACY_BOT = 'lib_desugar-archive-jdk11-legacy'
Søren Gjesse45c70382022-06-24 10:37:07 +020027DESUGAR_JDK8_BOT = 'lib_desugar-archive-jdk8'
Rico Wind1cd21b02019-08-14 13:26:21 +020028
Rico Windb873c642019-04-15 11:07:39 +020029def 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 Winde11f71d2019-04-24 13:18:15 +020034 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 Wind8cc810a2022-06-24 09:33:34 +020038 result.add_option('--desugar-jdk11',
39 help='Run the jdk11 library desugar and archiving bot.',
Rico Wind1cd21b02019-08-14 13:26:21 +020040 default=False, action='store_true')
Søren Gjessef637d9d2022-08-24 15:32:55 +020041 result.add_option('--desugar-jdk11-legacy',
42 help='Run the jdk11 legacy library desugar and archiving bot.',
43 default=False, action='store_true')
Rico Wind8cc810a2022-06-24 09:33:34 +020044 result.add_option('--desugar-jdk8',
45 help='Run the jdk8 library desugar and archiving bot.',
46 default=False, action='store_true')
47
Rico Windb873c642019-04-15 11:07:39 +020048 result.add_option('--builder', help='Trigger specific builder')
49 return result.parse_args()
50
51def get_builders():
Rico Wind1cd21b02019-08-14 13:26:21 +020052
Rico Windb873c642019-04-15 11:07:39 +020053 is_release = False
Rico Wind1b52acf2021-03-21 12:36:55 +010054 main_builders = []
Rico Windb873c642019-04-15 11:07:39 +020055 release_builders = []
56 with open(LUCI_SCHEDULE, 'r') as fp:
57 lines = fp.readlines()
58 for line in lines:
Rico Windb12a44a2022-03-31 12:17:00 +020059 if 'branch-gitiles' in line:
Rico Windb873c642019-04-15 11:07:39 +020060 is_release = True
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010061 if 'main-gitiles-trigger' in line:
62 is_release = False
Rico Windb873c642019-04-15 11:07:39 +020063 match = re.match(TRIGGERS_RE, line)
64 if match:
65 builder = match.group(1)
66 if is_release:
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010067 assert 'release' in builder, builder
Rico Windb873c642019-04-15 11:07:39 +020068 release_builders.append(builder)
69 else:
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010070 assert 'release' not in builder, builder
Rico Wind1b52acf2021-03-21 12:36:55 +010071 main_builders.append(builder)
Rico Wind8cc810a2022-06-24 09:33:34 +020072 print('Desugar jdk11 builder:\n ' + DESUGAR_JDK11_BOT)
Søren Gjessef637d9d2022-08-24 15:32:55 +020073 print('Desugar jdk11 legacy builder:\n ' + DESUGAR_JDK11_LEGACY_BOT)
Rico Wind8cc810a2022-06-24 09:33:34 +020074 print('Desugar jdk8 builder:\n ' + DESUGAR_JDK8_BOT)
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010075 print('Main builders:\n ' + '\n '.join(main_builders))
76 print('Release builders:\n ' + '\n '.join(release_builders))
Rico Wind1b52acf2021-03-21 12:36:55 +010077 return (main_builders, release_builders)
Rico Windb873c642019-04-15 11:07:39 +020078
79def sanity_check_url(url):
Rico Windb12a44a2022-03-31 12:17:00 +020080 a = urlopen(url)
Rico Windb873c642019-04-15 11:07:39 +020081 if a.getcode() != 200:
82 raise Exception('Url: %s \n returned %s' % (url, a.getcode()))
83
84def 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 Winde11f71d2019-04-24 13:18:15 +020091def 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 Windb873c642019-04-15 11:07:39 +020096def Main():
97 (options, args) = ParseOptions()
Søren Gjessef637d9d2022-08-24 15:32:55 +020098 desugar = options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8
Rico Wind8cc810a2022-06-24 09:33:34 +020099 if len(args) != 1 and not options.cl and not desugar:
Rico Windb12a44a2022-03-31 12:17:00 +0200100 print('Takes exactly one argument, the commit to run')
Rico Windb873c642019-04-15 11:07:39 +0200101 return 1
Rico Winde11f71d2019-04-24 13:18:15 +0200102
103 if options.cl and options.release:
Rico Windb12a44a2022-03-31 12:17:00 +0200104 print('You can\'t run cls on the release bots')
Rico Winde11f71d2019-04-24 13:18:15 +0200105 return 1
106
Rico Wind8cc810a2022-06-24 09:33:34 +0200107 if options.cl and desugar:
Rico Windb12a44a2022-03-31 12:17:00 +0200108 print('You can\'t run cls on the desugar bot')
Rico Wind1cd21b02019-08-14 13:26:21 +0200109 return 1
110
Rico Wind8cc810a2022-06-24 09:33:34 +0200111 commit = None if (options.cl or desugar) else args[0]
Rico Wind1b52acf2021-03-21 12:36:55 +0100112 (main_builders, release_builders) = get_builders()
113 builders = release_builders if options.release else main_builders
Rico Windb873c642019-04-15 11:07:39 +0200114 if options.builder:
115 builder = options.builder
Rico Wind1b52acf2021-03-21 12:36:55 +0100116 assert builder in main_builders or builder in release_builders
Rico Winde11f71d2019-04-24 13:18:15 +0200117 builders = [options.builder]
Rico Wind8cc810a2022-06-24 09:33:34 +0200118 if desugar:
Søren Gjessef637d9d2022-08-24 15:32:55 +0200119 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 Wind1b52acf2021-03-21 12:36:55 +0100126 commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_main=True)
Rico Winde11f71d2019-04-24 13:18:15 +0200127 if options.cl:
128 trigger_cl(builders, options.cl)
Rico Windb873c642019-04-15 11:07:39 +0200129 else:
Rico Winde11f71d2019-04-24 13:18:15 +0200130 assert commit
131 trigger_builders(builders, commit)
Rico Windb873c642019-04-15 11:07:39 +0200132
133if __name__ == '__main__':
134 sys.exit(Main())