Merge pull request #4940 from diizzyy/patch-95
[feed/packages.git] / .travis_do.sh
1 #!/bin/bash
2 #
3 # MIT Alexander Couzens <lynxis@fe80.eu>
4
5 set -e
6
7 SDK_HOME="$HOME/sdk"
8 SDK_PATH=https://downloads.lede-project.org/snapshots/targets/ar71xx/generic/
9 SDK=lede-sdk-ar71xx-generic_gcc-5.5.0_musl.Linux-x86_64
10 PACKAGES_DIR="$PWD"
11
12 echo_red() { printf "\033[1;31m$*\033[m\n"; }
13 echo_green() { printf "\033[1;32m$*\033[m\n"; }
14 echo_blue() { printf "\033[1;34m$*\033[m\n"; }
15
16 exec_status() {
17 PATTERN="$1"
18 shift
19 while :;do sleep 590;echo "still running (please don't kill me Travis)";done &
20 ("$@" 2>&1) | tee logoutput
21 R=${PIPESTATUS[0]}
22 kill $! && wait $! 2>/dev/null
23 if [ $R -ne 0 ]; then
24 echo_red "=> '$*' failed (return code $R)"
25 return 1
26 fi
27 if grep -qE "$PATTERN" logoutput; then
28 echo_red "=> '$*' failed (log matched '$PATTERN')"
29 return 1
30 fi
31
32 echo_green "=> '$*' successful"
33 return 0
34 }
35
36 # download will run on the `before_script` step
37 # The travis cache will be used (all files under $HOME/sdk/). Meaning
38 # We don't have to download the file again
39 download_sdk() {
40 mkdir -p "$SDK_HOME"
41 cd "$SDK_HOME"
42
43 echo_blue "=== download SDK"
44 wget "$SDK_PATH/sha256sums" -O sha256sums
45 wget "$SDK_PATH/sha256sums.gpg" -O sha256sums.asc
46
47 # LEDE Build System (LEDE GnuPG key for unattended build jobs)
48 gpg --import $PACKAGES_DIR/.travis/626471F1.asc
49 echo '54CC74307A2C6DC9CE618269CD84BCED626471F1:6:' | gpg --import-ownertrust
50 # LEDE Release Builder (17.01 "Reboot" Signing Key)
51 gpg --import $PACKAGES_DIR/.travis/D52BBB6B.asc
52 echo 'B09BE781AE8A0CD4702FDCD3833C6010D52BBB6B:6:' | gpg --import-ownertrust
53
54 gpg --verify sha256sums.asc
55 grep "$SDK" sha256sums > sha256sums.small
56
57 # if missing, outdated or invalid, download again
58 if ! sha256sum -c ./sha256sums.small ; then
59 wget "$SDK_PATH/$SDK.tar.xz" -O "$SDK.tar.xz"
60 fi
61
62 # check again and fail here if the file is still bad
63 sha256sum -c ./sha256sums.small
64 echo_blue "=== SDK is up-to-date"
65 }
66
67 # test_package will run on the `script` step.
68 # test_package call make download check for very new/modified package
69 test_packages2() {
70 # search for new or modified packages. PKGS will hold a list of package like 'admin/muninlite admin/monit ...'
71 PKGS=$(git diff --diff-filter=d --name-only "$TRAVIS_COMMIT_RANGE" | grep 'Makefile$' | grep -v '/files/' | awk -F'/Makefile' '{ print $1 }')
72
73 if [ -z "$PKGS" ] ; then
74 echo_blue "No new or modified packages found!"
75 return 0
76 fi
77
78 echo_blue "=== Found new/modified packages:"
79 for pkg in $PKGS ; do
80 echo "===+ $pkg"
81 done
82
83 echo_blue "=== Setting up SDK"
84 tmp_path=$(mktemp -d)
85 cd "$tmp_path"
86 tar Jxf "$SDK_HOME/$SDK.tar.xz" --strip=1
87
88 # use github mirrors to spare lede servers
89 cat > feeds.conf <<EOF
90 src-git base https://github.com/lede-project/source.git
91 src-link packages $PACKAGES_DIR
92 src-git luci https://github.com/openwrt/luci.git
93 EOF
94
95 # enable BUILD_LOG
96 sed -i '1s/^/config BUILD_LOG\n\tbool\n\tdefault y\n\n/' Config-build.in
97
98 ./scripts/feeds update -a > /dev/null
99 ./scripts/feeds install -a > /dev/null
100 make defconfig > /dev/null
101 echo_blue "=== Setting up SDK done"
102
103 RET=0
104 # E.g: pkg_dir => admin/muninlite
105 # pkg_name => muninlite
106 for pkg_dir in $PKGS ; do
107 pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
108 echo_blue "=== $pkg_name: Starting quick tests"
109
110 exec_status 'WARNING|ERROR' make "package/$pkg_name/download" V=s || RET=1
111 exec_status 'WARNING|ERROR' make "package/$pkg_name/check" V=s || RET=1
112
113 echo_blue "=== $pkg_name: quick tests done"
114 done
115
116 [ $RET -ne 0 ] && return $RET
117
118 for pkg_dir in $PKGS ; do
119 pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
120 echo_blue "=== $pkg_name: Starting compile test"
121
122 # we can't enable verbose built else we often hit Travis limits
123 # on log size and the job get killed
124 exec_status '^ERROR' make "package/$pkg_name/compile" -j3 || RET=1
125
126 echo_blue "=== $pkg_name: compile test done"
127
128 echo_blue "=== $pkg_name: begin compile logs"
129 for f in $(find logs/package/feeds/packages/$pkg_name/ -type f); do
130 echo_blue "Printing last 200 lines of $f"
131 tail -n200 "$f"
132 done
133 echo_blue "=== $pkg_name: end compile logs"
134
135 echo_blue "=== $pkg_name: begin packages sizes"
136 du -ba bin/
137 echo_blue "=== $pkg_name: end packages sizes"
138 done
139
140 return $RET
141 }
142
143 test_commits() {
144 RET=0
145 for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE/.../..}); do
146 echo_blue "=== Checking commit '$commit'"
147 if git show --format='%P' -s $commit | grep -qF ' '; then
148 echo_red "Pull request should not include merge commits"
149 RET=1
150 fi
151
152 author="$(git show -s --format=%aN $commit)"
153 if echo $author | grep -q '\S\+\s\+\S\+'; then
154 echo_green "Author name ($author) seems ok"
155 else
156 echo_red "Author name ($author) need to be your real name 'firstname lastname'"
157 RET=1
158 fi
159
160 subject="$(git show -s --format=%s $commit)"
161 if echo "$subject" | grep -q -e '^[0-9A-Za-z,/-]\+: ' -e '^Revert '; then
162 echo_green "Commit subject line seems ok ($subject)"
163 else
164 echo_red "Commit subject line MUST start with '<package name>: ' ($subject)"
165 RET=1
166 fi
167
168 body="$(git show -s --format=%b $commit)"
169 sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
170 if echo "$body" | grep -qF "$sob"; then
171 echo_green "Signed-off-by match author"
172 else
173 echo_red "Signed-off-by is missing or doesn't match author (should be '$sob')"
174 RET=1
175 fi
176 done
177
178 return $RET
179 }
180
181 test_packages() {
182 test_commits && test_packages2 || return 1
183 }
184
185 echo_blue "=== Travis ENV"
186 env
187 echo_blue "=== Travis ENV"
188
189 while true; do
190 # if clone depth is too small, git rev-list / diff return incorrect or empty results
191 C="$(git rev-list ${TRAVIS_COMMIT_RANGE/.../..} | tail -n1)" 2>/dev/null
192 [ -n "$C" -a "$C" != "a22de9b74cf9579d1ce7e6cf1845b4afa4277b00" ] && break
193 echo_blue "Fetching 50 commits more"
194 git fetch origin --deepen=50
195 done
196
197 if [ "$TRAVIS_PULL_REQUEST" = false ] ; then
198 echo "Only Pull Requests are supported at the moment." >&2
199 exit 0
200 fi
201
202
203 if [ $# -ne 1 ] ; then
204 cat <<EOF
205 Usage: $0 (download_sdk|test_packages)
206
207 download_sdk - download the SDK to $HOME/sdk.tar.xz
208 test_packages - do a make check on the package
209 EOF
210 exit 1
211 fi
212
213 $@