diff --git a/README.md b/README.md index d935eed..5c95675 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ Automation using Bash scripts and Cron jobs, inorder to automate the concordance check calculations. +[![CircleCI](https://dl.circleci.com/status-badge/img/gh/molgenis/ConcordanceCheck/tree/master.svg?style=svg)](https://dl.circleci.com/status-badge/redirect/gh/molgenis/ConcordanceCheck/tree/master) #### Code style diff --git a/check/indentationcheck.sh b/check/indentationcheck.sh index 5d9b88a..ea25371 100755 --- a/check/indentationcheck.sh +++ b/check/indentationcheck.sh @@ -1,9 +1,11 @@ #!/bin/bash +MYDIR="$(cd -P "$(dirname "${0}")" && pwd)" + echo '#####################################################################################' echo ' Bash code must be indented with TABs. Checking for lines indented with spaces ... ' echo '#####################################################################################' -grep -n '^[[:space:]]* [[:space:]]*' "${WORKSPACE:-../}"/{bin,lib}/*.*sh +grep -n '^[[:space:]]* [[:space:]]*' "${MYDIR}"/../{bin,lib}/*.*sh grep_exit_status="${?}" if [[ "${grep_exit_status}" -eq 0 ]]; then echo '#####################################################################################' diff --git a/check/shellcheck.sh b/check/shellcheck.sh index 50b63f0..b1b91f9 100755 --- a/check/shellcheck.sh +++ b/check/shellcheck.sh @@ -1,5 +1,9 @@ #!/bin/bash +set -e +set -u +set -o pipefail + # # Disable some shellcheck warnings: # * SC2004: $/${} is unnecessary on arithmetic variables. @@ -31,14 +35,15 @@ EOH # # Parse commandline options # -while getopts "hv" opt +declare format='gcc' # default +while getopts ":hv" opt do case "${opt}" in h) showHelp ;; v) - verbose='1' + format='tty' ;; \?) printf '%s\n' "FATAL: Invalid option -${OPTARG}. Try $(basename "${0}") -h for help." @@ -64,14 +69,13 @@ which shellcheck 2>&1 >/dev/null \ exit 1 } +MYDIR="$(cd -P "$(dirname "${0}")" && pwd)" # # Run ShellCheck for all Bash scripts in the bin/ subdir. # * Includes sourced files, so the libraries from the lib/ subfolder # are checked too as long a they are used in at least one script. -# * Select format and output based on whether this script is -# executed by Jenkins or by a regular user. # -if [[ -n "${WORKSPACE:-}" ]] +if [[ "${CIRCLECI:-}" == true ]] then # # Exclude SC2154 (warning for variables that are referenced but not assigned), @@ -79,26 +83,9 @@ then # export SHELLCHECK_OPTS="${SHELLCHECK_OPTS} -e SC2154" # - # ShellCheck for Jenkins. - # - shellcheck -a -x -o all -f checkstyle "${WORKSPACE}"/bin/*.sh | tee checkstyle-result.xml - # - # Reformat the generated report to add hyperlinks to the ShellCheck issues on the wiki: - # https://github.com/koalaman/shellcheck/wiki/SC${ISSUENUMBER} - # explaining whatis wrong with the code / style and how to improve it. - # - perl -pi -e "s|message='([^']+)'\s+source='ShellCheck.(SC[0-9]+)'|message='<a href="https://github.com/koalaman/shellcheck/wiki/\$2">\$2: \$1</a>' source='ShellCheck.\$2'|" checkstyle-result.xml -else - # - # ShellCheck for regular user on the commandline. + # Exclude SC2312 (warning for masking return values of command in a subshell when using process substitution) temporarily, + # because we did not find a reliable fix yet.... # - MYDIR="$(cd -P "$(dirname "${0}")" && pwd)" - if [[ "${verbose:-0}" -eq 1 ]] - then - cd "${MYDIR}/.." - shellcheck -a -x -o all -f tty bin/*.sh # cannot use the printf construct used below for non-vebose output as it destroys the terminal colors. - cd '-' # Goes back to previous directory before we changed to ${MYDIR}. - else - printf '%s\n' "$(cd "${MYDIR}/.." && shellcheck -a -x -o all -f gcc bin/*.sh)" - fi + export SHELLCHECK_OPTS="${SHELLCHECK_OPTS} -e SC2312" fi +shellcheck -a -x -o all -f "${format}" "${MYDIR}"/../bin/*.sh | sed "s|${MYDIR}/../||g" \ No newline at end of file