Skip to content

Commit

Permalink
Bugfixes for switching from Jenkins to CircleCI.
Browse files Browse the repository at this point in the history
  • Loading branch information
pneerincx committed Mar 31, 2023
1 parent 4a8da6e commit 32899bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion check/indentationcheck.sh
Original file line number Diff line number Diff line change
@@ -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 '#####################################################################################'
Expand Down
39 changes: 13 additions & 26 deletions check/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

set -e
set -u
set -o pipefail

#
# Disable some shellcheck warnings:
# * SC2004: $/${} is unnecessary on arithmetic variables.
Expand Down Expand Up @@ -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."
Expand All @@ -64,41 +69,23 @@ 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),
# because we cannot easily resolve variables sourced from etc/*.cfg config files.
#
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"

0 comments on commit 32899bb

Please sign in to comment.