Skip to content

Commit

Permalink
shellcheck: introduce the --shellcheck-timeout option
Browse files Browse the repository at this point in the history
... to configure maximum amount of wall-clock time taken by a single
shellcheck process

Related: https://issues.redhat.com/browse/OSH-655
  • Loading branch information
kdudka committed Aug 12, 2024
1 parent 402510b commit 8991e99
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion py/plugins/shellcheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
FILTER_CMD = "csgrep --mode=json --remove-duplicates --quiet " \
"--invert-match --event '^note|warning\\[SC1090\\]'"

DEFAULT_SC_TIMEOUT = 30


class PluginProps:
def __init__(self):
Expand All @@ -48,6 +50,10 @@ def enable(self):

def init_parser(self, parser):
csmock.common.util.install_script_scan_opts(parser, "shellcheck")
parser.add_argument(
"--shellcheck-timeout", type=int, default=DEFAULT_SC_TIMEOUT,
help=f"maximum amount of wall-clock time taken by a single shellcheck process [s]" \
" (defaults to {DEFAULT_SC_TIMEOUT})")

def handle_args(self, parser, args, props):
if not self.enabled:
Expand All @@ -58,7 +64,8 @@ def handle_args(self, parser, args, props):
parser, args, props, "shellcheck")

props.install_pkgs += ["ShellCheck"]
cmd = f"SC_RESULTS_DIR={SHELLCHECK_CAP_DIR} {RUN_SHELLCHECK_SH} {dirs_to_scan}"
cmd = f"SC_RESULTS_DIR={SHELLCHECK_CAP_DIR} SC_TIMEOUT={args.shellcheck_timeout} "
cmd += f"{RUN_SHELLCHECK_SH} {dirs_to_scan}"
props.post_build_chroot_cmds += [cmd]
props.copy_out_files += [SHELLCHECK_CAP_DIR]

Expand Down
3 changes: 2 additions & 1 deletion scripts/run-shellcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ export SC_BATCH=1
export SC_JOBS=$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1)

# how long we wait (wall-clock time) for a single shellcheck process to finish
export SC_TIMEOUT=30
test -n "$SC_TIMEOUT" || export SC_TIMEOUT=30
test 0 -lt "$SC_TIMEOUT" || exit $?

# directory for shellcheck results
test -n "$SC_RESULTS_DIR" || export SC_RESULTS_DIR="./shellcheck-results"
Expand Down

0 comments on commit 8991e99

Please sign in to comment.