diff --git a/tools/stats/upload_stats_lib.py b/tools/stats/upload_stats_lib.py index 34548b80d76ba..959d49b80767f 100644 --- a/tools/stats/upload_stats_lib.py +++ b/tools/stats/upload_stats_lib.py @@ -104,14 +104,16 @@ def download_s3_artifacts( paths = [] for obj in objs: object_name = Path(obj.key).name - # target an artifact for a specific job_id if provided, otherwise skip the download. if job_id is not None and str(job_id) not in object_name: continue found_one = True p = Path(Path(obj.key).name) print(f"Downloading {p}") + s3_resource = get_s3_resource() + bucket_obj = s3_resource.Bucket(GHA_ARTIFACTS_BUCKET) + obj_data = bucket_obj.Object(obj.key).get() with open(p, "wb") as f: - f.write(obj.get()["Body"].read()) + f.write(obj_data["Body"].read()) paths.append(p) if not found_one: @@ -161,10 +163,8 @@ def upload_to_s3( json.dump(doc, body) body.write("\n") - get_s3_resource().Object( - f"{bucket_name}", - f"{key}", - ).put( + s3_obj = get_s3_resource().Object(f"{bucket_name}", f"{key}") + s3_obj.put( Body=gzip.compress(body.getvalue().encode()), ContentEncoding="gzip", ContentType="application/json", @@ -186,7 +186,8 @@ def read_from_s3( .get()["Body"] .read() ) - results = gzip.decompress(body).decode().split("\n") + decompressed = gzip.decompress(body).decode() + results = decompressed.split("\n") return [json.loads(result) for result in results if result] diff --git a/tools/stats/upload_test_stats.py b/tools/stats/upload_test_stats.py index 45a390fc5051d..262dd0ab7f2f6 100644 --- a/tools/stats/upload_test_stats.py +++ b/tools/stats/upload_test_stats.py @@ -170,6 +170,8 @@ def summarize_test_cases(test_cases: list[dict[str, Any]]) -> list[dict[str, Any manually instead of using the `test-suite` XML tag because xmlrunner does not produce reliable output for it. """ + + test_cases = sorted(test_cases, key=lambda x: (x.get("file", ""), x.get("classname", ""))) def get_key(test_case: dict[str, Any]) -> Any: return (