---
lint:shellcheck:
  stage: lint
  image:
    name: megabytelabs/shellcheck:slim
    entrypoint: ['']
  rules:
    - if: $DO_CI == 'false'
      when: never
    - if: $CI_COMMIT_BRANCH == 'synchronize'
      when: never
    - exists:
        - '**/*.{sh,sh.j2}'
  needs: []
  variables:
    GIT_DEPTH: 1
  script:
    - set -eo pipefail
    - printenv
    - |
      if (find . -type d \( -name .cache -o -name .git -o -name .modules  -o -name node_modules -o -name .husky \) \
      -prune -o -type f \( -name \*.sh -o -name \*.sh.j2 \) -exec shellcheck -e SC1091 -f json1 {} \+ > results.json); then
        echo "Shellcheck did not find any errors"
        echo "[]" > gl-codequality.json
      else
        find . -type d \( -name .cache -o -name .git -o -name .modules  -o -name node_modules -o -name .husky \) \
        -prune -o -type f \( -name \*.sh -o -name \*.sh.j2 \) -exec shellcheck -e SC1091 {} \+
      fi
  artifacts:
    reports:
      codequality: gl-codequality.json
