Skip to content

Commit

Permalink
Merge pull request #44 from pneerincx/improved_indentationcheck
Browse files Browse the repository at this point in the history
Improved indentation check.
  • Loading branch information
marieke-bijlsma authored Jun 20, 2023
2 parents 90c16ab + a290e9a commit 4039ee7
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 65 deletions.
Binary file removed .DS_Store
Binary file not shown.
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
* text=auto

*.sh eol=lf
*.bash eol=lf
*.md eol=lf
*.cfg eol=lf
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.DS_Store
*.project
*.pydevproject
*.settings
*.md.html
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,4 @@ Navigate to jobs folder. The location of the jobs folder will be outputted at th
```BASH
bash submit.sh
```

12 changes: 2 additions & 10 deletions check/indentationcheck.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#!/bin/bash

#
# Use either WORKSPACE location for Jenkins or
# resolve path to scripts we need to check
# when executed manually outside Jenkins.
#
if [[ -z "${WORKSPACE:-}" ]]; then
MYDIR="$(cd -P "$(dirname "${0}")" && pwd)"
WORKSPACE="$(dirname ${MYDIR})"
fi
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:-../}/protocols/"*.sh
grep --recursive --line-number --include='*.*sh' --exclude-dir='deprecated' '^[[:space:]]* [[:space:]]*' "${MYDIR}"/../
grep_exit_status="${?}"
if [[ "${grep_exit_status}" -eq 0 ]]; then
echo '#####################################################################################'
Expand Down
49 changes: 16 additions & 33 deletions check/shellcheck.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#!/bin/bash

set -e
set -u
set -o pipefail

#
# Disable some shellcheck warnings:
# * SC2004: $/${} is unnecessary on arithmetic variables.
# But for consistency we prefer to always use ${} anyway.
# * SC2015: Note that A && B || C is not if-then-else. C may run when A is true.
# We know and use this construct regularly to create "transactions"
# where C is only executed when both A and B have succeeded.
# * SC2154: Due to Molgenis Compute string initialization the warning is not valid
#
# * SC2148: the shebang is declared in the header.ftl not in the protocols
# * SC2148: The shebang is declared in the header.ftl and not in the protocols.
#

export SHELLCHECK_OPTS="-e SC2004 -e SC2015 -e SC2154 -e SC2148"
export SHELLCHECK_OPTS="-e SC2004 -e SC2015 -e SC2148"

function showHelp() {
#
Expand All @@ -35,14 +36,15 @@ EOH
#
# Parse commandline options
#
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 @@ -68,42 +70,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
# Run ShellCheck for all Bash scripts in the protocols/ subdir.
# * Includes sourced files, so files in a 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}"/protocols/*.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 what is 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 protocols/*.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 protocols/*.sh)"
fi
export SHELLCHECK_OPTS="${SHELLCHECK_OPTS} -e SC2312"
fi
shellcheck -a -x -o all -f "${format}" "${MYDIR}"/../protocols/*.sh | sed "s|${MYDIR}/../||g"
20 changes: 8 additions & 12 deletions checkEnvironment.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
HOST=$1

if [ -f ./environment_checks.txt ]
if [[ -f ./environment_checks.txt ]]
then
rm ./environment_checks.txt
fi
Expand All @@ -10,29 +10,25 @@ TMPDIR=""
GROUP=""
if [ "${HOST}" == "zinc-finger.gcc.rug.nl" ]
then
ENVIRONMENT_PARAMETERS="zinc-finger"
TMPDIR="tmp05"
ENVIRONMENT_PARAMETERS="zinc-finger"
TMPDIR="tmp05"
elif [ "${HOST}" == "leucine-zipper.gcc.rug.nl" ]
then
ENVIRONMENT_PARAMETERS="leucine-zipper"
TMPDIR="tmp06"
elif [ "${HOST}" == "calculon" ]
then
ENVIRONMENT_PARAMETERS="calculon"
TMPDIR="tmp04"
ENVIRONMENT_PARAMETERS="leucine-zipper"
TMPDIR="tmp06"
else
echo "unknown host: running is only possible on calculon,zinc-finger or leucine-zipper"
echo "Unknown host: running is only possible on zinc-finger or leucine-zipper."
fi

THISDIR=$(pwd)
if [[ $THISDIR == *"/groups/umcg-gaf/"* ]]
then
GROUP="umcg-gaf"
elif [[ $THISDIR == *"/groups/umcg-gd/"* ]]
elif [[ $THISDIR == *"/groups/umcg-gd/"* ]]
then
GROUP="umcg-gd"
else
echo "this is not a known group, please run only in umcg-gd or umcg-gaf group"
echo "This is not a known group. Please run only in umcg-gd or umcg-gaf group."
fi

printf "${ENVIRONMENT_PARAMETERS}\t${TMPDIR}\t${GROUP}" > ./environment_checks.txt
4 changes: 2 additions & 2 deletions templates/generate_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ then
echo "RNA pipeline loaded, proceeding"
else
echo "No RNA pipeline loaded, exiting"
exit 1
exit 1
fi

module list
Expand Down Expand Up @@ -58,7 +58,7 @@ workflow="${EBROOTNGS_RNA}/workflow_${pipeline}.csv"
if [ -f .compute.properties ];
then
rm .compute.properties
rm .compute.properties
fi
perl "${EBROOTNGS_RNA}/convertParametersGitToMolgenis.pl" "${EBROOTNGS_RNA}/parameters.${species}.${build}.csv" > \
Expand Down
6 changes: 3 additions & 3 deletions test/autotest_generate_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ PIPELINE="hisat" # hisat, lexogen

WORKFLOW=${EBROOTNGS_RNA}/test_workflow_${PIPELINE}.csv

if [ -f .compute.properties ];
if [[ -f .compute.properties ]]
then
rm .compute.properties
rm .compute.properties
fi

if [ -f ${GAF}/generatedscripts/${PROJECT}/out.csv ];
if [[ -f ${GAF}/generatedscripts/${PROJECT}/out.csv ]]
then
rm -rf ${GAF}/generatedscripts/${PROJECT}/out.csv
fi
Expand Down
10 changes: 5 additions & 5 deletions test/protocols/Autotest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ done

if [[ -f "${testResults}/output_NGS_RNA/notInVcf1.txt" || -f "${testResults}/output_NGS_RNA/notInVcf2.txt" || -f "${testResults}/output_NGS_RNA/inconsistent.txt" || -f "${testResults}/output_NGS_RNA/"*.fail ]]
then
echo "there are differences between the test and the original output"
echo "please fix the bug or update this test"
echo "the stats can be found here: ${testResults}/output_NGS_RNA/vcfStats.txt"
exit 1
echo "There are differences between the test and the original output."
echo "Please fix the bug or update this test."
echo "The stats can be found here: ${testResults}/output_NGS_RNA/vcfStats.txt"
exit 1
else
echo "test succeeded"
echo "Test succeeded."
head -2 "${testResults}/output_NGS_RNA/vcfStats.txt"
fi

0 comments on commit 4039ee7

Please sign in to comment.