diff --git a/README.md b/README.md index a99254268a043c83a37ee9adf78a5387c7b7a8d8..96a08e1ca588429d427c08753002a0289b3d729f 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 fcb04595070c259753a45936c539accc51a501dd..d612ef5fe24f6a1b5398fcd5b2e3b7c9580e4fa7 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 0666e45e726253ef9f663e7f4d9275c8111936bb..1e22b8031215a0dba67155f3f794025940500c9a 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