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.

203 lines
5.5 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 $!
  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
  79. ./scripts/feeds install -a
  80. make defconfig
  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
  99. echo_blue "=== $pkg_name: compile test done"
  100. echo_blue "=== $pkg_name: begin compile logs"
  101. cat logs/package/feeds/packages/$pkg_name/compile.txt
  102. echo_blue "=== $pkg_name: end compile logs"
  103. done
  104. return 0
  105. }
  106. test_commits() {
  107. RET=0
  108. for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE/.../..}); do
  109. echo_blue "=== Checking commit '$commit'"
  110. if git show --format='%P' -s $commit | grep -qF ' '; then
  111. echo_red "Pull request should not include merge commits"
  112. RET=1
  113. fi
  114. author="$(git show -s --format=%aN $commit)"
  115. if echo $author | grep -q '\S\+\s\+\S\+'; then
  116. echo_green "Author name ($author) seems ok"
  117. else
  118. echo_red "Author name ($author) need to be your real name 'firstname lastname'"
  119. RET=1
  120. fi
  121. subject="$(git show -s --format=%s $commit)"
  122. if echo "$subject" | grep -q -e '^[0-9A-Za-z,/-]\+: ' -e '^Revert '; then
  123. echo_green "Commit subject line seems ok ($subject)"
  124. else
  125. echo_red "Commit subject line MUST start with '<package name>: ' ($subject)"
  126. RET=1
  127. fi
  128. body="$(git show -s --format=%b $commit)"
  129. sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
  130. if echo "$body" | grep -qF "$sob"; then
  131. echo_green "Signed-off-by match author"
  132. else
  133. echo_red "Signed-off-by is missing or doesn't match author (should be '$sob')"
  134. RET=1
  135. fi
  136. done
  137. return $RET
  138. }
  139. test_packages() {
  140. test_commits && test_packages2 || return 1
  141. }
  142. echo_blue "=== Travis ENV"
  143. env
  144. echo_blue "=== Travis ENV"
  145. while true; do
  146. # if clone depth is too small, git rev-list / diff return incorrect or empty results
  147. C="$(git rev-list ${TRAVIS_COMMIT_RANGE/.../..} | tail -n1)" 2>/dev/null
  148. [ -n "$C" -a "$C" != "a22de9b74cf9579d1ce7e6cf1845b4afa4277b00" ] && break
  149. echo_blue "Fetching 50 commits more"
  150. git fetch origin --deepen=50
  151. done
  152. if [ "$TRAVIS_PULL_REQUEST" = false ] ; then
  153. echo "Only Pull Requests are supported at the moment." >&2
  154. exit 0
  155. fi
  156. if [ $# -ne 1 ] ; then
  157. cat <<EOF
  158. Usage: $0 (download_sdk|test_packages)
  159. download_sdk - download the SDK to $HOME/sdk.tar.xz
  160. test_packages - do a make check on the package
  161. EOF
  162. exit 1
  163. fi
  164. $@