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.

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