Skip to content

Commit c20f604

Browse files
committed
[Travis] Add separate job to check doc/logprint/subtree
Break out a new job to do the basic linting that check-dock.py and logprint-scanner.py did. Also add new scripts to check the sanity of any git subtrees and to check that new pull requests don't contain any trailing whitespace. Also, remove the outdated slack notification callback Github-Pull: #639 Rebased-From: 6f695b5
1 parent f3c8c6a commit c20f604

File tree

3 files changed

+235
-8
lines changed

3 files changed

+235
-8
lines changed

.travis.yml

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ cache:
77
- depends/built
88
- depends/sdk-sources
99
- $HOME/.ccache
10+
stages:
11+
- lint
12+
- test
1013
env:
1114
global:
1215
- MAKEJOBS=-j3
1316
- RUN_TESTS=false
14-
- CHECK_DOC=0
15-
- CHECK_LOGPRINT=0
1617
- BOOST_TEST_RANDOM=1$TRAVIS_BUILD_ID
1718
- CCACHE_SIZE=100M
1819
- CCACHE_TEMPDIR=/tmp/.ccache-temp
@@ -22,7 +23,7 @@ env:
2223
- WINEDEBUG=fixme-all
2324
matrix:
2425
# ARM
25-
- HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" CHECK_DOC=1 CHECK_LOGPRINT=1 GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
26+
- HOST=arm-linux-gnueabihf PACKAGES="g++-arm-linux-gnueabihf" GOAL="install" BITCOIN_CONFIG="--enable-glibc-back-compat --enable-reduce-exports"
2627
# Win32
2728
- HOST=i686-w64-mingw32 DPKG_ADD_ARCH="i386" DEP_OPTS="NO_QT=1" PACKAGES="python3 nsis g++-mingw-w64-i686 wine1.6 bc" RUN_TESTS=true GOAL="install" BITCOIN_CONFIG="--enable-reduce-exports"
2829
# 32-bit + dash
@@ -44,8 +45,6 @@ install:
4445
- if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get update; fi
4546
- if [ -n "$PACKAGES" ]; then travis_retry sudo apt-get install --no-install-recommends --no-upgrade -qq $PACKAGES; fi
4647
before_script:
47-
- if [ "$CHECK_DOC" = 1 ]; then contrib/devtools/check-doc.py; fi
48-
- if [ "$CHECK_LOGPRINT" = 1 ]; then contrib/devtools/logprint-scanner.py; fi
4948
- unset CC; unset CXX
5049
- mkdir -p depends/SDKs depends/sdk-sources
5150
- if [ -n "$OSX_SDK" -a ! -f depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz ]; then curl --location --fail $SDK_URL/MacOSX${OSX_SDK}.sdk.tar.gz -o depends/sdk-sources/MacOSX${OSX_SDK}.sdk.tar.gz; fi
@@ -69,6 +68,26 @@ script:
6968
after_script:
7069
- echo $TRAVIS_COMMIT_RANGE
7170
- echo $TRAVIS_COMMIT_LOG
72-
notifications:
73-
slack:
74-
secure: w22XjHoG/3xplxWzddS9Ma7i99Q/hq4FA3Q56xS+RtO2vlFgDT+eDzCppstdx96mn2/4e+/V1aiQ4E6GVEvJMeldqSUhPv9OBnKR0KJVAOwu4haNXt+0ZeQFt8lIndKB5cMVyOJkoq6peGoHNXslClM0lGuBn7g7VC2QPQYNWrJNrrGL7IiVb6fNOIKHWcC4URkzSvXAhO/WIqSSlmKxAAx0B2oEsM8LhdAbcjbp7Sm7zH87TIVGBZ7iTVuMc6B9+SfClbE8bBuRtvjTX57Q4UUZzn0zDtKdPdCte0oXdaQF4RdVim9mDodBGIpDo+avW4WL7EE+AK33fs94pwH5bu0LEandR/aeEvVpbSpQ2XsEKSe+6woizgl5i4GXFVZduJF62y/o1f+S/zC3qW9lIEEpiZc4PpX7pDy30X3p6S5nMrW7T/zNh+SjLhS1VP6XKdQtpD3WRCY4GKZYammZhk5RbOy3jTXAahIXuttWdhl/Q3Rb5VqfFJWlrG/qQXt73qOk2/DgJnABxXE6gnWO4MpHAq+kdomNR+nod4HeXI3DOk1wRuQRVoW1rSjiqQd6Db+TP56RKYgt4M4csOD0DG9G+W0AOtZkuKHTeoEtmQfkKFPZLYAQumv41cDN2UE9gKIECmvJSevj4sMCDTWtozKWqay/W4n2+cmhbzmGflY=
71+
72+
jobs:
73+
include:
74+
- stage: lint
75+
sudo: false
76+
cache: false
77+
addons:
78+
apt:
79+
packages:
80+
- python3-pip
81+
- shellcheck
82+
install:
83+
- travis_retry pip3 install flake8 --user
84+
before_script:
85+
- git fetch --unshallow
86+
script:
87+
- contrib/devtools/git-subtree-check.sh src/univalue
88+
# Remove this comment and the `#` from the following two lines when we merge proper subtree implementations for secp256k1 and leveldb
89+
#- contrib/devtools/git-subtree-check.sh src/secp256k1
90+
#- contrib/devtools/git-subtree-check.sh src/leveldb
91+
- contrib/devtools/check-doc.py
92+
- contrib/devtools/logprint-scanner.py
93+
- if [ "$TRAVIS_EVENT_TYPE" = "pull_request" ]; then contrib/devtools/lint-whitespace.sh; fi
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/sh
2+
# Copyright (c) 2015 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
export LC_ALL=C
7+
DIR="$1"
8+
COMMIT="$2"
9+
if [ -z "$COMMIT" ]; then
10+
COMMIT=HEAD
11+
fi
12+
13+
# Taken from git-subtree (Copyright (C) 2009 Avery Pennarun <[email protected]>)
14+
find_latest_squash()
15+
{
16+
dir="$1"
17+
sq=
18+
main=
19+
sub=
20+
git log --grep="^git-subtree-dir: $dir/*\$" \
21+
--pretty=format:'START %H%n%s%n%n%b%nEND%n' "$COMMIT" |
22+
while read a b _; do
23+
case "$a" in
24+
START) sq="$b" ;;
25+
git-subtree-mainline:) main="$b" ;;
26+
git-subtree-split:) sub="$b" ;;
27+
END)
28+
if [ -n "$sub" ]; then
29+
if [ -n "$main" ]; then
30+
# a rejoin commit?
31+
# Pretend its sub was a squash.
32+
sq="$sub"
33+
fi
34+
echo "$sq" "$sub"
35+
break
36+
fi
37+
sq=
38+
main=
39+
sub=
40+
;;
41+
esac
42+
done
43+
}
44+
45+
# find latest subtree update
46+
latest_squash="$(find_latest_squash "$DIR")"
47+
if [ -z "$latest_squash" ]; then
48+
echo "ERROR: $DIR is not a subtree" >&2
49+
exit 2
50+
fi
51+
set $latest_squash
52+
old=$1
53+
rev=$2
54+
55+
# get the tree in the current commit
56+
tree_actual=$(git ls-tree -d "$COMMIT" "$DIR" | head -n 1)
57+
if [ -z "$tree_actual" ]; then
58+
echo "FAIL: subtree directory $DIR not found in $COMMIT" >&2
59+
exit 1
60+
fi
61+
set $tree_actual
62+
tree_actual_type=$2
63+
tree_actual_tree=$3
64+
echo "$DIR in $COMMIT currently refers to $tree_actual_type $tree_actual_tree"
65+
if [ "d$tree_actual_type" != "dtree" ]; then
66+
echo "FAIL: subtree directory $DIR is not a tree in $COMMIT" >&2
67+
exit 1
68+
fi
69+
70+
# get the tree at the time of the last subtree update
71+
tree_commit=$(git show -s --format="%T" $old)
72+
echo "$DIR in $COMMIT was last updated in commit $old (tree $tree_commit)"
73+
74+
# ... and compare the actual tree with it
75+
if [ "$tree_actual_tree" != "$tree_commit" ]; then
76+
git diff $tree_commit $tree_actual_tree >&2
77+
echo "FAIL: subtree directory was touched without subtree merge" >&2
78+
exit 1
79+
fi
80+
81+
# get the tree in the subtree commit referred to
82+
if [ "d$(git cat-file -t $rev 2>/dev/null)" != dcommit ]; then
83+
echo "subtree commit $rev unavailable: cannot compare" >&2
84+
exit
85+
fi
86+
tree_subtree=$(git show -s --format="%T" $rev)
87+
echo "$DIR in $COMMIT was last updated to upstream commit $rev (tree $tree_subtree)"
88+
89+
# ... and compare the actual tree with it
90+
if [ "$tree_actual_tree" != "$tree_subtree" ]; then
91+
echo "FAIL: subtree update commit differs from upstream tree!" >&2
92+
exit 1
93+
fi
94+
95+
echo "GOOD"
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#!/bin/bash
2+
#
3+
# Copyright (c) 2017 The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
#
7+
# Check for new lines in diff that introduce trailing whitespace.
8+
9+
# We can't run this check unless we know the commit range for the PR.
10+
11+
export LC_ALL=C
12+
while getopts "?" opt; do
13+
case $opt in
14+
?)
15+
echo "Usage: .lint-whitespace.sh [N]"
16+
echo " TRAVIS_COMMIT_RANGE='<commit range>' .lint-whitespace.sh"
17+
echo " .lint-whitespace.sh -?"
18+
echo "Checks unstaged changes, the previous N commits, or a commit range."
19+
echo "TRAVIS_COMMIT_RANGE='47ba2c3...ee50c9e' .lint-whitespace.sh"
20+
exit 0
21+
;;
22+
esac
23+
done
24+
25+
if [ -z "${TRAVIS_COMMIT_RANGE}" ]; then
26+
if [ "$1" ]; then
27+
TRAVIS_COMMIT_RANGE="HEAD~$1...HEAD"
28+
else
29+
TRAVIS_COMMIT_RANGE="HEAD"
30+
fi
31+
fi
32+
33+
showdiff() {
34+
if ! git diff -U0 "${TRAVIS_COMMIT_RANGE}" -- "." ":(exclude)depends/patches/" ":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/"; then
35+
echo "Failed to get a diff"
36+
exit 1
37+
fi
38+
}
39+
40+
showcodediff() {
41+
if ! git diff -U0 "${TRAVIS_COMMIT_RANGE}" -- *.cpp *.h *.md *.py *.sh ":(exclude)src/leveldb/" ":(exclude)src/secp256k1/" ":(exclude)src/univalue/" ":(exclude)doc/release-notes/"; then
42+
echo "Failed to get a diff"
43+
exit 1
44+
fi
45+
}
46+
47+
RET=0
48+
49+
# Check if trailing whitespace was found in the diff.
50+
if showdiff | grep -E -q '^\+.*\s+$'; then
51+
echo "This diff appears to have added new lines with trailing whitespace."
52+
echo "The following changes were suspected:"
53+
FILENAME=""
54+
SEEN=0
55+
SEENLN=0
56+
while read -r line; do
57+
if [[ "$line" =~ ^diff ]]; then
58+
FILENAME="$line"
59+
SEEN=0
60+
elif [[ "$line" =~ ^@@ ]]; then
61+
LINENUMBER="$line"
62+
SEENLN=0
63+
else
64+
if [ "$SEEN" -eq 0 ]; then
65+
# The first time a file is seen with trailing whitespace, we print the
66+
# filename (preceded by a newline).
67+
echo
68+
echo "$FILENAME"
69+
SEEN=1
70+
fi
71+
if [ "$SEENLN" -eq 0 ]; then
72+
echo "$LINENUMBER"
73+
SEENLN=1
74+
fi
75+
echo "$line"
76+
fi
77+
done < <(showdiff | grep -E '^(diff --git |@@|\+.*\s+$)')
78+
RET=1
79+
fi
80+
81+
# Check if tab characters were found in the diff.
82+
if showcodediff | perl -nle '$MATCH++ if m{^\+.*\t}; END{exit 1 unless $MATCH>0}' > /dev/null; then
83+
echo "This diff appears to have added new lines with tab characters instead of spaces."
84+
echo "The following changes were suspected:"
85+
FILENAME=""
86+
SEEN=0
87+
SEENLN=0
88+
while read -r line; do
89+
if [[ "$line" =~ ^diff ]]; then
90+
FILENAME="$line"
91+
SEEN=0
92+
elif [[ "$line" =~ ^@@ ]]; then
93+
LINENUMBER="$line"
94+
SEENLN=0
95+
else
96+
if [ "$SEEN" -eq 0 ]; then
97+
# The first time a file is seen with a tab character, we print the
98+
# filename (preceded by a newline).
99+
echo
100+
echo "$FILENAME"
101+
SEEN=1
102+
fi
103+
if [ "$SEENLN" -eq 0 ]; then
104+
echo "$LINENUMBER"
105+
SEENLN=1
106+
fi
107+
echo "$line"
108+
fi
109+
done < <(showcodediff | perl -nle 'print if m{^(diff --git |@@|\+.*\t)}')
110+
RET=1
111+
fi
112+
113+
exit $RET

0 commit comments

Comments
 (0)