From 8722635c710c5ece43b4c51767de3a4fe68b0f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Kwiecin=CC=81ski?= Date: Wed, 6 Mar 2024 22:10:48 +0700 Subject: [PATCH] Trying to fix windows encoding --- entrypoint.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/entrypoint.py b/entrypoint.py index 5f34422..2c3399a 100644 --- a/entrypoint.py +++ b/entrypoint.py @@ -144,6 +144,9 @@ def sizeof_fmt(num, suffix='B', sign=False): exec_call.extend(["--old-mapping", os.getenv("INPUT_OLD_MAPPING_FILE")]) if os.getenv("INPUT_NEW_MAPPING_FILE").strip(): exec_call.extend(["--new-mapping", os.getenv("INPUT_NEW_MAPPING_FILE")]) +exec_call.append("--text") +output_file_name = "diffuse-output.txt" +exec_call.append(output_file_name) oldSize = os.stat(oldFile).st_size oldSizeText = sizeof_fmt(oldSize) @@ -158,21 +161,27 @@ def sizeof_fmt(num, suffix='B', sign=False): print(diffComment1) print(" ".join(exec_call)) -os.system(f"echo \"size-old-bytes={oldSize}\" >> $GITHUB_OUTPUT") -os.system(f"echo \"size-old-text={oldSizeText}\" >> $GITHUB_OUTPUT") -os.system(f"echo \"size-new-bytes={newSize}\" >> $GITHUB_OUTPUT") -os.system(f"echo \"size-new-text={newSizeText}\" >> $GITHUB_OUTPUT") -os.system(f"echo \"size-diff-comment_style_1={diffComment1}\" >> $GITHUB_OUTPUT") +github_output("size-old-bytes", oldSize) +github_output("size-old-text", oldSizeText) +github_output("size-new-bytes", newSize) +github_output("size-new-text", newSizeText) +github_output("size-diff-comment_style_1", diffComment1) -process = subprocess.Popen(exec_call, stdout=subprocess.PIPE) -out, _ = process.communicate() -diff = out.decode(encoding=sys.stdout.encoding).strip() +process = subprocess.run(exec_call) +if process.returncode != 0: + raise Exception("Error while executing diffuse") + +with open(output_file_name, mode="r", encoding="utf-8") as output: + outputPath = os.path.realpath(output.name) + diff = output.read().encode('utf-8') if process.returncode != 0: raise Exception("Error while executing diffuse") if is_debug(): + print(f"Encoding: {sys.stdout.encoding}") + print(f"Diff preview: {diff[0:200]}") print(f"Diff size: {len(diff)}") headerPattern = re.compile('=+\\s=+\\s+(\\w+)\\s+=+\\s=*\\s') @@ -180,6 +189,7 @@ def sizeof_fmt(num, suffix='B', sign=False): if is_debug(): print(f"Found {len(sections)} sections") + print(f"Full output stored in: {outputPath}") github_comment = "" github_comment_all_collapsed = "" @@ -206,13 +216,6 @@ def sizeof_fmt(num, suffix='B', sign=False): github_comment_no_dex += section(title.strip(), value) github_comment_no_dex_all_collapsed += section(title.strip(), value) -output = open("diffuse-output.txt", "w") -output.write(diff) -output.close() -outputPath = os.path.realpath(output.name) -if is_debug(): - print(f"Full output stored in: {outputPath}") - github_output("diff-file", outputPath) github_output("diff-raw", diff[0:github_output_limit]) github_output("diff-gh-comment", github_comment)