Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Copyright 2017 Google Inc. |
| 4 | # |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
| 8 | |
| 9 | """Submit one or more try jobs.""" |
| 10 | |
| 11 | |
| 12 | import argparse |
| 13 | import json |
| 14 | import os |
| 15 | import re |
| 16 | import subprocess |
| 17 | import sys |
| 18 | |
| 19 | |
Eric Boren | cff9f95 | 2017-10-17 09:18:18 -0400 | [diff] [blame^] | 20 | BUCKET_SKIA_PRIMARY = 'skia.primary' |
Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 21 | CHECKOUT_ROOT = os.path.realpath(os.path.join( |
| 22 | os.path.dirname(os.path.abspath(__file__)), os.pardir)) |
Eric Boren | cff9f95 | 2017-10-17 09:18:18 -0400 | [diff] [blame^] | 23 | INFRA_BOTS = os.path.join(CHECKOUT_ROOT, 'infra', 'bots') |
| 24 | JOBS_JSON = os.path.join(INFRA_BOTS, 'jobs.json') |
| 25 | |
| 26 | sys.path.insert(0, INFRA_BOTS) |
| 27 | |
| 28 | import update_meta_config |
Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 29 | |
| 30 | |
| 31 | def main(): |
| 32 | # Parse arguments. |
| 33 | d = 'Helper script for triggering try jobs defined in %s.' % JOBS_JSON |
| 34 | parser = argparse.ArgumentParser(description=d) |
| 35 | parser.add_argument('--list', action='store_true', default=False, |
| 36 | help='Just list the jobs; do not trigger anything.') |
| 37 | parser.add_argument('job', nargs='?', default=None, |
| 38 | help='Job name or regular expression to match job names.') |
| 39 | args = parser.parse_args() |
| 40 | |
Eric Boren | cff9f95 | 2017-10-17 09:18:18 -0400 | [diff] [blame^] | 41 | # Load and filter the list of Skia jobs. |
| 42 | jobs = [] |
Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 43 | with open(JOBS_JSON) as f: |
Eric Boren | cff9f95 | 2017-10-17 09:18:18 -0400 | [diff] [blame^] | 44 | jobs.append((BUCKET_SKIA_PRIMARY, json.load(f))) |
| 45 | jobs.extend(update_meta_config.CQ_INCLUDE_CHROMIUM_TRYBOTS) |
Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 46 | if args.job: |
Eric Boren | cff9f95 | 2017-10-17 09:18:18 -0400 | [diff] [blame^] | 47 | new_jobs = [] |
| 48 | for bucket, job_list in jobs: |
| 49 | filtered = [j for j in job_list if re.search(args.job, j)] |
| 50 | if len(filtered) > 0: |
| 51 | new_jobs.append((bucket, filtered)) |
| 52 | jobs = new_jobs |
Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 53 | |
| 54 | # Display the list of jobs. |
| 55 | if len(jobs) == 0: |
| 56 | print 'Found no jobs matching "%s"' % repr(args.job) |
| 57 | sys.exit(1) |
Eric Boren | cff9f95 | 2017-10-17 09:18:18 -0400 | [diff] [blame^] | 58 | count = 0 |
| 59 | for bucket, job_list in jobs: |
| 60 | count += len(job_list) |
| 61 | print 'Found %d jobs:' % count |
| 62 | for bucket, job_list in jobs: |
| 63 | print ' %s:' % bucket |
| 64 | for j in job_list: |
| 65 | print ' %s' % j |
Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 66 | if args.list: |
| 67 | return |
| 68 | |
| 69 | # Prompt before triggering jobs. |
| 70 | resp = raw_input('\nDo you want to trigger these jobs? (y/n) ') |
| 71 | if resp != 'y': |
| 72 | sys.exit(1) |
| 73 | |
| 74 | # Trigger the try jobs. |
Eric Boren | cff9f95 | 2017-10-17 09:18:18 -0400 | [diff] [blame^] | 75 | for bucket, job_list in jobs: |
| 76 | cmd = ['git', 'cl', 'try', '-B', bucket] |
| 77 | for j in job_list: |
| 78 | cmd.extend(['-b', j]) |
| 79 | try: |
| 80 | subprocess.check_call(cmd) |
| 81 | except subprocess.CalledProcessError: |
| 82 | # Output from the command will fall through, so just exit here rather than |
| 83 | # printing a stack trace. |
| 84 | sys.exit(1) |
Eric Boren | 6376517 | 2017-10-16 14:22:47 -0400 | [diff] [blame] | 85 | |
| 86 | |
| 87 | if __name__ == '__main__': |
| 88 | main() |