Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #!/usr/bin/env python | |
| 2 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | |
| 3 # Use of this source code is governed by a BSD-style license that can be | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Tool for scheduling builds on Buildbucket. | |
|
sheyang
2015/06/08 22:02:13
I guess there'll be a follow-up CL to make "git cl
smut
2015/06/08 22:16:46
Potentially.
| |
| 7 | |
| 8 Usage: | |
| 9 $ depot-tools-auth login https://cr-buildbucket.appspot.com | |
| 10 $ buildbucket.py \ | |
| 11 --builder my-builder \ | |
| 12 --bucket master.chromium.tryserver.linux \ | |
|
sheyang
2015/06/08 22:02:13
master.tryserver.chromium.linux
smut
2015/06/08 22:16:46
Done.
| |
| 13 | |
| 14 Schedules a build on buildbucket for my-builder on chromium.tryserver.linux. | |
| 15 """ | |
| 16 | |
| 17 import argparse | |
| 18 import json | |
| 19 import urlparse | |
| 20 import os | |
| 21 import sys | |
| 22 | |
| 23 from third_party import httplib2 | |
| 24 | |
| 25 import auth | |
| 26 | |
| 27 | |
| 28 BUILDBUCKET_URL = 'https://cr-buildbucket.appspot.com' | |
| 29 PUT_BUILD_URL = urlparse.urljoin( | |
| 30 BUILDBUCKET_URL, | |
| 31 '_ah/api/buildbucket/v1/builds', | |
| 32 ) | |
| 33 | |
| 34 | |
| 35 def main(argv): | |
| 36 parser = argparse.ArgumentParser() | |
|
nodir
2015/06/08 21:46:15
Please make it
buildbucket put --bucket .....
in
smut
2015/06/08 22:16:47
Done.
| |
| 37 parser.add_argument( | |
| 38 '-m', | |
|
sheyang
2015/06/08 22:02:13
The combination ('-m' and '--bucket') seems strang
smut
2015/06/08 22:16:46
-m for master because -b was taken. added --master
| |
| 39 '--bucket', | |
| 40 help='The bucket to schedule the build on. Typically the master name.', | |
|
sheyang
2015/06/08 22:02:13
I would give an example such as 'master.tryserver.
smut
2015/06/08 22:16:47
Done.
| |
| 41 required=True, | |
| 42 ) | |
| 43 parser.add_argument( | |
| 44 '-b', | |
| 45 '--builder-name', | |
| 46 help='The builder to schedule the build on.', | |
| 47 required=True, | |
| 48 ) | |
| 49 parser.add_argument( | |
| 50 '-p', | |
| 51 '--properties', | |
| 52 help='A file to load a JSON dict of properties from.', | |
| 53 ) | |
| 54 parser.add_argument( | |
| 55 '-v', | |
| 56 '--verbose', | |
| 57 action='store_true', | |
| 58 ) | |
| 59 args = parser.parse_args() | |
| 60 | |
| 61 properties = { | |
| 62 'category': os.path.basename(argv[0]), | |
| 63 'reason': os.path.basename(argv[0]), | |
|
nodir
2015/06/08 21:46:15
"buildbucket.py" is not a good category or reason.
smut
2015/06/08 22:16:46
I've seen "CQ" as the category and reason, so I th
| |
| 64 } | |
| 65 if args.properties: | |
| 66 with open(args.properties) as fp: | |
| 67 properties.update(json.load(fp)) | |
|
nodir
2015/06/08 21:46:15
Add exception handling with meaningful explanation
smut
2015/06/08 22:16:46
Exception is pretty clear:
ValueError: No JSON obj
| |
| 68 | |
| 69 authenticator = auth.get_authenticator_for_host( | |
| 70 BUILDBUCKET_URL, | |
| 71 auth.make_auth_config(use_oauth2=True), | |
| 72 ) | |
| 73 http = authenticator.authorize(httplib2.Http()) | |
| 74 http.force_exception_to_status_code = True | |
| 75 response, content = http.request( | |
| 76 PUT_BUILD_URL, | |
| 77 'PUT', | |
| 78 body=json.dumps({ | |
| 79 'bucket': args.bucket, | |
| 80 'parameters_json': json.dumps({ | |
| 81 'builder_name': args.builder_name, | |
| 82 'properties': properties, | |
| 83 }), | |
| 84 }), | |
| 85 headers={'Content-Type': 'application/json'}, | |
| 86 ) | |
| 87 | |
| 88 if args.verbose: | |
| 89 print content | |
| 90 | |
| 91 return response.status != 200 | |
|
nodir
2015/06/08 21:46:15
It should return an int, not boolean, no?
smut
2015/06/08 22:16:46
Doesn't really matter. int(False) is 0, int(True)
| |
| 92 | |
| 93 | |
| 94 if __name__ == '__main__': | |
| 95 sys.exit(main(sys.argv)) | |
| OLD | NEW |