Skip to content

Commit ce95da5

Browse files
jcfrthewtex
authored andcommitted
ci: Add linting of shell scripts
Note that to allow running the linting script locally, the dockerized version is used (instead of the suggested integration [1]) [1] https://github.com/koalaman/shellcheck#travis-ci-setup
1 parent 65a4193 commit ce95da5

12 files changed

+130
-40
lines changed

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
sudo: required
2+
3+
services:
4+
- docker
5+
6+
cache:
7+
directories:
8+
- $HOME/docker
9+
10+
before_install:
11+
- pip install -U scikit-ci-addons
12+
- ci_addons docker load-pull-save r.j3ss.co/shellcheck
13+
14+
script:
15+
- scripts/lint-shell-scripts.sh

scripts/dockcross-manylinux-build-module-wheels.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ chmod u+x /tmp/dockcross-manylinux-x64
1818
#docker run dockcross/manylinux-x86 > /tmp/dockcross-manylinux-x86
1919
#chmod u+x /tmp/dockcross-manylinux-x86
2020

21-
script_dir="`cd $(dirname $0); pwd`"
21+
script_dir=$(cd $(dirname $0) || exit 1; pwd)
2222

2323
# Build wheels
2424
mkdir -p dist

scripts/dockcross-manylinux-build-wheels.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ chmod u+x /tmp/dockcross-manylinux-x64
1717
#docker run dockcross/manylinux-x86 > /tmp/dockcross-manylinux-x86
1818
#chmod u+x /tmp/dockcross-manylinux-x86
1919

20-
script_dir="`cd $(dirname $0); pwd`"
20+
script_dir=$(cd $(dirname $0) || exit 1; pwd)
2121

2222
# Build wheels
2323
pushd $script_dir/..

scripts/internal/manylinux-build-common.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ fi
1818
# i686 or x86_64 ?
1919
case $(uname -p) in
2020
i686)
21-
arch=x86
21+
ARCH=x86
2222
;;
2323
x86_64)
24-
arch=x64
24+
ARCH=x64
2525
;;
2626
*)
2727
die "Unknown architecture $(uname -p)"
2828
;;
2929
esac
3030

31-
echo "Building wheels for $arch"
31+
echo "Building wheels for $ARCH"
3232

3333
# Since the python interpreter exports its symbol (see [1]), python
3434
# modules should not link against any python libraries.

scripts/internal/manylinux-build-module-wheels.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env bash
22

3-
script_dir="`cd $(dirname $0); pwd`"
3+
script_dir=$(cd $(dirname $0) || exit 1; pwd)
44
source "${script_dir}/manylinux-build-common.sh"
55

6+
# -----------------------------------------------------------------------
7+
# ARCH, PYBINARIES variables are set in common script
8+
# -----------------------------------------------------------------------
9+
610
# Compile wheels re-using standalone project and archive cache
711
for PYBIN in "${PYBINARIES[@]}"; do
812
if [[ ${PYBIN} == *"cp26"* || ${PYBIN} == *"cp33"* ]]; then
@@ -21,14 +25,14 @@ for PYBIN in "${PYBINARIES[@]}"; do
2125
if [[ -e /work/requirements-dev.txt ]]; then
2226
${PYBIN}/pip install -r /work/requirements-dev.txt
2327
fi
24-
itk_build_dir=/work/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${arch}
25-
ln -fs /ITKPythonPackage/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${arch} $itk_build_dir
28+
itk_build_dir=/work/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${ARCH}
29+
ln -fs /ITKPythonPackage/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${ARCH} $itk_build_dir
2630
if [[ ! -d $itk_build_dir ]]; then
2731
echo 'ITK build tree not available!' 1>&2
2832
exit 1
2933
fi
30-
itk_source_dir=/work/standalone-${arch}-build/ITK-source
31-
ln -fs /ITKPythonPackage/standalone-${arch}-build/ /work/standalone-${arch}-build
34+
itk_source_dir=/work/standalone-${ARCH}-build/ITK-source
35+
ln -fs /ITKPythonPackage/standalone-${ARCH}-build/ /work/standalone-${ARCH}-build
3236
if [[ ! -d $itk_source_dir ]]; then
3337
echo 'ITK source tree not available!' 1>&2
3438
exit 1

scripts/internal/manylinux-build-wheels.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#!/usr/bin/env bash
22

3-
script_dir="`cd $(dirname $0); pwd`"
3+
script_dir=$(cd $(dirname $0) || exit 1; pwd)
44
source "${script_dir}/manylinux-build-common.sh"
55

6+
# -----------------------------------------------------------------------
7+
# ARCH, PYBINARIES variables are set in common script
8+
# -----------------------------------------------------------------------
9+
610
# Build standalone project and populate archive cache
7-
mkdir -p /work/standalone-${arch}-build
8-
pushd /work/standalone-${arch}-build > /dev/null 2>&1
11+
mkdir -p /work/standalone-${ARCH}-build
12+
pushd /work/standalone-${ARCH}-build > /dev/null 2>&1
913
cmake -DITKPythonPackage_BUILD_PYTHON:PATH=0 -G Ninja ../
1014
ninja
1115
popd > /dev/null 2>&1
@@ -29,8 +33,8 @@ for PYBIN in "${PYBINARIES[@]}"; do
2933
${PYBIN}/pip install -r /work/requirements-dev.txt
3034

3135
build_type=MinSizeRel
32-
source_path=/work/standalone-${arch}-build/ITK-source
33-
build_path=/work/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${arch}
36+
source_path=/work/standalone-${ARCH}-build/ITK-source
37+
build_path=/work/ITK-$(basename $(dirname ${PYBIN}))-manylinux1_${ARCH}
3438
SETUP_PY_CONFIGURE="${script_dir}/../setup_py_configure.py"
3539

3640
# Clean up previous invocations
@@ -128,7 +132,7 @@ for PYBIN in "${PYBINARIES[@]}"; do
128132
fi
129133
sudo ${PYBIN}/pip install itk --no-cache-dir --no-index -f /work/dist
130134
sudo ${PYBIN}/pip install numpy
131-
(cd $HOME; ${PYBIN}/python -c 'from itk import ITKCommon;')
132-
(cd $HOME; ${PYBIN}/python -c 'import itk; image = itk.Image[itk.UC, 2].New()')
133-
(cd $HOME; ${PYBIN}/python -c 'import itkConfig; itkConfig.LazyLoading = False; import itk;')
135+
(cd $HOME && ${PYBIN}/python -c 'from itk import ITKCommon;')
136+
(cd $HOME && ${PYBIN}/python -c 'import itk; image = itk.Image[itk.UC, 2].New()')
137+
(cd $HOME && ${PYBIN}/python -c 'import itkConfig; itkConfig.LazyLoading = False; import itk;')
134138
done

scripts/internal/shellcheck-run.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
6+
(
7+
exit_code=0
8+
9+
#
10+
# SC1090: Can't follow non-constant source. Use a directive to specify location.
11+
# SC2006: Use $(..) instead of legacy `..`.
12+
# SC2046: Quote this to prevent word splitting.
13+
# SC2086: Double quote to prevent globbing and word splitting.
14+
# SC2153: Possible misspelling: SCRIPT_DIR may not be assigned, but script_dir is.
15+
# SC2155: Declare and assign separately to avoid masking return values.
16+
#
17+
18+
# find all executables and run `shellcheck`
19+
for f in $(find . -type f -not -iwholename '*.git*' | sort -u); do
20+
if file "$f" | grep --quiet -e shell -e bash; then
21+
shellcheck \
22+
-e SC1090 \
23+
-e SC2006 \
24+
-e SC2046 \
25+
-e SC2086 \
26+
-e SC2153 \
27+
-e SC2155 \
28+
"$f" \
29+
&& echo "[OK]: successfully linted $f" || echo "[FAILED]: found issues linting $f"
30+
current_exit_code=$?
31+
if [[ $current_exit_code != 0 ]]; then
32+
exit_code=$current_exit_code
33+
fi
34+
fi
35+
done
36+
37+
exit $exit_code
38+
)

scripts/lint-shell-scripts.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -o pipefail
5+
6+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
7+
8+
pushd $SCRIPT_DIR > /dev/null
9+
10+
docker run --rm -it \
11+
--name df-shellcheck \
12+
-v $(pwd):/usr/src:ro \
13+
--workdir /usr/src \
14+
r.j3ss.co/shellcheck ./internal/shellcheck-run.sh
15+
16+
exit_code=$?
17+
18+
popd > /dev/null
19+
20+
exit $exit_code

scripts/macpython-build-common.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
# macpython-build-module-wheels.sh
33

44
set -e -x
5+
6+
SCRIPT_DIR=$(cd $(dirname $0) || exit 1; pwd)
7+
58
MACPYTHON_PY_PREFIX=/Library/Frameworks/Python.framework/Versions
6-
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
79

810
# Versions can be restricted by passing them in as arguments to the script
911
# For example,

scripts/macpython-build-module-wheels.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
#
99
# scripts/macpython-build-module-wheels.sh 2.7 3.5
1010

11-
script_dir="`cd $(dirname $0); pwd`"
11+
script_dir=$(cd $(dirname $0) || exit 1; pwd)
1212
source "${script_dir}/macpython-build-common.sh"
1313

14+
# -----------------------------------------------------------------------
15+
# SCRIPT_DIR, VENVS variables are set in common script
16+
# -----------------------------------------------------------------------
17+
1418
VENV="${VENVS[0]}"
1519
PYTHON_EXECUTABLE=${VENV}/bin/python
1620
$PYTHON_EXECUTABLE -m pip install --no-cache cmake
17-
CMAKE_EXECUTABLE=${VENV}/bin/cmake
21+
# CMAKE_EXECUTABLE=${VENV}/bin/cmake
1822
$PYTHON_EXECUTABLE -m pip install --no-cache ninja
1923
NINJA_EXECUTABLE=${VENV}/bin/ninja
2024
$PYTHON_EXECUTABLE -m pip install --no-cache delocate

0 commit comments

Comments
 (0)