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.

219 lines
6.2 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. local commit_range=$TRAVIS_COMMIT_RANGE
  59. if [ -z "$TRAVIS_PULL_REQUEST_SHA" ]; then
  60. echo_blue "Using only the latest commit, since we're not in a Pull Request"
  61. commit_range=HEAD~1
  62. fi
  63. # search for new or modified packages. PKGS will hold a list of package like 'admin/muninlite admin/monit ...'
  64. PKGS=$(git diff --diff-filter=d --name-only "$commit_range" | grep 'Makefile$' | grep -v '/files/' | awk -F'/Makefile' '{ print $1 }')
  65. if [ -z "$PKGS" ] ; then
  66. echo_blue "No new or modified packages found!"
  67. return 0
  68. fi
  69. echo_blue "=== Found new/modified packages:"
  70. for pkg in $PKGS ; do
  71. echo "===+ $pkg"
  72. done
  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. # use github mirrors to spare lede servers
  78. cat > feeds.conf <<EOF
  79. src-git base https://github.com/lede-project/source.git
  80. src-link packages $PACKAGES_DIR
  81. src-git luci https://github.com/openwrt/luci.git
  82. EOF
  83. # enable BUILD_LOG
  84. sed -i '1s/^/config BUILD_LOG\n\tbool\n\tdefault y\n\n/' Config-build.in
  85. ./scripts/feeds update -a > /dev/null
  86. ./scripts/feeds install -a > /dev/null
  87. make defconfig > /dev/null
  88. echo_blue "=== Setting up SDK done"
  89. RET=0
  90. # E.g: pkg_dir => admin/muninlite
  91. # pkg_name => muninlite
  92. for pkg_dir in $PKGS ; do
  93. pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
  94. echo_blue "=== $pkg_name: Starting quick tests"
  95. exec_status 'WARNING|ERROR' make "package/$pkg_name/download" V=s || RET=1
  96. exec_status 'WARNING|ERROR' make "package/$pkg_name/check" V=s || RET=1
  97. echo_blue "=== $pkg_name: quick tests done"
  98. done
  99. [ $RET -ne 0 ] && return $RET
  100. for pkg_dir in $PKGS ; do
  101. pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
  102. echo_blue "=== $pkg_name: Starting compile test"
  103. # we can't enable verbose built else we often hit Travis limits
  104. # on log size and the job get killed
  105. exec_status '^ERROR' make "package/$pkg_name/compile" -j3 || RET=1
  106. echo_blue "=== $pkg_name: compile test done"
  107. echo_blue "=== $pkg_name: begin compile logs"
  108. for f in $(find logs/package/feeds/packages/$pkg_name/ -type f); do
  109. echo_blue "Printing last 200 lines of $f"
  110. tail -n200 "$f"
  111. done
  112. echo_blue "=== $pkg_name: end compile logs"
  113. echo_blue "=== $pkg_name: begin packages sizes"
  114. du -ba bin/
  115. echo_blue "=== $pkg_name: end packages sizes"
  116. done
  117. return $RET
  118. }
  119. test_commits() {
  120. RET=0
  121. if [ -z "$TRAVIS_PULL_REQUEST_SHA" ]; then
  122. echo_blue "Skipping commits tests (not in a Pull Request)"
  123. return 0
  124. fi
  125. for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE/.../..}); do
  126. echo_blue "=== Checking commit '$commit'"
  127. if git show --format='%P' -s $commit | grep -qF ' '; then
  128. echo_red "Pull request should not include merge commits"
  129. RET=1
  130. fi
  131. author="$(git show -s --format=%aN $commit)"
  132. if echo $author | grep -q '\S\+\s\+\S\+'; then
  133. echo_green "Author name ($author) seems ok"
  134. else
  135. echo_red "Author name ($author) need to be your real name 'firstname lastname'"
  136. RET=1
  137. fi
  138. subject="$(git show -s --format=%s $commit)"
  139. if echo "$subject" | grep -q -e '^[0-9A-Za-z,/_-]\+: ' -e '^Revert '; then
  140. echo_green "Commit subject line seems ok ($subject)"
  141. else
  142. echo_red "Commit subject line MUST start with '<package name>: ' ($subject)"
  143. RET=1
  144. fi
  145. body="$(git show -s --format=%b $commit)"
  146. sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
  147. if echo "$body" | grep -qF "$sob"; then
  148. echo_green "Signed-off-by match author"
  149. else
  150. echo_red "Signed-off-by is missing or doesn't match author (should be '$sob')"
  151. RET=1
  152. fi
  153. done
  154. return $RET
  155. }
  156. test_packages() {
  157. test_commits && test_packages2 || return 1
  158. }
  159. echo_blue "=== Travis ENV"
  160. env
  161. echo_blue "=== Travis ENV"
  162. if [ -n "$TRAVIS_PULL_REQUEST_SHA" ]; then
  163. while true; do
  164. # if clone depth is too small, git rev-list / diff return incorrect or empty results
  165. C="$(git rev-list ${TRAVIS_COMMIT_RANGE/.../..} | tail -n1)" 2>/dev/null
  166. [ -n "$C" -a "$C" != "a22de9b74cf9579d1ce7e6cf1845b4afa4277b00" ] && break
  167. echo_blue "Fetching 50 commits more"
  168. git fetch origin --deepen=50
  169. done
  170. fi
  171. if [ $# -ne 1 ] ; then
  172. cat <<EOF
  173. Usage: $0 (download_sdk|test_packages)
  174. download_sdk - download the SDK to $HOME/sdk.tar.xz
  175. test_packages - do a make check on the package
  176. EOF
  177. exit 1
  178. fi
  179. $@