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.

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