Skip to content

Commit 0916bda

Browse files
committed
CI: compress result.json files
1 parent 072a30b commit 0916bda

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

ci/praktika/result.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,10 +535,33 @@ class _ResultS3:
535535
def copy_result_to_s3(cls, result, clean=False):
536536
result.dump()
537537
env = _Environment.get()
538-
s3_path = f"{Settings.HTML_S3_PATH}/{env.get_s3_prefix()}"
538+
result_file_path = result.file_name()
539+
s3_path = f"{Settings.HTML_S3_PATH}/{env.get_s3_prefix()}/{Path(result_file_path).name}"
539540
if clean:
540541
S3.delete(s3_path)
541-
url = S3.copy_file_to_s3(s3_path=s3_path, local_path=result.file_name())
542+
archive_file = Utils.compress_file(result_file_path, no_strict=True)
543+
archive_type = archive_file.split(".")[-1]
544+
content_encoding = ""
545+
if archive_type == "gz":
546+
content_encoding = "gzip"
547+
elif archive_type == "zst":
548+
content_encoding = "zstd"
549+
elif archive_type == "br":
550+
content_encoding = "br"
551+
else:
552+
if archive_type:
553+
print(
554+
f"WARNING: Not supported compress codec: [{archive_type}] - skip compress"
555+
)
556+
archive_file = result_file_path
557+
558+
url = S3.copy_file_to_s3(
559+
s3_path=s3_path,
560+
local_path=archive_file,
561+
text=True,
562+
content_encoding=content_encoding,
563+
with_rename=True,
564+
)
542565
return url
543566

544567
@classmethod

ci/praktika/utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def compress_file_zst(cls, path):
627627
return path_out
628628

629629
@classmethod
630-
def compress_file(cls, path):
630+
def compress_file(cls, path, no_strict=False):
631631
if Shell.check("which zstd"):
632632
return cls.compress_file_zst(path)
633633
elif Shell.check("which pigz"):
@@ -646,9 +646,10 @@ def compress_file(cls, path):
646646
)
647647
else:
648648
path_out = path
649-
Utils.raise_with_error(
650-
f"Failed to compress file [{path}] no zstd or gz installed"
651-
)
649+
if not no_strict:
650+
raise RuntimeError(
651+
f"Failed to compress file [{path}] no zstd or gz installed"
652+
)
652653
return path_out
653654

654655
@classmethod

0 commit comments

Comments
 (0)