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.

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