Skip to content

Commit 584d6fd

Browse files
committed
shellcheck_run_steps: default to using shellcheck docker image
Requires that temp files live in the current directory, as that is what will be mounted within the container. We should replace this with a guarded container. Signed-off-by: dann frazier <dann.frazier@chainguard.dev>
1 parent a8f19d0 commit 584d6fd

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

pre_commit_hooks/shellcheck_run_steps.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import argparse
4+
import os
45
import subprocess
56
import tempfile
67
from collections.abc import Generator
@@ -51,10 +52,11 @@ def do_shellcheck(
5152
for step in pipelines:
5253
if "runs" not in step.keys():
5354
continue
54-
with tempfile.NamedTemporaryFile(mode="w") as shfile:
55+
with tempfile.NamedTemporaryFile(mode="w", dir=os.getcwd()) as shfile:
5556
shfile.write(step["runs"])
5657
subprocess.check_call(
57-
shellcheck + ["--shell=busybox", "--", shfile.name],
58+
shellcheck
59+
+ ["--shell=busybox", "--", os.path.basename(shfile.name)],
5860
)
5961

6062

@@ -63,7 +65,14 @@ def main(argv: Sequence[str] | None = None) -> int:
6365
parser.add_argument("filenames", nargs="*", help="Filenames to check.")
6466
parser.add_argument(
6567
"--shellcheck",
66-
default=["shellcheck"],
68+
default=[
69+
"docker",
70+
"run",
71+
f"--volume={os.getcwd()}:/mnt",
72+
"--rm",
73+
"-it",
74+
"koalaman/shellcheck:latest",
75+
],
6776
nargs="*",
6877
help="shellcheck command",
6978
)

0 commit comments

Comments
 (0)