Skip to content

Commit fe0905d

Browse files
authored
ci: add shellcheck; fix violations (#8753)
1 parent 5ea26d5 commit fe0905d

File tree

7 files changed

+50
-39
lines changed

7 files changed

+50
-39
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ jobs:
2828
node-version: ${{ env.NODE_VERSION }}
2929
- run: npm run eslint
3030

31+
shellcheck:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v3
35+
- run: sudo apt-get install shellcheck
36+
- run: git ls-files '*.sh' | xargs shellcheck
37+
3138
# Run the integration, find and mapreduce tests against CouchDB on Node.js.
3239
# This should be run against every version of CouchDB and every version of
3340
# Node.js we support.

bin/build-node.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash -e
22

33
# don't bother doing this in GHA because it's already been built
4-
if [ -z $GITHUB_REPOSITORY ]; then
4+
if [ -z "$GITHUB_REPOSITORY" ]; then
55
BUILD_NODE=1 npm run build-modules
66
fi

bin/publish-packages.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ publish_packages () {
99
return 0
1010
fi
1111

12+
# shellcheck disable=SC2207
1213
local pkgs=($(cat "$todo"))
1314
local failed='n'
1415

@@ -43,7 +44,7 @@ should_publish () {
4344

4445
if [ ! -d "packages/node_modules/$pkg" ]; then
4546
return 1
46-
elif [ "true" = $(node --eval "console.log(require('./packages/node_modules/$pkg/package.json').private);") ]; then
47+
elif [ "true" = "$(node --eval "console.log(require('./packages/node_modules/$pkg/package.json').private);")" ]; then
4748
return 1
4849
else
4950
return 0

bin/release.sh

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

3-
if [ ! -z $DRY_RUN ]; then
3+
if [ -n "$DRY_RUN" ]; then
44
echo "Doing a dry run release..."
5-
elif [ ! -z $BETA ]; then
5+
elif [ -n "$BETA" ]; then
66
echo "Doing a beta release to npm..."
77
else
88
echo "Doing a real release! Use DRY_RUN=1 for a dry run instead."
@@ -30,20 +30,20 @@ ls packages/node_modules > release-todo.txt
3030
# Create git tag, which is also the Bower/Github release
3131
rm -fr lib src dist bower.json component.json package.json
3232
cp -r packages/node_modules/pouchdb/{src,lib,dist,bower.json,component.json,package.json} .
33-
git add -f lib src dist *.json
33+
git add -f -- lib src dist *.json
3434
git rm -fr packages bin docs scripts tests
3535

3636
git commit -m "build $VERSION"
3737

3838
# Only "publish" to GitHub/Bower if this is a non-beta non-dry run
39-
if [ -z $DRY_RUN ]; then
40-
if [ -z $BETA ]; then
39+
if [ -z "$DRY_RUN" ]; then
40+
if [ -z "$BETA" ]; then
4141
# Tag and push
42-
git tag $VERSION
43-
git push --tags git@github.com:pouchdb/pouchdb.git $VERSION
42+
git tag "$VERSION"
43+
git push --tags git@github.com:pouchdb/pouchdb.git "$VERSION"
4444

4545
# Cleanup
46-
git checkout $SOURCE_DIR
46+
git checkout "$SOURCE_DIR"
4747
git branch -D $BUILD_DIR
4848
fi
4949
fi

bin/run-test.sh

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
#!/bin/bash -e
2+
shopt -s nullglob
23

34
cleanup() {
4-
if [[ ! -z $SERVER_PID ]]; then
5-
kill $SERVER_PID
5+
if [[ -n $SERVER_PID ]]; then
6+
kill "$SERVER_PID"
67
fi
78
}
89
trap cleanup EXIT
910

1011
# Run tests against a local setup of pouchdb-express-router
1112
# by default unless COUCH_HOST is specified.
12-
[ -z "$COUCH_HOST" -a -z "$SERVER" ] && SERVER="pouchdb-express-router"
13+
if [ -z "$COUCH_HOST" ] && [ -z "$SERVER" ]; then
14+
SERVER="pouchdb-express-router"
15+
fi
1316

14-
: ${CLIENT:="node"}
15-
: ${COUCH_HOST:="http://127.0.0.1:5984"}
16-
: ${VIEW_ADAPTERS:="memory"}
17+
: "${CLIENT:=node}"
18+
: "${COUCH_HOST:=http://127.0.0.1:5984}"
19+
: "${VIEW_ADAPTERS:=memory}"
1720
export VIEW_ADAPTERS
1821

1922
pouchdb-setup-server() {
@@ -34,9 +37,9 @@ pouchdb-setup-server() {
3437

3538
TESTDIR=./tests/pouchdb_server
3639
rm -rf $TESTDIR && mkdir -p $TESTDIR
37-
FLAGS="$POUCHDB_SERVER_FLAGS --dir $TESTDIR"
38-
echo -e "Starting up pouchdb-server with flags: $FLAGS \n"
39-
./pouchdb-server-install/node_modules/.bin/pouchdb-server -n -p 6984 $FLAGS &
40+
FLAGS=("$POUCHDB_SERVER_FLAGS" --dir "$TESTDIR")
41+
echo -e "Starting up pouchdb-server with flags: ${FLAGS[*]} \n"
42+
./pouchdb-server-install/node_modules/.bin/pouchdb-server -n -p 6984 "${FLAGS[@]}" &
4043
export SERVER_PID=$!
4144
}
4245

@@ -54,8 +57,8 @@ pouchdb-link-server-modules() {
5457
fi
5558

5659
# internal node_modules of other packages
57-
for subPkg in $(ls -d node_modules/**/node_modules/${pkg}/ 2>/dev/null); do
58-
cd ${subPkg}../..
60+
for subPkg in node_modules/**/node_modules/"$pkg"; do
61+
cd "$subPkg/../.."
5962
echo -e "\nnpm link ${pkg} for ${subPkg}"
6063
npm link "${pkg}"
6164
cd ../..
@@ -79,7 +82,7 @@ pouchdb-build-node() {
7982
fi
8083
}
8184

82-
if [[ ! -z $SERVER ]]; then
85+
if [[ -n $SERVER ]]; then
8386
if [ "$SERVER" == "pouchdb-server" ]; then
8487
export COUCH_HOST='http://127.0.0.1:6984'
8588
if [[ -n "$GITHUB_REPOSITORY" || "$COVERAGE" == 1 ]]; then
@@ -110,22 +113,22 @@ if [[ ! -z $SERVER ]]; then
110113
fi
111114

112115
if [ "$SERVER" == "couchdb-master" ]; then
113-
while [ '200' != $(curl -s -o /dev/null -w %{http_code} ${COUCH_HOST}) ]; do
116+
while [ '200' != "$(curl -s -o /dev/null -w '%{http_code}' ${COUCH_HOST})" ]; do
114117
echo waiting for couch to load... ;
115118
sleep 1;
116119
done
117120

118121
./node_modules/.bin/add-cors-to-couchdb $COUCH_HOST
119122
fi
120123

121-
printf "Waiting for host to start on $COUCH_HOST..."
124+
printf "Waiting for host to start on %s..." "$COUCH_HOST"
122125
WAITING=0
123-
until $(curl --output /dev/null --silent --head --fail --max-time 2 $COUCH_HOST); do
126+
until curl --output /dev/null --silent --head --fail --max-time 2 $COUCH_HOST; do
124127
if [ $WAITING -eq 4 ]; then
125128
printf '\nHost failed to start\n'
126129
exit 1
127130
fi
128-
let WAITING=WAITING+1
131+
((WAITING=WAITING+1))
129132
printf '.'
130133
sleep 5
131134
done

bin/test-node.sh

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

3-
: ${TIMEOUT:=5000}
4-
: ${REPORTER:="spec"}
5-
: ${BAIL:=1}
6-
: ${TYPE:="integration"}
3+
: "${TIMEOUT:=5000}"
4+
: "${REPORTER:="spec"}"
5+
: "${BAIL:=1}"
6+
: "${TYPE:="integration"}"
77

88
if [ $BAIL -eq 1 ]; then
99
BAIL_OPT="--bail"
@@ -29,41 +29,41 @@ fi
2929
if [ $TYPE = "find" ]; then
3030
TESTS_PATH="tests/find/*/test.*.js"
3131
fi
32-
if [ $COVERAGE ]; then
32+
if [ "$COVERAGE" ]; then
3333
# run all tests when testing for coverage
3434
TESTS_PATH="tests/{unit,integration,mapreduce,component}/test*.js tests/find/*/test.*.js"
3535
fi
3636

37-
if [ $PERF ]; then
37+
if [ "$PERF" ]; then
3838
node tests/performance/index.js
39-
elif [ ! $COVERAGE ]; then
39+
elif [ ! "$COVERAGE" ]; then
4040
# --exit required to workaround #8839
4141
./node_modules/.bin/mocha \
4242
--exit \
43-
$BAIL_OPT \
43+
"$BAIL_OPT" \
4444
--timeout "$TIMEOUT" \
4545
--require=./tests/integration/node.setup.js \
4646
--reporter="$REPORTER" \
4747
--grep="$GREP" \
48-
$TESTS_PATH
48+
"$TESTS_PATH"
4949
else
5050
# --exit required to workaround #8839
5151
./node_modules/.bin/istanbul cover \
5252
--no-default-excludes -x 'tests/**' -x 'node_modules/**' \
5353
./node_modules/mocha/bin/_mocha -- \
5454
--exit \
55-
$BAIL_OPT \
55+
"$BAIL_OPT" \
5656
--timeout "$TIMEOUT" \
5757
--require=./tests/integration/node.setup.js \
5858
--reporter="$REPORTER" \
5959
--grep="$GREP" \
60-
$TESTS_PATH
60+
"$TESTS_PATH"
6161

6262
./node_modules/.bin/istanbul check-coverage --line 100
6363
fi
6464

6565
EXIT_STATUS=$?
66-
if [[ ! -z $DOWN_SERVER_PID ]]; then
66+
if [[ -n $DOWN_SERVER_PID ]]; then
6767
kill $DOWN_SERVER_PID
6868
fi
6969
exit $EXIT_STATUS

bin/verify-bundle-size.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ MAX=50000
66

77
# testing pouchdb.js instead of pouchdb.min.js because minification isn't run in Travis
88
# in order to make our builds faster
9-
SIZE=`./node_modules/.bin/terser -mc < packages/node_modules/pouchdb/dist/pouchdb.js 2>/dev/null | gzip -c | wc -c`
9+
SIZE=$(./node_modules/.bin/terser -mc < packages/node_modules/pouchdb/dist/pouchdb.js 2>/dev/null | gzip -c | wc -c)
1010

1111
echo "Checking that pouchdb.min.js size $SIZE is less than $MAX and greater than 20"
1212

0 commit comments

Comments
 (0)