From e4ece7de1b7b58007ff17024085a84ff65724ce2 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 15 Mar 2023 09:32:17 -0400 Subject: [PATCH 1/3] Add github action to shellcheck master on push and PRs --- .github/workflows/shellcheck.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/shellcheck.yml diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 000000000000..087aba7689b8 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,23 @@ +--- +name: Shellcheck + +on: + push: + branches: [master] + pull_request: + branches: [master] + +jobs: + shellcheck: + name: Check shell scripts + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Install dependencies + run: | + sudo apt update && sudo apt install -y shellcheck + - name: shellcheck + run: | + git grep -l '^#\( *shellcheck \|!\(/bin/\|/usr/bin/env \)\(sh\|bash\|dash\|ksh\)\)' | xargs shellcheck From 5d381cba9779d84133f3db36467b63d2a0e46a56 Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 15 Mar 2023 09:40:25 -0400 Subject: [PATCH 2/3] [DATALAD RUNCMD] Autofix scripts using shellcheck === Do not change lines below === { "chain": [], "cmd": "shellcheckit doit -f diff | git apply", "exit": 0, "extra_inputs": [], "inputs": [], "outputs": [], "pwd": "." } ^^^ Do not change lines above ^^^ --- misc/build-debug-python.sh | 14 +++++++------- misc/clean-mypyc.sh | 4 ++-- misc/test-stubgenc.sh | 2 +- misc/trigger_wheel_build.sh | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/misc/build-debug-python.sh b/misc/build-debug-python.sh index f652d6ad9937..6c1ab3a51077 100755 --- a/misc/build-debug-python.sh +++ b/misc/build-debug-python.sh @@ -23,12 +23,12 @@ if [[ $(uname) == Darwin ]]; then LDFLAGS="-L$(brew --prefix openssl)/lib" fi -curl -O https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tgz -tar zxf Python-$VERSION.tgz -cd Python-$VERSION -CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" ./configure CFLAGS="-DPy_DEBUG -DPy_TRACE_REFS -DPYMALLOC_DEBUG" --with-pydebug --prefix=$PREFIX +curl -O https://www.python.org/ftp/python/"$VERSION"/Python-"$VERSION".tgz +tar zxf Python-"$VERSION".tgz +cd Python-"$VERSION" +CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" ./configure CFLAGS="-DPy_DEBUG -DPy_TRACE_REFS -DPYMALLOC_DEBUG" --with-pydebug --prefix="$PREFIX" make -j4 make install -$PREFIX/bin/python3 -m pip install virtualenv -$PREFIX/bin/python3 -m virtualenv $VENV -ln -s python3-config $PREFIX/bin/python-config +"$PREFIX"/bin/python3 -m pip install virtualenv +"$PREFIX"/bin/python3 -m virtualenv "$VENV" +ln -s python3-config "$PREFIX"/bin/python-config diff --git a/misc/clean-mypyc.sh b/misc/clean-mypyc.sh index 8b29a7d09d68..d850f925f664 100755 --- a/misc/clean-mypyc.sh +++ b/misc/clean-mypyc.sh @@ -1,4 +1,4 @@ #!/bin/bash echo "Cleaning C/C++ build artifacts..." -(cd mypyc/lib-rt; make clean) -(cd mypyc/external/googletest/make; make clean) +(cd mypyc/lib-rt || exit; make clean) +(cd mypyc/external/googletest/make || exit; make clean) diff --git a/misc/test-stubgenc.sh b/misc/test-stubgenc.sh index 7da135f0bf16..3f0b32fef38e 100755 --- a/misc/test-stubgenc.sh +++ b/misc/test-stubgenc.sh @@ -3,7 +3,7 @@ set -e set -x -cd "$(dirname $0)/.." +cd "$(dirname "$0")/.." # Install dependencies, demo project and mypy python -m pip install -r test-requirements.txt diff --git a/misc/trigger_wheel_build.sh b/misc/trigger_wheel_build.sh index c914a6e7cf86..094f6342006b 100755 --- a/misc/trigger_wheel_build.sh +++ b/misc/trigger_wheel_build.sh @@ -14,10 +14,10 @@ pip install -r mypy-requirements.txt V=$(python3 -m mypy --version) V=$(echo "$V" | cut -d" " -f2) -git clone --depth 1 https://${WHEELS_PUSH_TOKEN}@github.com/mypyc/mypy_mypyc-wheels.git build +git clone --depth 1 https://"${WHEELS_PUSH_TOKEN}"@github.com/mypyc/mypy_mypyc-wheels.git build cd build -echo $COMMIT > mypy_commit +echo "$COMMIT" > mypy_commit git commit -am "Build wheels for mypy $V" -git tag v$V +git tag v"$V" # Push a tag, but no need to push the change to master git push --tags From 4030984477eba765ba9cf0e9839ad4481787218e Mon Sep 17 00:00:00 2001 From: Yaroslav Halchenko Date: Wed, 15 Mar 2023 09:43:19 -0400 Subject: [PATCH 3/3] Safeproof misc/test-stubgenc.sh for the value of a variable codespell complained In misc/test-stubgenc.sh line 15: rm -rf $STUBGEN_OUTPUT_FOLDER/* ^----------------------^ SC2115 (warning): Use "${var:?}" to ensure this never expands to /* . For more information: https://www.shellcheck.net/wiki/SC2115 -- Use "${var:?}" to ensure this nev... so I followed the recommendation and also ""quoted the value use later in the lines. In principle that is all not required ATM since the value is hardcoded in the script BUT happen the value changes, and e.g. variable name gets changed or mystyped without correct changes to uses -- someone might end up in pain while triggering all those gotchas. With these changes code becomes safer and thus preferable imho. --- misc/test-stubgenc.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/misc/test-stubgenc.sh b/misc/test-stubgenc.sh index 3f0b32fef38e..4a89112dc58c 100755 --- a/misc/test-stubgenc.sh +++ b/misc/test-stubgenc.sh @@ -12,8 +12,8 @@ python -m pip install . # Remove expected stubs and generate new inplace STUBGEN_OUTPUT_FOLDER=./test-data/pybind11_mypy_demo/stubgen -rm -rf $STUBGEN_OUTPUT_FOLDER/* -stubgen -p pybind11_mypy_demo -o $STUBGEN_OUTPUT_FOLDER +rm -rf "${STUBGEN_OUTPUT_FOLDER:?}/"* +stubgen -p pybind11_mypy_demo -o "$STUBGEN_OUTPUT_FOLDER" # Compare generated stubs to expected ones -git diff --exit-code $STUBGEN_OUTPUT_FOLDER +git diff --exit-code "$STUBGEN_OUTPUT_FOLDER"