aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/try.py
blob: a5dc3782554abe09868e80a4065c53d20e49afeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python

# Copyright 2017 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.


"""Submit one or more try jobs."""


import argparse
import json
import os
import re
import subprocess
import sys


BUCKET = 'skia.primary'
CHECKOUT_ROOT = os.path.realpath(os.path.join(
    os.path.dirname(os.path.abspath(__file__)), os.pardir))
JOBS_JSON = os.path.join(CHECKOUT_ROOT, 'infra', 'bots', 'jobs.json')


def main():
  # Parse arguments.
  d = 'Helper script for triggering try jobs defined in %s.' % JOBS_JSON
  parser = argparse.ArgumentParser(description=d)
  parser.add_argument('--list', action='store_true', default=False,
                      help='Just list the jobs; do not trigger anything.')
  parser.add_argument('job', nargs='?', default=None,
                      help='Job name or regular expression to match job names.')
  args = parser.parse_args()

  # Load and filter the list of jobs.
  with open(JOBS_JSON) as f:
    jobs = json.load(f)
  if args.job:
    jobs = [j for j in jobs if re.search(args.job, j)]

  # Display the list of jobs.
  if len(jobs) == 0:
    print 'Found no jobs matching "%s"' % repr(args.job)
    sys.exit(1)
  print 'Found %d jobs:' % len(jobs)
  for j in jobs:
    print '  %s' % j
  if args.list:
    return

  # Prompt before triggering jobs.
  resp = raw_input('\nDo you want to trigger these jobs? (y/n) ')
  if resp != 'y':
    sys.exit(1)

  # Trigger the try jobs.
  cmd = ['git', 'cl', 'try', '-B', BUCKET]
  for j in jobs:
    cmd.extend(['-b', j])
  try:
    subprocess.check_call(cmd)
  except subprocess.CalledProcessError:
    # Output from the command will fall through, so just exit here rather than
    # printing a stack trace.
    sys.exit(1)


if __name__ == '__main__':
  main()