2017-03-11 01:37:19 +00:00
|
|
|
#!/usr/bin/python2
|
|
|
|
"""Waits for project build on Google Cloud Builder.
|
|
|
|
|
|
|
|
Usage: wait_for_build.py <build_id>
|
|
|
|
"""
|
|
|
|
|
2017-03-22 19:07:36 +00:00
|
|
|
import argparse
|
2017-03-11 01:37:19 +00:00
|
|
|
import sys
|
|
|
|
import time
|
2017-03-14 00:03:07 +00:00
|
|
|
import datetime
|
2017-03-11 01:37:19 +00:00
|
|
|
|
|
|
|
from googleapiclient.discovery import build
|
|
|
|
from oauth2client.client import GoogleCredentials
|
|
|
|
|
|
|
|
POLL_INTERVAL = 15
|
2017-03-14 00:03:07 +00:00
|
|
|
cloudbuild = None
|
2017-03-11 01:37:19 +00:00
|
|
|
|
|
|
|
|
2017-03-22 19:07:36 +00:00
|
|
|
def get_build(build_id, cloudbuild, project):
|
2017-03-14 00:03:07 +00:00
|
|
|
return cloudbuild.projects().builds().get(
|
2017-03-22 19:07:36 +00:00
|
|
|
projectId=project, id=build_id).execute()
|
2017-03-11 01:37:19 +00:00
|
|
|
|
|
|
|
|
2017-03-22 19:07:36 +00:00
|
|
|
def wait_for_build(build_id, project):
|
2017-03-16 01:57:58 +00:00
|
|
|
DONE_STATUSES = [
|
|
|
|
'SUCCESS',
|
|
|
|
'FAILURE',
|
|
|
|
'INTERNAL_ERROR',
|
|
|
|
'CANCELLED',
|
2017-07-19 15:56:18 +00:00
|
|
|
'TIMEOUT',
|
2017-03-16 01:57:58 +00:00
|
|
|
]
|
2017-03-11 01:37:19 +00:00
|
|
|
|
2017-03-14 00:03:07 +00:00
|
|
|
status = None
|
2017-03-11 01:37:19 +00:00
|
|
|
while True:
|
2017-03-22 19:07:36 +00:00
|
|
|
build_info = get_build(build_id, cloudbuild, project)
|
2017-03-14 00:12:20 +00:00
|
|
|
|
2017-03-14 00:03:07 +00:00
|
|
|
current_status = build_info['status']
|
|
|
|
if current_status != status:
|
2018-07-27 03:32:09 +00:00
|
|
|
print datetime.datetime.now(), current_status
|
|
|
|
sys.stdout.flush()
|
2017-03-14 00:03:07 +00:00
|
|
|
status = current_status
|
2017-03-16 01:57:58 +00:00
|
|
|
if status in DONE_STATUSES:
|
2017-03-14 00:03:07 +00:00
|
|
|
return status == 'SUCCESS'
|
|
|
|
|
2017-03-11 01:37:19 +00:00
|
|
|
time.sleep(POLL_INTERVAL)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2017-03-14 00:03:07 +00:00
|
|
|
global cloudbuild
|
|
|
|
|
2017-03-22 19:07:36 +00:00
|
|
|
parser = argparse.ArgumentParser(description='Wait for build to complete')
|
|
|
|
parser.add_argument(
|
2018-07-27 03:32:09 +00:00
|
|
|
'-p', '--project', help='Cloud Project', default='oss-fuzz')
|
2017-03-22 19:07:36 +00:00
|
|
|
parser.add_argument('build_id', help='The Container Builder build ID.')
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
2017-03-11 01:37:19 +00:00
|
|
|
|
2017-03-14 00:03:07 +00:00
|
|
|
credentials = GoogleCredentials.get_application_default()
|
|
|
|
cloudbuild = build('cloudbuild', 'v1', credentials=credentials)
|
2017-03-11 01:37:19 +00:00
|
|
|
|
2017-03-22 19:07:36 +00:00
|
|
|
success = wait_for_build(args.build_id, args.project)
|
2017-03-11 01:37:19 +00:00
|
|
|
|
2017-03-14 00:03:07 +00:00
|
|
|
if not success:
|
2017-03-11 01:37:19 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
|
2017-03-22 19:07:36 +00:00
|
|
|
if __name__ == '__main__':
|
2017-03-11 01:37:19 +00:00
|
|
|
main()
|