You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
5.7 KiB

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