.travis_do.sh 6.9 KB

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