Skip to content

Commit b261c69

Browse files
authored
Merge pull request #13 from chainguard-dev/shellcheck-fixes
shellcheck fixes
2 parents 20d7516 + bd7e7ae commit b261c69

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ repos:
4343
rev: 528d713e620bdf4b41849db93cb489c4fef9f5c5 # v0.6.0
4444
hooks:
4545
- id: misspell
46+
exclude: '^example\.pre-commit-config\.yaml$'

example.pre-commit-config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ repos:
66
- repo: https://github.com/chainguard-dev/pre-commit-hooks
77
rev: 71fca50bcd1006b5cbcf71f03a3b493f48c4af7f
88
hooks:
9-
# Not quite ready for prime time yet, due to a tool dependency outside the pre-commit managed environment.
10-
#- id: shellcheck-run-steps
9+
- id: shellcheck-run-steps
10+
files: '^[^.][^/]*\.yaml$' # matches non-hidden .yaml files at the top level only
11+
args:
12+
- "--" # options to hook before this, options to shellcheck after
13+
- "-S"
14+
- "error"
15+
- "--" # terminates shellcheck options, rest will be filenames
1116
- id: check-for-epoch-bump
1217
files: |
1318
(?x)^(

pre_commit_hooks/shellcheck_run_steps.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
yaml = ruamel.yaml.YAML(typ="safe")
1515

16+
# Please provide the output of `grype koalaman/shellcheck@sha256:<newhash>`
17+
# in your PR when bumping. Referenced by SHA for safety.
18+
DefaultShellCheckImage = "koalaman/shellcheck@sha256:652a5a714dc2f5f97e36f565d4f7d2322fea376734f3ec1b04ed54ce2a0b124f"
19+
1620

1721
def do_shellcheck(
1822
melange_cfg: Mapping[str, Any],
@@ -55,7 +59,7 @@ def do_shellcheck(
5559
shfile.write(step["runs"])
5660
shfile.close()
5761
subprocess.check_call(
58-
["/usr/bin/shellcheck"]
62+
shellcheck
5963
+ shellcheck_args
6064
+ ["--shell=busybox", "--"]
6165
+ [os.path.basename(f.name) for _, f in all_steps],
@@ -68,8 +72,7 @@ def main(argv: Sequence[str] | None = None) -> int:
6872
parser.add_argument(
6973
"filenames",
7074
nargs="*",
71-
help="Filenames to check. You can also pass "
72-
"arguments to shellcheck before a '--' separator.",
75+
metavar="[-- SHELLCHECK ARGS -- ] FILENAMES",
7376
)
7477
parser.add_argument(
7578
"--shellcheck",
@@ -79,7 +82,7 @@ def main(argv: Sequence[str] | None = None) -> int:
7982
f"--volume={os.getcwd()}:/mnt",
8083
"--rm",
8184
"-it",
82-
"koalaman/shellcheck:latest",
85+
DefaultShellCheckImage,
8386
],
8487
nargs="*",
8588
help="shellcheck command",

0 commit comments

Comments
 (0)