Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shellcheck and pre-commit to CI jobs #3002

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bf588a2
add shellcheck and pre-commit to CI jobs
terhorstd Nov 21, 2023
bb00bbf
Merge remote-tracking branch 'upstream/master' into add-shellcheck-pr…
terhorstd Jan 21, 2025
aed74c6
enable checking more file formatting issues
terhorstd Jan 21, 2025
6e0e5c4
reformatted whitespaces and newlines
terhorstd Jan 21, 2025
ac35773
fixed numerous quotes and plain bugs found by shellcheck
terhorstd Jan 21, 2025
d9e7231
add shellcheck, pre-commit-hooks and cppcheck as build prerequisites
terhorstd Jan 21, 2025
12d79b4
add CI check for Windows line endings CRLF
terhorstd Jan 21, 2025
8fddc68
fix run_examples search mechanism
terhorstd Jan 21, 2025
42765f6
attempt to fix missing shellcheck input file
terhorstd Jan 21, 2025
6f1b088
fix return code of check_forbidden_types.sh
terhorstd Jan 21, 2025
6678863
try argument with koalaman/shellcheck-precommit
terhorstd Jan 21, 2025
9286262
notice incoherent shellcheck file lists
terhorstd Jan 21, 2025
24d4a39
fix typo
terhorstd Jan 22, 2025
26456a7
fix undefined variable in junit_xml.sh
terhorstd Jan 22, 2025
ff38aad
partial pre-commit autoupdate
terhorstd Jan 22, 2025
a69ce17
improved comment
terhorstd Jan 22, 2025
f7e9464
add workaround for missing 'find -printf' on MacOS
terhorstd Jan 22, 2025
4ea5f00
added extra explanation for future me
terhorstd Jan 22, 2025
9571b05
Fix typo in comment
heplesser Jan 22, 2025
cd2484c
more fixes of shell quoting and escaping for install scripts
terhorstd Jan 30, 2025
a8fa1a9
Merge remote-tracking branch 'refs/remotes/origin/add-shellcheck-prec…
terhorstd Jan 30, 2025
efdf4c8
Merge remote-tracking branch 'upstream/master' into add-shellcheck-pr…
terhorstd Jan 30, 2025
6f937eb
change quoting and reporting of library install paths
terhorstd Jan 30, 2025
b9025f7
change hardcoded gtime path on Darwin to $(which …)
terhorstd Feb 26, 2025
ec854ca
Merge branch 'master' into add-shellcheck-precommit
terhorstd Feb 26, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions build_support/install_csa-libneurosim.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#!/bin/bash
# Install libneurosim
set -euo pipefail

NEUROSIM_INSTALL_PATH="${1:-${HOME}/.cache/libneurosim.install}"
CSA_INSTALL_PATH="${1:-${HOME}/.cache/csa.install}"
PYLIB_DIR="$(python3 -c "import sysconfig; print(sysconfig.get_path('include'))" | sed 's/include/lib/')" || true # was "$1" before

# Install libneurosim
git clone "https://github.com/INCF/libneurosim.git" libneurosim.src
pushd libneurosim.src
./autogen.sh
./configure --prefix="${HOME}/.cache/libneurosim.install" --with-mpi --with-python=3
make
./configure --prefix="${NEUROSIM_INSTALL_PATH}" --with-mpi --with-python=3
make -j"$(nproc)"
make install
popd || exit $?
rm -rf libneurosim.src
Expand All @@ -17,7 +21,7 @@ pushd csa.src
sed -i 's/lpyneurosim/lpy3neurosim/g' configure.ac
sed -i 's/print __version__/print\(__version__\)/g' Makefile.am
./autogen.sh
LDFLAGS="-L${1}" ./configure --with-libneurosim="${HOME}/.cache/libneurosim.install" --prefix="${HOME}/.cache/csa.install"
LDFLAGS="${PYLIB_DIR:+-L${PYLIB_DIR}}" ./configure --with-libneurosim="${NEUROSIM_INSTALL_PATH}" --prefix="${CSA_INSTALL_PATH}"
make
make install
popd || exit $?
Expand Down
5 changes: 3 additions & 2 deletions build_support/install_music.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/bin/bash
set -euo pipefail

MUSIC_INSTALL_PATH="${1:-${HOME}/.cache/music.install}"
# Install current MUSIC version.
git clone "https://github.com/INCF/MUSIC.git" music.src
pushd music.src
./autogen.sh
./configure --prefix="${HOME}/.cache/music.install"
make
./configure --prefix="${MUSIC_INSTALL_PATH}"
make -j"$(nproc)"
make install
popd || exit $?
rm -rf music.src
5 changes: 3 additions & 2 deletions build_support/install_sionlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
set -euo pipefail

SIONLIBVERSION="1.7.4"
SIONLIB_INSTALL_PATH="${1:-${HOME}/.cache/csa.install}"

# Install SIONlib
wget --content-disposition "http://apps.fz-juelich.de/jsc/sionlib/download.php?version=${SIONLIBVERSION}"
tar xfz "sionlib-${SIONLIBVERSION}.tar.gz"
mv sionlib sionlib.src
pushd sionlib.src
./configure --prefix="${HOME}/.cache/sionlib.install" --mpi=openmpi --enable-python=3 --disable-fortran --disable-parutils --disable-mic
./configure --prefix="${SIONLIB_INSTALL_PATH}" --mpi=openmpi --enable-python=3 --disable-fortran --disable-parutils --disable-mic
cd build-linux-gomp-openmpi
make
make -j"$(nproc)"
make install
popd || exit $?
rm -rf "sionlib-${SIONLIBVERSION}.tar.gz" sionlib.src
53 changes: 40 additions & 13 deletions examples/run_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,28 @@ if ! python3 -c "import nest" >/dev/null 2>&1; then
exit 1
fi


# set bash strict mode
set -euo pipefail
set -x
IFS=$' \n\t'

# current directory where all results are save is "basedir"
basedir="$PWD"
# source tree where all input scripts/data can be found is "sourcedir"
sourcedir="$(realpath "$(dirname "$0")/..")"

declare -a EXAMPLES
if [ "${#}" -eq 0 ]; then
# Find all examples that have a line containing "autorun=true"
# The examples can be found in subdirectory nest and in the
# examples installation path.
EXAMPLELIST="$(mktemp examplelist.XXXXXXXXXX)"
if [ -d "nest/" ] ; then
grep -rl --include='*.sli' 'autorun=true' nest/ >>"$EXAMPLELIST"
grep -rl --include='*.sli' 'autorun=true' "${sourcedir}/nest/" >>"$EXAMPLELIST" || true
else
grep -rl --include='*.sli' 'autorun=true' examples/ >>"$EXAMPLELIST"
grep -rl --include='*.sli' 'autorun=true' "${sourcedir}/examples/" >>"$EXAMPLELIST" || true
fi
find pynest/examples -name '*.py' >>"$EXAMPLELIST"
find "${sourcedir}/pynest/examples" -name '*.py' >>"$EXAMPLELIST" || true
readarray -t EXAMPLES <"$EXAMPLELIST" # append each example found above
rm "$EXAMPLELIST"
else
Expand All @@ -64,10 +69,34 @@ done
MPLCONFIGDIR="$(pwd)/matplotlib/"
export MPLCONFIGDIR

time_format=" time: {real: %E, user: %U, system: %S}\n\
memory: {total: %K, max_rss: %M}"
INFO_OS="$(uname -s)"

basedir=$PWD
# find "time" command
if test "${INFO_OS:-}" = "Darwin"; then
if test -x "/usr/local/bin/gtime"; then
# https://www.man7.org/linux/man-pages/man1/time.1.html
alias time="/usr/local/bin/gtime -f ' time: {real: %E, user: %U, system: %S}\n memory: {total: %K, max_rss: %M}' --quiet"
else
if command -v gtime >/dev/null; then
alias time="\$(command -v gtime) -f ' time: {real: %E, user: %U, system: %S}\n memory: {total: %K, max_rss: %M}' --quiet"
elif command -v time >/dev/null; then
# bash built-in time does not have memory information and uses TIMEFORMAT env variable
TIMEFORMAT=" time: {real: %E, user: %U, system: %S}"
export TIMEFORMAT
else
echo "'time' does not work on macOS. Try 'brew install gnu-time' or provide a compatible command by different means."
exit 1;
fi
fi
else
# bash built-in time does not have memory information and uses TIMEFORMAT env variable
TIMEFORMAT=" time: {real: %E, user: %U, system: %S}"
export TIMEFORMAT
if ! command -v time >/dev/null; then
echo "could not determine a 'time' command. aborting"
exit 1;
fi
fi

FAILURES=0
START="${SECONDS}"
Expand Down Expand Up @@ -101,11 +130,9 @@ for i in "${EXAMPLES[@]}"; do

export NEST_DATA_PATH="$output_dir"
touch .start_example
sleep 1
#sleep 1 # why was this needed?!
set +e
# The following line will not work on macOS. There, `brew install gnu-time` and use the commented-out line below.
/usr/bin/time -f "$time_format" --quiet sh -c "'$runner' '$example' >'$logfile' 2>&1" |& tee -a "$metafile"
# /usr/local/bin/gtime -f "$time_format" --quiet sh -c "'$runner' '$example' >'$logfile' 2>&1" | tee -a "$metafile" 2>&1
time sh -c "'$runner' '$example' >'$logfile' 2>&1" 2>&1 | tee -a "$metafile"
ret=$?
set -e

Expand All @@ -131,12 +158,12 @@ for i in "${EXAMPLES[@]}"; do

unset NEST_DATA_PATH
cd "$basedir"

exit 42
done
ELAPSED_TIME="$(( SECONDS - START ))"

echo ">>> Longest running examples:"
grep -Eo "real: [^,]+" example_logs/*/meta.yaml | sed -e 's/:real://' | sort -k2 -rg | head -n 15
grep -Eo "real: [^,]+" example_logs/*/meta.yaml | sed -e 's/:real://' | sort -k2 -rg | head -n 15 || true

echo ">>> RESULTS: ${FAILURES} failed /$(echo "${EXAMPLES[*]}" | wc -w) total"
echo ">>> TOTAL TIME: $((ELAPSED_TIME/60)) min $((ELAPSED_TIME%60)) sec."
Expand Down
8 changes: 4 additions & 4 deletions testsuite/do_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ if test "${HAVE_MPI}" = "true"; then
fi

# Under Mac OS X, suppress crash reporter dialogs. Restore old state at end.
echo "INFO_OS=${INFO_OS}"
if test "${INFO_OS}" = "Darwin"; then
echo "INFO_OS=${INFO_OS:-}"
if test "${INFO_OS:-}" = "Darwin"; then
TEST_CRSTATE="$( defaults read com.apple.CrashReporter DialogType )" || true
echo "TEST_CRSTATE=$TEST_CRSTATE"
defaults write com.apple.CrashReporter DialogType server || echo "WARNING: Could not set CrashReporter DialogType!"
Expand All @@ -178,7 +178,7 @@ list_files() {
# instead use list_files like
#
# list_files <somedir> <some_pattern> | while read -r test_name; do ... done
if test "${INFO_OS}" = "Darwin"; then
if test "${INFO_OS:-}" = "Darwin"; then
# ref https://stackoverflow.com/a/752893
# Note that on GNU systems an additional '-r' would be needed for
# xargs, which is not available here.
Expand Down Expand Up @@ -593,7 +593,7 @@ python3 "$(dirname "$0")/summarize_tests.py" "${REPORTDIR}"
TESTSUITE_RESULT="$?"

# Mac OS X: Restore old crash reporter state
if test "${INFO_OS}" = "Darwin" ; then
if test "${INFO_OS:-}" = "Darwin" ; then
defaults write com.apple.CrashReporter DialogType "${TEST_CRSTATE}" || echo "WARNING: Could not reset CrashReporter DialogType to '${TEST_CRSTATE}'!"
fi

Expand Down
1 change: 0 additions & 1 deletion testsuite/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ run_test ()
if test "x${unexpected_exitcode:-}" != x ; then
echo "***"
echo "*** An unexpected exit code usually hints at a bug in the test suite!"
ask_results
exit 2
fi

Expand Down