blob: 24a0c253426adc9ee235d760103f21b31a19de9b [file] [log] [blame]
Eric Boren63765172017-10-16 14:22:47 -04001#!/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
12import argparse
13import json
14import os
15import re
16import subprocess
17import sys
18
19
Eric Borencff9f952017-10-17 09:18:18 -040020BUCKET_SKIA_PRIMARY = 'skia.primary'
Eric Boren63765172017-10-16 14:22:47 -040021CHECKOUT_ROOT = os.path.realpath(os.path.join(
22 os.path.dirname(os.path.abspath(__file__)), os.pardir))
Eric Borencff9f952017-10-17 09:18:18 -040023INFRA_BOTS = os.path.join(CHECKOUT_ROOT, 'infra', 'bots')
24JOBS_JSON = os.path.join(INFRA_BOTS, 'jobs.json')
25
26sys.path.insert(0, INFRA_BOTS)
27
28import update_meta_config
Eric Boren63765172017-10-16 14:22:47 -040029
30
31def 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 Borencff9f952017-10-17 09:18:18 -040041 # Load and filter the list of Skia jobs.
42 jobs = []
Eric Boren63765172017-10-16 14:22:47 -040043 with open(JOBS_JSON) as f:
Eric Borencff9f952017-10-17 09:18:18 -040044 jobs.append((BUCKET_SKIA_PRIMARY, json.load(f)))
45 jobs.extend(update_meta_config.CQ_INCLUDE_CHROMIUM_TRYBOTS)
Eric Boren63765172017-10-16 14:22:47 -040046 if args.job:
Eric Borencff9f952017-10-17 09:18:18 -040047 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 Boren63765172017-10-16 14:22:47 -040053
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 Borencff9f952017-10-17 09:18:18 -040058 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 Boren63765172017-10-16 14:22:47 -040066 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 Borencff9f952017-10-17 09:18:18 -040075 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 Boren63765172017-10-16 14:22:47 -040085
86
87if __name__ == '__main__':
88 main()