From d1835e98afa83598e12b8944c2ceeb64d0adf79c Mon Sep 17 00:00:00 2001 From: Andrew Ferlitsch Date: Tue, 14 Nov 2023 16:00:31 -0800 Subject: [PATCH] feat: auto find latest build results (#2517) --- .cloud-build/utils/build_results_viewer.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.cloud-build/utils/build_results_viewer.py b/.cloud-build/utils/build_results_viewer.py index 6715f0466..4618752fc 100644 --- a/.cloud-build/utils/build_results_viewer.py +++ b/.cloud-build/utils/build_results_viewer.py @@ -7,11 +7,16 @@ import argparse import json from util import download_file import csv +import datetime +from google.cloud import storage + +BUILD_BUCKET = "cloud-build-notebooks-presubmit" +BUILD_FOLDER = "build_results" parser = argparse.ArgumentParser() parser.add_argument('--file', dest='file', - default='build.json', type=str, help='build results file') + default=None, type=str, help='build results filei (local or GCS)') args = parser.parse_args() investigate = {} @@ -20,6 +25,19 @@ with open('investigate.csv', 'r') as csvfile: for row in reader: investigate[row[0][:-6]] = row[1] +if not args.file: + client = storage.Client() + blobs = client.list_blobs(BUILD_BUCKET, prefix=BUILD_FOLDER) + newest_time = datetime.datetime(2000, 1, 1) + for blob in blobs: + # individual PR + if blob.size < 2000: + continue + time_created = blob.time_created.replace(tzinfo=None) + if time_created > newest_time: + newest_time = time_created + args.file = f"gs://{BUILD_BUCKET}/{blob.name}" + if args.file.startswith("gs://"): path = args.file[5:] bucket = path.split('/')[0]