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.

192 lines
5.1 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. ./scripts/feeds update -a
  75. ./scripts/feeds install -a
  76. make defconfig
  77. echo_blue "=== Setting up SDK done"
  78. RET=0
  79. # E.g: pkg_dir => admin/muninlite
  80. # pkg_name => muninlite
  81. for pkg_dir in $PKGS ; do
  82. pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
  83. echo_blue "=== $pkg_name: Starting quick tests"
  84. exec_status 'WARNING|ERROR' make "package/$pkg_name/download" V=s || RET=1
  85. exec_status 'WARNING|ERROR' make "package/$pkg_name/check" V=s || RET=1
  86. echo_blue "=== $pkg_name: quick tests done"
  87. done
  88. [ $RET -ne 0 ] && return $RET
  89. for pkg_dir in $PKGS ; do
  90. pkg_name=$(echo "$pkg_dir" | awk -F/ '{ print $NF }')
  91. echo_blue "=== $pkg_name: Starting compile test"
  92. exec_status '^ERROR' make "package/$pkg_name/compile" V=s -j3
  93. echo_blue "=== $pkg_name: compile test done"
  94. done
  95. return 0
  96. }
  97. test_commits() {
  98. RET=0
  99. for commit in $(git rev-list ${TRAVIS_COMMIT_RANGE/.../..}); do
  100. echo_blue "=== Checking commit '$commit'"
  101. if git show --format='%P' -s $commit | grep -qF ' '; then
  102. echo_red "Pull request should not include merge commits"
  103. RET=1
  104. fi
  105. author="$(git show -s --format=%aN $commit)"
  106. if echo $author | grep -q '\S\+\s\+\S\+'; then
  107. echo_green "Author name ($author) seems ok"
  108. else
  109. echo_red "Author name ($author) need to be your real name 'firstname lastname'"
  110. RET=1
  111. fi
  112. subject="$(git show -s --format=%s $commit)"
  113. if echo "$subject" | grep -q -e '^[0-9A-Za-z,/-]\+: ' -e '^Revert '; then
  114. echo_green "Commit subject line seems ok ($subject)"
  115. else
  116. echo_red "Commit subject line MUST start with '<package name>: ' ($subject)"
  117. RET=1
  118. fi
  119. body="$(git show -s --format=%b $commit)"
  120. sob="$(git show -s --format='Signed-off-by: %aN <%aE>' $commit)"
  121. if echo "$body" | grep -qF "$sob"; then
  122. echo_green "Signed-off-by match author"
  123. else
  124. echo_red "Signed-off-by is missing or doesn't match author (should be '$sob')"
  125. RET=1
  126. fi
  127. done
  128. return $RET
  129. }
  130. test_packages() {
  131. test_commits && test_packages2 || return 1
  132. }
  133. echo_blue "=== Travis ENV"
  134. env
  135. echo_blue "=== Travis ENV"
  136. while true; do
  137. # if clone depth is too small, git rev-list / diff return incorrect or empty results
  138. C="$(git rev-list ${TRAVIS_COMMIT_RANGE/.../..} | tail -n1)" 2>/dev/null
  139. [ -n "$C" -a "$C" != "a22de9b74cf9579d1ce7e6cf1845b4afa4277b00" ] && break
  140. echo_blue "Fetching 50 commits more"
  141. git fetch origin --deepen=50
  142. done
  143. if [ "$TRAVIS_PULL_REQUEST" = false ] ; then
  144. echo "Only Pull Requests are supported at the moment." >&2
  145. exit 0
  146. fi
  147. if [ $# -ne 1 ] ; then
  148. cat <<EOF
  149. Usage: $0 (download_sdk|test_packages)
  150. download_sdk - download the SDK to $HOME/sdk.tar.xz
  151. test_packages - do a make check on the package
  152. EOF
  153. exit 1
  154. fi
  155. $@