jenkins.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. # This script is called from the Jenkinsfile, which ultimately runs
  18. # the CI through Yetus.
  19. # We use Ubuntu Focal as the main platform for building Hadoop, thus
  20. # it runs for all the PRs. Additionally, we also ensure that
  21. # Hadoop builds across the supported platforms whenever there's a change
  22. # in any of the C/C++ files, C/C++ build files or platform changes.
  23. ## @description Check if the given extension is related to C/C++
  24. ## @param seeking
  25. ## @return 0 if yes
  26. ## @return 1 if no
  27. is_c_cpp_extension() {
  28. local c_cpp_extension=("c" "cc" "cpp" "h" "hpp")
  29. local seeking=$1
  30. for element in "${c_cpp_extension[@]}"; do
  31. if [[ $element == "$seeking" ]]; then
  32. return 0
  33. fi
  34. done
  35. return 1
  36. }
  37. ## @description Check if the given relative path corresponds to
  38. ## change in platform files
  39. ## @param in_path
  40. ## @return 0 if yes
  41. ## @return 1 if no
  42. is_platform_change() {
  43. declare in_path
  44. in_path="${SOURCEDIR}"/"${1}"
  45. for path in "${SOURCEDIR}"/dev-support/docker/Dockerfile* "${SOURCEDIR}"/dev-support/docker/pkg-resolver/*.json; do
  46. if [ "${in_path}" == "${path}" ]; then
  47. echo "Found C/C++ platform related changes in ${in_path}"
  48. return 0
  49. fi
  50. done
  51. return 1
  52. }
  53. ## @description Checks if the given path corresponds to a change
  54. ## in C/C++ files or related to C/C++ build system
  55. ## @param path
  56. ## @return 0 if yes
  57. ## @return 1 if no
  58. is_c_cpp_change() {
  59. shopt -s nocasematch
  60. local path=$1
  61. declare filename
  62. filename=$(basename -- "${path}")
  63. extension=${filename##*.}
  64. if is_c_cpp_extension "${extension}"; then
  65. echo "Found C/C++ changes in ${path}"
  66. return 0
  67. fi
  68. if [[ $filename =~ CMakeLists\.txt ]]; then
  69. echo "Found C/C++ build related changes in ${path}"
  70. return 0
  71. fi
  72. return 1
  73. }
  74. ## @description Check if the CI needs to be run - CI will always run if
  75. ## IS_OPTIONAL is 0, or if there's any change in
  76. ## C/C++ files or C/C++ build or platform
  77. ## @return 0 if yes
  78. ## @return 1 if no
  79. function check_ci_run() {
  80. # Get the first commit of this PR relative to the trunk branch
  81. firstCommitOfThisPr=$(git --git-dir "${SOURCEDIR}/.git" rev-parse origin/trunk)
  82. # Loop over the paths of all the changed files and check if the criteria
  83. # to run the CI has been satisfied
  84. for path in $(git --git-dir "${SOURCEDIR}/.git" diff --name-only "${firstCommitOfThisPr}" HEAD); do
  85. if is_c_cpp_change "${path}"; then
  86. return 0
  87. fi
  88. if is_platform_change "${path}"; then
  89. return 0
  90. fi
  91. done
  92. # We must run the CI if it's not optional
  93. if [ "$IS_OPTIONAL" -eq 0 ]; then
  94. return 0
  95. fi
  96. return 1
  97. }
  98. ## @description Run the CI using YETUS
  99. function run_ci() {
  100. TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/test-patch.sh"
  101. # this must be clean for every run
  102. if [[ -d "${PATCHDIR}" ]]; then
  103. rm -rf "${PATCHDIR:?}"
  104. fi
  105. mkdir -p "${PATCHDIR}"
  106. # if given a JIRA issue, process it. If CHANGE_URL is set
  107. # (e.g., Github Branch Source plugin), process it.
  108. # otherwise exit, because we don't want Hadoop to do a
  109. # full build. We wouldn't normally do this check for smaller
  110. # projects. :)
  111. if [[ -n "${JIRA_ISSUE_KEY}" ]]; then
  112. YETUS_ARGS+=("${JIRA_ISSUE_KEY}")
  113. elif [[ -z "${CHANGE_URL}" ]]; then
  114. echo "Full build skipped" >"${PATCHDIR}/report.html"
  115. exit 0
  116. fi
  117. YETUS_ARGS+=("--patch-dir=${PATCHDIR}")
  118. # where the source is located
  119. YETUS_ARGS+=("--basedir=${SOURCEDIR}")
  120. # our project defaults come from a personality file
  121. YETUS_ARGS+=("--project=hadoop")
  122. YETUS_ARGS+=("--personality=${SOURCEDIR}/dev-support/bin/hadoop.sh")
  123. # lots of different output formats
  124. YETUS_ARGS+=("--brief-report-file=${PATCHDIR}/brief.txt")
  125. YETUS_ARGS+=("--console-report-file=${PATCHDIR}/console.txt")
  126. YETUS_ARGS+=("--html-report-file=${PATCHDIR}/report.html")
  127. # enable writing back to Github
  128. YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
  129. # auto-kill any surefire stragglers during unit test runs
  130. YETUS_ARGS+=("--reapermode=kill")
  131. # set relatively high limits for ASF machines
  132. # changing these to higher values may cause problems
  133. # with other jobs on systemd-enabled machines
  134. YETUS_ARGS+=("--proclimit=5500")
  135. YETUS_ARGS+=("--dockermemlimit=22g")
  136. # -1 spotbugs issues that show up prior to the patch being applied
  137. YETUS_ARGS+=("--spotbugs-strict-precheck")
  138. # rsync these files back into the archive dir
  139. YETUS_ARGS+=("--archive-list=checkstyle-errors.xml,spotbugsXml.xml")
  140. # URL for user-side presentation in reports and such to our artifacts
  141. # (needs to match the archive bits below)
  142. YETUS_ARGS+=("--build-url-artifacts=artifact/out")
  143. # plugins to enable
  144. YETUS_ARGS+=("--plugins=all,-jira")
  145. # don't let these tests cause -1s because we aren't really paying that
  146. # much attention to them
  147. YETUS_ARGS+=("--tests-filter=checkstyle")
  148. # run in docker mode and specifically point to our
  149. # Dockerfile since we don't want to use the auto-pulled version.
  150. YETUS_ARGS+=("--docker")
  151. YETUS_ARGS+=("--dockerfile=${DOCKERFILE}")
  152. YETUS_ARGS+=("--mvn-custom-repos")
  153. # effectively treat dev-suport as a custom maven module
  154. YETUS_ARGS+=("--skip-dirs=dev-support")
  155. # help keep the ASF boxes clean
  156. YETUS_ARGS+=("--sentinel")
  157. # test with Java 8 and 11
  158. YETUS_ARGS+=("--java-home=/usr/lib/jvm/java-8-openjdk-amd64")
  159. YETUS_ARGS+=("--multijdkdirs=/usr/lib/jvm/java-11-openjdk-amd64")
  160. YETUS_ARGS+=("--multijdktests=compile")
  161. # custom javadoc goals
  162. YETUS_ARGS+=("--mvn-javadoc-goals=process-sources,javadoc:javadoc-no-fork")
  163. # write Yetus report as GitHub comment (YETUS-1102)
  164. YETUS_ARGS+=("--github-write-comment")
  165. YETUS_ARGS+=("--github-use-emoji-vote")
  166. "${TESTPATCHBIN}" "${YETUS_ARGS[@]}"
  167. }
  168. ## @description Cleans up the processes started by YETUS
  169. function cleanup_ci_proc() {
  170. # See YETUS-764
  171. if [ -f "${PATCHDIR}/pidfile.txt" ]; then
  172. echo "test-patch process appears to still be running: killing"
  173. kill "$(cat "${PATCHDIR}/pidfile.txt")" || true
  174. sleep 10
  175. fi
  176. if [ -f "${PATCHDIR}/cidfile.txt" ]; then
  177. echo "test-patch container appears to still be running: killing"
  178. docker kill "$(cat "${PATCHDIR}/cidfile.txt")" || true
  179. fi
  180. }
  181. ## @description Invokes github_status_recovery in YETUS's precommit
  182. function github_status_recovery() {
  183. YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
  184. YETUS_ARGS+=("--patch-dir=${PATCHDIR}")
  185. TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/github-status-recovery.sh"
  186. /usr/bin/env bash "${TESTPATCHBIN}" "${YETUS_ARGS[@]}" "${EXTRA_ARGS}" || true
  187. }
  188. if [ -z "$1" ]; then
  189. echo "Must specify an argument for jenkins.sh"
  190. echo "run_ci - Runs the CI based on platform image as defined by DOCKERFILE"
  191. echo "cleanup_ci_proc - Cleans up the processes spawned for running the CI"
  192. echo "github_status_recovery - Sends Github status (refer to YETUS precommit for more details)"
  193. exit 1
  194. fi
  195. # Process arguments to jenkins.sh
  196. if [ "$1" == "run_ci" ]; then
  197. # Check if the CI needs to be run, if so, do so :)
  198. if check_ci_run; then
  199. run_ci
  200. else
  201. echo "No C/C++ file or C/C++ build or platform changes found, will not run CI for this platform"
  202. fi
  203. elif [ "$1" == "cleanup_ci_proc" ]; then
  204. cleanup_ci_proc
  205. elif [ "$1" == "github_status_recovery" ]; then
  206. github_status_recovery
  207. else
  208. echo "Don't know how to process $1"
  209. exit 1
  210. fi