Skip to content

Commit 825c568

Browse files
committed
use target-architecture from package YAML definition
Signed-off-by: Azimjon Ulmasov <azimjon.ulmasov@chainguard.dev>
1 parent cdaf3eb commit 825c568

File tree

1 file changed

+22
-40
lines changed

1 file changed

+22
-40
lines changed

pre_commit_hooks/shellcheck_run_steps.py

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -109,47 +109,29 @@ def main(argv: Sequence[str] | None = None) -> int:
109109
"w",
110110
delete_on_close=False,
111111
) as compiled_out:
112-
# Try multiple architectures
113-
architectures = list(
114-
dict.fromkeys([os.uname().machine, "x86_64", "aarch64"]),
112+
try:
113+
with open(filename) as pkg:
114+
yaml_def = yaml.load(pkg)
115+
architectures = yaml_def["package"].get("target-architecture", [])
116+
if not architectures:
117+
architectures = ["x86_64"]
118+
except (FileNotFoundError, ruamel.yaml.YAMLError):
119+
architectures = ["x86_64"]
120+
arch = architectures[0]
121+
subprocess.check_call(
122+
[
123+
"docker",
124+
"run",
125+
f"--volume={os.getcwd()}:/work",
126+
"--rm",
127+
MelangeImage,
128+
"compile",
129+
f"--arch={arch}",
130+
"--pipeline-dir=./pipelines",
131+
filename,
132+
],
133+
stdout=compiled_out,
115134
)
116-
compilation_succeeded = False
117-
118-
for i, arch in enumerate(architectures):
119-
try:
120-
subprocess.run(
121-
[
122-
"docker",
123-
"run",
124-
f"--volume={os.getcwd()}:/work",
125-
"--rm",
126-
MelangeImage,
127-
"compile",
128-
f"--arch={arch}",
129-
"--pipeline-dir=./pipelines",
130-
filename,
131-
],
132-
stdout=compiled_out,
133-
stderr=subprocess.PIPE,
134-
check=True,
135-
text=True,
136-
)
137-
compilation_succeeded = True
138-
break # Success, exit the architecture loop
139-
except subprocess.CalledProcessError:
140-
if i < len(architectures) - 1:
141-
# Reset the file for the next attempt
142-
compiled_out.seek(0)
143-
compiled_out.truncate()
144-
continue
145-
else:
146-
# Last architecture failed, propagate the error
147-
raise
148-
149-
if not compilation_succeeded:
150-
fail_cnt += 1
151-
continue
152-
153135
compiled_out.close()
154136
try:
155137
with open(compiled_out.name) as compiled_in:

0 commit comments

Comments
 (0)