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 13 commits
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
1 change: 0 additions & 1 deletion .cppcheck_suppressions
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ duplicateCondition:./
nullPointer:./
missingInclude:./
uninitvar:./

2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ If applicable, add screenshots to help explain your problem.
- NEST-Version: [e.g. nest-2.18, or git hash]
- Installation: [e.g. conda packet, apt, with/out MPI, ...]
(in case you compiled the source code manually, provide the
"Installation Summary" that you see at the end of the
"Installation Summary" that you see at the end of the
cmake step)

**Additional context**
Expand Down
1 change: 0 additions & 1 deletion .github/styles/nest-styles/Ampersands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ level: warning
nonword: true
tokens:
- '\w+\s&\s\w+'

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Annotations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ tokens:
- FIXME
- TODO
- NOTE

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Capitalization.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ message: "'%s' should be in sentence case"
level: warning
scope: heading
match: $sentence

1 change: 0 additions & 1 deletion .github/styles/nest-styles/CommasPerSentence.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ extends: occurrence
scope: sentence
max: 3
token: ','

1 change: 0 additions & 1 deletion .github/styles/nest-styles/ComplexWords.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ swap:
transmit: "'send'"
utilization: "'use'"
utilize: "'use'"

1 change: 0 additions & 1 deletion .github/styles/nest-styles/ListCapitalize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ scope: list
nonword: true
tokens:
- '^[a-z].+'

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Negative.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ tokens:
- don't
- doesn't
- hasn't

1 change: 0 additions & 1 deletion .github/styles/nest-styles/NotEasy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ tokens:
- just
- easily
- simply

1 change: 0 additions & 1 deletion .github/styles/nest-styles/ParagraphLength.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ scope: paragraph.rst
level: suggestion
max: 150
token: \b(\w+)\b

1 change: 0 additions & 1 deletion .github/styles/nest-styles/PassiveVoice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,3 @@ tokens:
- woven
- written
- wrung

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Pronouns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@ tokens:
- hers
- himself
- herself

1 change: 0 additions & 1 deletion .github/styles/nest-styles/SentenceLength.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ scope: sentence
level: suggestion
max: 25
token: \b(\w+)\b

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Slash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ ignorecase: true
level: error
tokens:
- '\w+/\w+'

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Spelling.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ message: "Did you really mean '%s'?"
level: error
ignore:
- vocab.txt

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Units.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ message: "Add a space between a numeral and a unit of measure."
level: error
tokens:
- '\d+(?:MB|Gbit|GB|kbps|KB|kb)'

1 change: 0 additions & 1 deletion .github/styles/nest-styles/Wordiness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,3 @@ swap:
with regard to: regarding
with respect to: about or on
with the exception of: except for

60 changes: 58 additions & 2 deletions .github/workflows/nestbuildmatrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,62 @@ jobs:
files=$(find . \( -iname "*.h" -o -iname "*.c" -o -iname "*.cc" -o -iname "*.cpp" \) -not -path "./thirdparty/*")
diff -u <(cat ${files}) <(clang-format ${files})

shellcheck:
runs-on: "ubuntu-20.04"
steps:
- name: "Checkout repository content"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: "Install Linux system dependencies"
run: |
sudo apt-get update
sudo apt-get install shellcheck

- name: "Run shellcheck..."
run: |
shellcheck --version
find . -iname "*.sh" -o -iname "*.sh.in" | xargs shellcheck

pre-commit-hooks:
runs-on: "ubuntu-20.04"
steps:
- name: "Checkout repository content"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: "Set up Python 3.x"
uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1 # v4.7.0
with:
python-version: 3.9

- name: "Install dependencies"
run: |
pip install pre-commit

- name: "Run pre-commit checks..."
run: |
pre-commit run --all-files

no-crlf:
# While pre-commit-hook mixed-line-endings could check for this, it would
# be incompatible with "git smudge", as users may decide to use any
# formatting in their editor consistently.
# https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#mixed-line-ending
#
# This check makes sure the repository is always consistent NL line endings.
runs-on: "ubuntu-20.04"
steps:
- name: "Checkout repository content"
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
with:
fetch-depth: 0

- name: "Check all files for broken line endings…"
run: '! find . -not -type d -exec file "{}" ";" | grep CRLF'

cppcheck:
runs-on: "ubuntu-22.04"
steps:
Expand Down Expand Up @@ -509,7 +565,7 @@ jobs:
build_linux:
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
runs-on: ${{ matrix.os }}
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, isort, black, flake8]
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, isort, black, flake8, shellcheck, pre-commit-hooks, cppcheck, no-crlf]
env:
CXX_FLAGS: "-pedantic -Wextra -Woverloaded-virtual -Wno-unknown-pragmas"
NEST_VPATH: "build"
Expand Down Expand Up @@ -727,7 +783,7 @@ jobs:
build_macos:
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
runs-on: ${{ matrix.os }}
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, isort, black, flake8]
needs: [clang-format, mypy, copyright_headers, unused_names, forbidden_types, pylint, isort, black, flake8, shellcheck, pre-commit-hooks, cppcheck, no-crlf]
env:
CXX_FLAGS: "-pedantic -Wextra -Woverloaded-virtual -Wno-unknown-pragmas"
NEST_VPATH: "build"
Expand Down
79 changes: 44 additions & 35 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml

- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.3
hooks:
- id: gitleaks

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--thirdparty", "nest"]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/koalaman/shellcheck-precommit
rev: v0.9.0
hooks:
- id: shellcheck

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.4
hooks:
- id: clang-format
types_or: [c++]
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: forbid-submodules
- id: mixed-line-ending
- id: fix-byte-order-marker

- repo: https://github.com/gitleaks/gitleaks
rev: v8.16.3
hooks:
- id: gitleaks

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black", "--thirdparty", "nest"]

- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
# explicitly add input files that are not "*.sh"
args: [ # note that these differ from arguments in .github/workflows/nestbuildmatrix.yml
"bin/nest_vars.sh.in", # testsuite/do_tests.sh:112 requires this for `. "${PREFIX}/bin/nest_vars.sh"`
]

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v17.0.4
hooks:
- id: clang-format
types_or: [c++]

exclude: 'build/.*|thirdparty/.*'
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ The NEST Simulator is a scientific tool and as such it is never finished and con


Visit the [contributing to NEST docs](https://nest-simulator.readthedocs.io/en/latest/developer_space/index.html) for details
on
on

* development workflow
* reporing bugs and issues
* making changes to the code or documentation
* code review policies

and much more!

1 change: 0 additions & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,3 @@ severity and further handling via [Security
Advisories](https://github.com/nest/nest-simulator/security/advisories)
or as normal [Issue](https://github.com/nest/nest-simulator/issues) in
non-critical cases.

24 changes: 12 additions & 12 deletions bin/nest-config.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,32 @@ Known values for OPTION are:

EOF

exit $1
exit "${1}"
}

if test $# -eq 0; then
usage 1
fi

cflags=false
libs=false

while test $# -gt 0; do
case "$1" in
-*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
*) optarg= ;;
-*=*)
optarg="$(echo "$1" | sed 's/[-_a-zA-Z0-9]*=//')"
;;
*)
optarg=
;;
esac

case "$1" in
--prefix=*)
prefix=$optarg
prefix="${optarg}"
;;
--prefix)
echo $prefix
echo "${prefix}"
;;
--exec-prefix)
echo $exec_prefix
echo "${exec_prefix}"
;;
--version)
echo "@NEST_VERSION@"
Expand All @@ -68,7 +69,7 @@ while test $# -gt 0; do
echo "@ALL_CXXFLAGS@"
;;
--libs)
echo "-L$prefix/@CMAKE_INSTALL_LIBDIR@/nest @MODULE_LINK_LIBS@"
echo "-L${prefix}/@CMAKE_INSTALL_LIBDIR@/nest @MODULE_LINK_LIBS@"
;;
--compiler)
echo "@CMAKE_CXX_COMPILER@"
Expand Down Expand Up @@ -99,8 +100,7 @@ while test $# -gt 0; do
echo "@CMAKE_INSTALL_LIBDIR@"
;;
*)
usage
exit 1
usage 1
;;
esac
shift
Expand Down
19 changes: 13 additions & 6 deletions bin/nest-server
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ pid() {
pgrep -f "gunicorn nest.server.app --bind ${HOST}:${PORT}"
}

declare -a GUNICORN_OPTS
set-gunicorn_opts() {
# Set opts for gunicorn.
GUNICORN_OPTS="--bind ${HOST}:${PORT}"
GUNICORN_OPTS+=( "--bind" "${HOST}:${PORT}" )
if [ "${DAEMON}" -eq 1 ]; then
GUNICORN_OPTS="${GUNICORN_OPTS} --daemon"
GUNICORN_OPTS+=( "--daemon" )
fi
if [ "${STDOUT}" -eq 0 ]; then
GUNICORN_OPTS="${GUNICORN_OPTS} --capture-output"
GUNICORN_OPTS+=( "--capture-output" )
fi
GUNICORN_OPTS="${GUNICORN_OPTS} --log-file ${LOGFILE}"
GUNICORN_OPTS+=( "--log-file" "${LOGFILE}" )
}

start() {
Expand All @@ -61,12 +62,17 @@ start() {
fi

set-gunicorn_opts
exec gunicorn nest.server:app ${GUNICORN_OPTS}
exec gunicorn nest.server:app "${GUNICORN_OPTS[@]}"
fi
}

status() {
# List all processes of NEST Server.
#
# NOTE: The following noqa should not be necessary. Please refactor the awk
# to use pgrep output if you know how.
# SC2009 (info): Consider using pgrep instead of grepping ps output.
# shellcheck disable=SC2009
PS_AUX="$(ps aux | grep "[g]unicorn nest.server.app")"
printf "USER\t\t\tPID\t\tHTTP-SOCKET\n"
echo "${PS_AUX}" | head -n 1 | awk '{ for(i=1;i<=NF;i++) {if ( i == 1 || i == 2 || i == 15 ) printf $i"\t\t"}; printf "\n" }'
Expand All @@ -85,11 +91,12 @@ stop() {

CMD=$1; shift
while getopts "dh:op:" opt; do
case $opt in
case "$opt" in
d) DAEMON=1 ;;
h) HOST=$OPTARG ;;
o) STDOUT=1 ;;
p) PORT=$OPTARG ;;
*) usage ;;
esac
done

Expand Down
Loading
Loading