From 4fee4c723602f01235d038c9f9b8b41d15e79577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Montury?= <10528250-pytgaen@users.noreply.gitlab.com> Date: Sun, 29 Sep 2024 09:37:38 +0000 Subject: [PATCH] fix: support glob patterns in ShellCheck files Glob pattern expansion implemented with find --- README.md | 2 +- kicker.json | 2 +- templates/gitlab-ci-bash.yml | 25 ++++++++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a992542..96a08e1 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ This job performs a static analysis of your shell scripts using [ShellCheck](htt | ----------------------- | -------------------------------------- | ----------------- | | `shellcheck-disabled` / `BASH_SHELLCHECK_DISABLED` | Set to `true` to disable ShellCheck | _none_ (enabled) | | `shellcheck-image` / `BASH_SHELLCHECK_IMAGE` | The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck) | `registry.hub.docker.com/koalaman/shellcheck-alpine:stable` | -| `shellcheck-files` / `BASH_SHELLCHECK_FILES` | Shell file(s) pattern to analyse | `**/*.sh` | +| `shellcheck-files` / `BASH_SHELLCHECK_FILES` | Shell file(s) or pattern(s) to analyse | `**/*.sh` | | `shellcheck-opts` / `BASH_SHELLCHECK_OPTS` | ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) | _none_ | ### `bash-bats` job diff --git a/kicker.json b/kicker.json index fcb0459..d612ef5 100644 --- a/kicker.json +++ b/kicker.json @@ -20,7 +20,7 @@ }, { "name": "BASH_SHELLCHECK_FILES", - "description": "Shell file(s) pattern to analyse", + "description": "Shell file(s) or pattern(s) to analyse", "default": "**/*.sh" }, { diff --git a/templates/gitlab-ci-bash.yml b/templates/gitlab-ci-bash.yml index 0666e45..1e22b80 100644 --- a/templates/gitlab-ci-bash.yml +++ b/templates/gitlab-ci-bash.yml @@ -23,7 +23,7 @@ spec: description: The Docker image used to run [ShellCheck](https://github.com/koalaman/shellcheck) default: registry.hub.docker.com/koalaman/shellcheck-alpine:stable shellcheck-files: - description: Shell file(s) pattern to analyse + description: Shell file(s) or pattern(s) to analyse default: '**/*.sh' shellcheck-opts: description: ShellCheck [options](https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md) @@ -132,15 +132,15 @@ stages: set -e function log_info() { - echo -e "[\\e[1;94mINFO\\e[0m] $*" + >&2 echo -e "[\\e[1;94mINFO\\e[0m] $*" } function log_warn() { - echo -e "[\\e[1;93mWARN\\e[0m] $*" + >&2 echo -e "[\\e[1;93mWARN\\e[0m] $*" } function log_error() { - echo -e "[\\e[1;91mERROR\\e[0m] $*" + >&2 echo -e "[\\e[1;91mERROR\\e[0m] $*" } function install_ca_certs() { @@ -354,6 +354,20 @@ stages: ls -lart "$BATS_LIBRARIES_DIR" } + function glob_expand() { + for f in "$@"; do + if [[ "$f" == *[*?[]* ]]; then + # expand pattern with * or ? or [ + find . -path "$f" -type f + elif [[ -f "$f" ]]; then + echo "$f" + else + log_error "File not found: $f" + exit 1 + fi + done + } + unscope_variables eval_all_secrets @@ -375,7 +389,8 @@ bash-shellcheck: entrypoint: [""] script: - export LC_ALL=C.UTF-8 - - shellcheck $BASH_SHELLCHECK_OPTS $BASH_SHELLCHECK_FILES + - shellcheck $BASH_SHELLCHECK_OPTS $(glob_expand $BASH_SHELLCHECK_FILES) + rules: - if: '$BASH_SHELLCHECK_DISABLED == "true"' when: never -- GitLab