Commit 4fee4c72 authored by Gaëtan Montury's avatar Gaëtan Montury Committed by Pierre Smeyers
Browse files

fix: support glob patterns in ShellCheck files

Glob pattern expansion implemented with find
parent 47049b53
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -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"
        },
        {
+20 −5
Original line number Diff line number Diff line
@@ -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