From cdbf4636cb600e251e50f6c2e8c233747adc1cb8 Mon Sep 17 00:00:00 2001 From: Azimjon Ulmasov Date: Tue, 5 Aug 2025 15:56:24 -0400 Subject: [PATCH 1/4] shellcheck_run_steps.py: add architecture variety to the melange compile portion to prevent architecture specific packages to fail Signed-off-by: Azimjon Ulmasov --- pre_commit_hooks/shellcheck_run_steps.py | 53 +++++++++++++++++------- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/pre_commit_hooks/shellcheck_run_steps.py b/pre_commit_hooks/shellcheck_run_steps.py index 35b0c0f..d03e431 100644 --- a/pre_commit_hooks/shellcheck_run_steps.py +++ b/pre_commit_hooks/shellcheck_run_steps.py @@ -109,20 +109,45 @@ def main(argv: Sequence[str] | None = None) -> int: "w", delete_on_close=False, ) as compiled_out: - subprocess.check_call( - [ - "docker", - "run", - f"--volume={os.getcwd()}:/work", - "--rm", - MelangeImage, - "compile", - f"--arch={os.uname().machine}", - "--pipeline-dir=./pipelines", - filename, - ], - stdout=compiled_out, - ) + # Try multiple architectures + architectures = list(dict.fromkeys([os.uname().machine, 'x86_64', 'aarch64'])) + compilation_succeeded = False + + for i, arch in enumerate(architectures): + try: + subprocess.run( + [ + "docker", + "run", + f"--volume={os.getcwd()}:/work", + "--rm", + MelangeImage, + "compile", + f"--arch={arch}", + "--pipeline-dir=./pipelines", + filename, + ], + stdout=compiled_out, + stderr=subprocess.PIPE, + check=True, + text=True + ) + compilation_succeeded = True + break # Success, exit the architecture loop + except subprocess.CalledProcessError as e: + if i < len(architectures) - 1: + # Reset the file for the next attempt + compiled_out.seek(0) + compiled_out.truncate() + continue + else: + # Last architecture failed, propagate the error + raise + + if not compilation_succeeded: + fail_cnt += 1 + continue + compiled_out.close() try: with open(compiled_out.name) as compiled_in: From cdaf3eb746b970dd6676dd1e82ac756c526a1511 Mon Sep 17 00:00:00 2001 From: Azimjon Ulmasov Date: Tue, 5 Aug 2025 16:06:59 -0400 Subject: [PATCH 2/4] lint update Signed-off-by: Azimjon Ulmasov --- pre_commit_hooks/shellcheck_run_steps.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pre_commit_hooks/shellcheck_run_steps.py b/pre_commit_hooks/shellcheck_run_steps.py index d03e431..500691a 100644 --- a/pre_commit_hooks/shellcheck_run_steps.py +++ b/pre_commit_hooks/shellcheck_run_steps.py @@ -110,7 +110,9 @@ def main(argv: Sequence[str] | None = None) -> int: delete_on_close=False, ) as compiled_out: # Try multiple architectures - architectures = list(dict.fromkeys([os.uname().machine, 'x86_64', 'aarch64'])) + architectures = list( + dict.fromkeys([os.uname().machine, "x86_64", "aarch64"]), + ) compilation_succeeded = False for i, arch in enumerate(architectures): @@ -130,12 +132,12 @@ def main(argv: Sequence[str] | None = None) -> int: stdout=compiled_out, stderr=subprocess.PIPE, check=True, - text=True + text=True, ) compilation_succeeded = True break # Success, exit the architecture loop - except subprocess.CalledProcessError as e: - if i < len(architectures) - 1: + except subprocess.CalledProcessError: + if i < len(architectures) - 1: # Reset the file for the next attempt compiled_out.seek(0) compiled_out.truncate() From b10a5b1535e9dd6c0071744177b3b09112ffb2e6 Mon Sep 17 00:00:00 2001 From: Azimjon Ulmasov Date: Tue, 5 Aug 2025 17:59:40 -0400 Subject: [PATCH 3/4] use target-architecture from package YAML definition Signed-off-by: Azimjon Ulmasov --- pre_commit_hooks/shellcheck_run_steps.py | 59 ++++++++---------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/pre_commit_hooks/shellcheck_run_steps.py b/pre_commit_hooks/shellcheck_run_steps.py index 500691a..72658e5 100644 --- a/pre_commit_hooks/shellcheck_run_steps.py +++ b/pre_commit_hooks/shellcheck_run_steps.py @@ -109,47 +109,26 @@ def main(argv: Sequence[str] | None = None) -> int: "w", delete_on_close=False, ) as compiled_out: - # Try multiple architectures - architectures = list( - dict.fromkeys([os.uname().machine, "x86_64", "aarch64"]), + with open(filename) as precompiled_in: + melange_cfg = yaml.load(precompiled_in) + architectures = melange_cfg["package"].get("target-architecture", []) + if not architectures: + architectures = ["x86_64"] + arch = architectures[0] + subprocess.check_call( + [ + "docker", + "run", + f"--volume={os.getcwd()}:/work", + "--rm", + MelangeImage, + "compile", + f"--arch={arch}", + "--pipeline-dir=./pipelines", + filename, + ], + stdout=compiled_out, ) - compilation_succeeded = False - - for i, arch in enumerate(architectures): - try: - subprocess.run( - [ - "docker", - "run", - f"--volume={os.getcwd()}:/work", - "--rm", - MelangeImage, - "compile", - f"--arch={arch}", - "--pipeline-dir=./pipelines", - filename, - ], - stdout=compiled_out, - stderr=subprocess.PIPE, - check=True, - text=True, - ) - compilation_succeeded = True - break # Success, exit the architecture loop - except subprocess.CalledProcessError: - if i < len(architectures) - 1: - # Reset the file for the next attempt - compiled_out.seek(0) - compiled_out.truncate() - continue - else: - # Last architecture failed, propagate the error - raise - - if not compilation_succeeded: - fail_cnt += 1 - continue - compiled_out.close() try: with open(compiled_out.name) as compiled_in: From 64740cd7d8cd5b6f7e797426d6be8ac5b51d804a Mon Sep 17 00:00:00 2001 From: Azimjon Ulmasov Date: Wed, 6 Aug 2025 09:22:07 -0400 Subject: [PATCH 4/4] move to cleaner arch detection Signed-off-by: Azimjon Ulmasov --- pre_commit_hooks/shellcheck_run_steps.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pre_commit_hooks/shellcheck_run_steps.py b/pre_commit_hooks/shellcheck_run_steps.py index 72658e5..7631998 100644 --- a/pre_commit_hooks/shellcheck_run_steps.py +++ b/pre_commit_hooks/shellcheck_run_steps.py @@ -111,10 +111,7 @@ def main(argv: Sequence[str] | None = None) -> int: ) as compiled_out: with open(filename) as precompiled_in: melange_cfg = yaml.load(precompiled_in) - architectures = melange_cfg["package"].get("target-architecture", []) - if not architectures: - architectures = ["x86_64"] - arch = architectures[0] + arch = melange_cfg["package"].get("target-architecture", ["x86_64"])[0] subprocess.check_call( [ "docker",