Skip to content

Commit 14aded4

Browse files
committed
script: Lint Gitian descriptors with ShellCheck
1 parent 22a5881 commit 14aded4

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

ci/lint/04_install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Copyright (c) 2018-2019 The Bitcoin Core developers
44
# Distributed under the MIT software license, see the accompanying
55
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
66

77
export LC_ALL=C
88

99
travis_retry pip3 install codespell==1.15.0
1010
travis_retry pip3 install flake8==3.7.8
11+
travis_retry pip3 install yq
1112

1213
SHELLCHECK_VERSION=v0.6.0
1314
curl -s "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" | tar --xz -xf - --directory /tmp/

test/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ Use the `-v` option for verbose output.
258258
|-----------|:----------:|:-------------------------------------------:|--------------
259259
| [`lint-python.sh`](lint/lint-python.sh) | [flake8](https://gitlab.com/pycqa/flake8) | [3.7.8](https://github.com/bitcoin/bitcoin/pull/15257) | `pip3 install flake8==3.7.8`
260260
| [`lint-shell.sh`](lint/lint-shell.sh) | [ShellCheck](https://github.com/koalaman/shellcheck) | [0.6.0](https://github.com/bitcoin/bitcoin/pull/15166) | [details...](https://github.com/koalaman/shellcheck#installing)
261+
| [`lint-shell.sh`](lint/lint-shell.sh) | [yq](https://github.com/kislyuk/yq) | default | `pip3 install yq`
261262
| [`lint-spelling.sh`](lint/lint-spelling.sh) | [codespell](https://github.com/codespell-project/codespell) | [1.15.0](https://github.com/bitcoin/bitcoin/pull/16186) | `pip3 install codespell==1.15.0`
262263

263264
Please be aware that on Linux distributions all dependencies are usually available as packages, but could be outdated.

test/lint/lint-shell.sh

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22
#
3-
# Copyright (c) 2018 The Bitcoin Core developers
3+
# Copyright (c) 2018-2019 The Bitcoin Core developers
44
# Distributed under the MIT software license, see the accompanying
55
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
66
#
@@ -16,16 +16,48 @@ if [ "$TRAVIS" = "true" ]; then
1616
unset LC_ALL
1717
fi
1818

19-
if ! command -v shellcheck > /dev/null; then
20-
echo "Skipping shell linting since shellcheck is not installed."
21-
exit 0
22-
fi
23-
2419
# Disabled warnings:
2520
disabled=(
2621
SC2046 # Quote this to prevent word splitting.
2722
SC2086 # Double quote to prevent globbing and word splitting.
2823
SC2162 # read without -r will mangle backslashes.
2924
)
30-
shellcheck -e "$(IFS=","; echo "${disabled[*]}")" \
31-
$(git ls-files -- "*.sh" | grep -vE 'src/(secp256k1|univalue)/')
25+
disabled_gitian=(
26+
SC2001 # See if you can use ${variable//search/replace} instead.
27+
SC2006 # Use $(...) notation instead of legacy backticked `...`.
28+
SC2094 # Make sure not to read and write the same file in the same pipeline.
29+
SC2129 # Consider using { cmd1; cmd2; } >> file instead of individual redirects.
30+
SC2155 # Declare and assign separately to avoid masking return values.
31+
SC2230 # which is non-standard. Use builtin 'command -v' instead.
32+
)
33+
34+
EXIT_CODE=0
35+
36+
if ! command -v shellcheck > /dev/null; then
37+
echo "Skipping shell linting since shellcheck is not installed."
38+
exit $EXIT_CODE
39+
fi
40+
41+
EXCLUDE="--exclude=$(IFS=','; echo "${disabled[*]}")"
42+
if ! shellcheck "$EXCLUDE" $(git ls-files -- '*.sh' | grep -vE 'src/(leveldb|secp256k1|univalue)/'); then
43+
EXIT_CODE=1
44+
fi
45+
46+
if ! command -v yq > /dev/null; then
47+
echo "Skipping Gitian desriptor scripts checking since yq is not installed."
48+
exit $EXIT_CODE
49+
fi
50+
51+
EXCLUDE_GITIAN=${EXCLUDE}",$(IFS=','; echo "${disabled_gitian[*]}")"
52+
for descriptor in $(git ls-files -- 'contrib/gitian-descriptors/*.yml')
53+
do
54+
echo
55+
echo "$descriptor"
56+
# Use #!/bin/bash as gitian-builder/bin/gbuild does to complete a script.
57+
SCRIPT=$'#!/bin/bash\n'$(yq -r .script "$descriptor")
58+
if ! echo "$SCRIPT" | shellcheck "$EXCLUDE_GITIAN" -; then
59+
EXIT_CODE=1
60+
fi
61+
done
62+
63+
exit $EXIT_CODE

0 commit comments

Comments
 (0)