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.

241 lines
6.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=-sdk-ar71xx-generic_
  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. exec_status '^ERROR' make "package/$pkg_name/check" V=s || RET=1
  118. echo_blue "=== $pkg_name: quick tests done"
  119. done
  120. [ $RET -ne 0 ] && return $RET
  121. for pkg_dir in $PKGS ; do
  122. pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
  123. echo_blue "=== $pkg_name: Starting compile test"
  124. # we can't enable verbose built else we often hit Travis limits
  125. # on log size and the job get killed
  126. exec_status '^ERROR' make "package/$pkg_name/compile" -j3 || RET=1
  127. echo_blue "=== $pkg_name: compile test done"
  128. echo_blue "=== $pkg_name: begin compile logs"
  129. for f in $(find logs/package/feeds/packages/$pkg_name/ -type f); do
  130. echo_blue "Printing last 200 lines of $f"
  131. tail -n200 "$f"
  132. done
  133. echo_blue "=== $pkg_name: end compile logs"
  134. echo_blue "=== $pkg_name: begin packages sizes"
  135. du -ba bin/
  136. echo_blue "=== $pkg_name: end packages sizes"
  137. done
  138. return $RET
  139. }
  140. test_commits() {
  141. RET=0
  142. if [ -z "$TRAVIS_PULL_REQUEST_SHA" ]; then
  143. echo_blue "Skipping commits tests (not in a Pull Request)"
  144. return 0
  145. fi
  146. for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE/.../..}); do
  147. echo_blue "=== Checking commit '$commit'"
  148. if git show --format='%P' -s $commit | grep -qF ' '; then
  149. echo_red "Pull request should not include merge commits"
  150. RET=1
  151. fi
  152. author="$(git show -s --format=%aN $commit)"
  153. if echo $author | grep -q '\S\+\s\+\S\+'; then
  154. echo_green "Author name ($author) seems ok"
  155. else
  156. echo_red "Author name ($author) need to be your real name 'firstname lastname'"
  157. RET=1
  158. fi
  159. subject="$(git show -s --format=%s $commit)"
  160. if echo "$subject" | grep -q -e '^[0-9A-Za-z,/_-]\+: ' -e '^Revert '; then
  161. echo_green "Commit subject line seems ok ($subject)"
  162. else
  163. echo_red "Commit subject line MUST start with '<package name>: ' ($subject)"
  164. RET=1
  165. fi
  166. body="$(git show -s --format=%b $commit)"
  167. sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
  168. if echo "$body" | grep -qF "$sob"; then
  169. echo_green "Signed-off-by match author"
  170. else
  171. echo_red "Signed-off-by is missing or doesn't match author (should be '$sob')"
  172. RET=1
  173. fi
  174. done
  175. return $RET
  176. }
  177. test_packages() {
  178. test_commits && test_packages2 || return 1
  179. }
  180. echo_blue "=== Travis ENV"
  181. env
  182. echo_blue "=== Travis ENV"
  183. if [ -n "$TRAVIS_PULL_REQUEST_SHA" ]; then
  184. while true; do
  185. # if clone depth is too small, git rev-list / diff return incorrect or empty results
  186. C="$(git rev-list ${TRAVIS_COMMIT_RANGE/.../..} | tail -n1)" 2>/dev/null
  187. [ -n "$C" -a "$C" != "a22de9b74cf9579d1ce7e6cf1845b4afa4277b00" ] && break
  188. echo_blue "Fetching 50 commits more"
  189. git fetch origin --deepen=50
  190. done
  191. fi
  192. if [ $# -ne 1 ] ; then
  193. cat <<EOF
  194. Usage: $0 (download_sdk|test_packages)
  195. download_sdk - download the SDK to $HOME/sdk.tar.xz
  196. test_packages - do a make check on the package
  197. EOF
  198. exit 1
  199. fi
  200. $@