Merge pull request #4514 from alive4ever/mksh-R55
[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.4.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 ("$@" 2>&1) > logoutput && status=0 || status=1
18 grep -qE 'WARNING|ERROR' logoutput && status=1
19 cat logoutput
20 if [ $status -eq 0 ]; then
21 echo_green "=> $* successful"
22 return 0
23 else
24 echo_red "=> $* failed"
25 return 1
26 fi
27 }
28
29 # download will run on the `before_script` step
30 # The travis cache will be used (all files under $HOME/sdk/). Meaning
31 # We don't have to download the file again
32 download_sdk() {
33 mkdir -p "$SDK_HOME"
34 cd "$SDK_HOME"
35
36 echo_blue "=== download SDK"
37 wget "$SDK_PATH/sha256sums" -O sha256sums
38 wget "$SDK_PATH/sha256sums.gpg" -O sha256sums.asc
39
40 # LEDE Build System (LEDE GnuPG key for unattended build jobs)
41 gpg --recv 0xCD84BCED626471F1
42 # LEDE Release Builder (17.01 "Reboot" Signing Key)
43 gpg --recv 0x833C6010D52BBB6B
44 gpg --verify sha256sums.asc
45 grep "$SDK" sha256sums > sha256sums.small
46
47 # if missing, outdated or invalid, download again
48 if ! sha256sum -c ./sha256sums.small ; then
49 wget "$SDK_PATH/$SDK.tar.xz" -O "$SDK.tar.xz"
50 fi
51
52 # check again and fail here if the file is still bad
53 sha256sum -c ./sha256sums.small
54 echo_blue "=== SDK is up-to-date"
55 }
56
57 # test_package will run on the `script` step.
58 # test_package call make download check for very new/modified package
59 test_packages2() {
60 # search for new or modified packages. PKGS will hold a list of package like 'admin/muninlite admin/monit ...'
61 PKGS=$(git diff --diff-filter=d --name-only "$TRAVIS_COMMIT_RANGE" | grep 'Makefile$' | grep -v '/files/' | awk -F'/Makefile' '{ print $1 }')
62
63 if [ -z "$PKGS" ] ; then
64 echo_blue "No new or modified packages found!"
65 return 0
66 fi
67
68 echo_blue "=== Found new/modified packages:"
69 for pkg in $PKGS ; do
70 echo "===+ $pkg"
71 done
72
73 echo_blue "=== Setting up SDK"
74 tmp_path=$(mktemp -d)
75 cd "$tmp_path"
76 tar Jxf "$SDK_HOME/$SDK.tar.xz" --strip=1
77
78 # use github mirrors to spare lede servers
79 cat > feeds.conf <<EOF
80 src-git base https://github.com/lede-project/source.git
81 src-link packages $PACKAGES_DIR
82 src-git luci https://github.com/openwrt/luci.git
83 EOF
84
85 ./scripts/feeds update -a
86 ./scripts/feeds install -a
87 make defconfig
88 echo_blue "=== Setting up SDK done"
89
90 RET=0
91 # E.g: pkg_dir => admin/muninlite
92 # pkg_name => muninlite
93 for pkg_dir in $PKGS ; do
94 pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
95 echo_blue "=== $pkg_name Testing package"
96
97 exec_status make "package/$pkg_name/download" V=s || RET=1
98 exec_status make "package/$pkg_name/check" V=s || RET=1
99
100 echo_blue "=== $pkg_name Finished package"
101 done
102
103 return $RET
104 }
105
106 test_commits() {
107 RET=0
108 for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE/.../..}); do
109 echo_blue "=== Checking commit '$commit'"
110 if git show --format='%P' -s $commit | grep -qF ' '; then
111 echo_red "Pull request should not include merge commits"
112 RET=1
113 fi
114
115 author="$(git show -s --format=%aN $commit)"
116 if echo $author | grep -q '\S\+\s\+\S\+'; then
117 echo_green "Author name ($author) seems ok"
118 else
119 echo_red "Author name ($author) need to be your real name 'firstname lastname'"
120 RET=1
121 fi
122
123 subject="$(git show -s --format=%s $commit)"
124 if echo "$subject" | grep -q '^[0-9A-Za-z,/-]\+: '; then
125 echo_green "Commit subject line seems ok ($subject)"
126 else
127 echo_red "Commit subject line MUST start with '<package name>: ' ($subject)"
128 RET=1
129 fi
130
131 body="$(git show -s --format=%b $commit)"
132 sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
133 if echo "$body" | grep -qF "$sob"; then
134 echo_green "Signed-off-by match author"
135 else
136 echo_red "Signed-off-by is missing or doesn't match author (should be '$sob')"
137 RET=1
138 fi
139 done
140
141 return $RET
142 }
143
144 test_packages() {
145 GRET=0
146 test_commits || GRET=1
147 test_packages2 || GRET=1
148 return $GRET
149 }
150
151 echo_blue "=== Travis ENV"
152 env
153 echo_blue "=== Travis ENV"
154
155 until [ "$(git rev-list ${TRAVIS_COMMIT_RANGE/.../..} | tail -n1)" != "a22de9b74cf9579d1ce7e6cf1845b4afa4277b00" ]; do
156 # if clone depth is too small, git rev-list / diff return incorrect results
157 echo_blue "Fetching 50 commits more"
158 git fetch origin --deepen=50
159 done
160
161 if [ "$TRAVIS_PULL_REQUEST" = false ] ; then
162 echo "Only Pull Requests are supported at the moment." >&2
163 exit 0
164 fi
165
166
167 if [ $# -ne 1 ] ; then
168 cat <<EOF
169 Usage: $0 (download_sdk|test_packages)
170
171 download_sdk - download the SDK to $HOME/sdk.tar.xz
172 test_packages - do a make check on the package
173 EOF
174 exit 1
175 fi
176
177 $@