jenkins.sh 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 "${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. if [[ "$IS_WINDOWS" && "$IS_WINDOWS" == 1 ]]; then
  102. echo "Building in a Windows environment, skipping some Yetus related settings"
  103. else
  104. # run in docker mode and specifically point to our
  105. # Dockerfile since we don't want to use the auto-pulled version.
  106. YETUS_ARGS+=("--docker")
  107. YETUS_ARGS+=("--dockerfile=${DOCKERFILE}")
  108. YETUS_ARGS+=("--mvn-custom-repos")
  109. YETUS_ARGS+=("--dockermemlimit=22g")
  110. # test with Java 8 and 11
  111. YETUS_ARGS+=("--java-home=/usr/lib/jvm/java-8-openjdk-amd64")
  112. YETUS_ARGS+=("--multijdkdirs=/usr/lib/jvm/java-11-openjdk-amd64")
  113. YETUS_ARGS+=("--multijdktests=compile")
  114. fi
  115. if [[ "$IS_NIGHTLY_BUILD" && "$IS_NIGHTLY_BUILD" == 1 ]]; then
  116. YETUS_ARGS+=("--empty-patch")
  117. YETUS_ARGS+=("--branch=${BRANCH_NAME}")
  118. else
  119. # this must be clean for every run
  120. if [[ -d "${PATCHDIR}" ]]; then
  121. rm -rf "${PATCHDIR:?}"
  122. fi
  123. mkdir -p "${PATCHDIR}"
  124. # if given a JIRA issue, process it. If CHANGE_URL is set
  125. # (e.g., Github Branch Source plugin), process it.
  126. # otherwise exit, because we don't want Hadoop to do a
  127. # full build. We wouldn't normally do this check for smaller
  128. # projects. :)
  129. if [[ -n "${JIRA_ISSUE_KEY}" ]]; then
  130. YETUS_ARGS+=("${JIRA_ISSUE_KEY}")
  131. elif [[ -z "${CHANGE_URL}" ]]; then
  132. echo "Full build skipped" >"${PATCHDIR}/report.html"
  133. exit 0
  134. fi
  135. # write Yetus report as GitHub comment (YETUS-1102)
  136. YETUS_ARGS+=("--github-write-comment")
  137. YETUS_ARGS+=("--github-use-emoji-vote")
  138. fi
  139. YETUS_ARGS+=("--patch-dir=${PATCHDIR}")
  140. # where the source is located
  141. YETUS_ARGS+=("--basedir=${SOURCEDIR}")
  142. # our project defaults come from a personality file
  143. YETUS_ARGS+=("--project=hadoop")
  144. YETUS_ARGS+=("--personality=${SOURCEDIR}/dev-support/bin/hadoop.sh")
  145. # lots of different output formats
  146. YETUS_ARGS+=("--brief-report-file=${PATCHDIR}/brief.txt")
  147. YETUS_ARGS+=("--console-report-file=${PATCHDIR}/console.txt")
  148. YETUS_ARGS+=("--html-report-file=${PATCHDIR}/report.html")
  149. # enable writing back to Github
  150. YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
  151. # auto-kill any surefire stragglers during unit test runs
  152. YETUS_ARGS+=("--reapermode=kill")
  153. # set relatively high limits for ASF machines
  154. # changing these to higher values may cause problems
  155. # with other jobs on systemd-enabled machines
  156. YETUS_ARGS+=("--proclimit=5500")
  157. # -1 spotbugs issues that show up prior to the patch being applied
  158. YETUS_ARGS+=("--spotbugs-strict-precheck")
  159. # rsync these files back into the archive dir
  160. YETUS_ARGS+=("--archive-list=checkstyle-errors.xml,spotbugsXml.xml")
  161. # URL for user-side presentation in reports and such to our artifacts
  162. # (needs to match the archive bits below)
  163. YETUS_ARGS+=("--build-url-artifacts=artifact/out")
  164. # plugins to enable
  165. YETUS_ARGS+=("--plugins=all,-jira")
  166. # don't let these tests cause -1s because we aren't really paying that
  167. # much attention to them
  168. YETUS_ARGS+=("--tests-filter=checkstyle")
  169. # effectively treat dev-suport as a custom maven module
  170. YETUS_ARGS+=("--skip-dirs=dev-support")
  171. # help keep the ASF boxes clean
  172. YETUS_ARGS+=("--sentinel")
  173. # custom javadoc goals
  174. YETUS_ARGS+=("--mvn-javadoc-goals=process-sources,javadoc:javadoc-no-fork")
  175. "${TESTPATCHBIN}" "${YETUS_ARGS[@]}"
  176. }
  177. ## @description Cleans up the processes started by YETUS
  178. function cleanup_ci_proc() {
  179. # See YETUS-764
  180. if [ -f "${PATCHDIR}/pidfile.txt" ]; then
  181. echo "test-patch process appears to still be running: killing"
  182. kill "$(cat "${PATCHDIR}/pidfile.txt")" || true
  183. sleep 10
  184. fi
  185. if [ -f "${PATCHDIR}/cidfile.txt" ]; then
  186. echo "test-patch container appears to still be running: killing"
  187. docker kill "$(cat "${PATCHDIR}/cidfile.txt")" || true
  188. fi
  189. }
  190. ## @description Invokes github_status_recovery in YETUS's precommit
  191. function github_status_recovery() {
  192. YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
  193. YETUS_ARGS+=("--patch-dir=${PATCHDIR}")
  194. TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/github-status-recovery.sh"
  195. /usr/bin/env bash "${TESTPATCHBIN}" "${YETUS_ARGS[@]}" "${EXTRA_ARGS}" || true
  196. }
  197. if [ -z "$1" ]; then
  198. echo "Must specify an argument for jenkins.sh"
  199. echo "run_ci - Runs the CI based on platform image as defined by DOCKERFILE"
  200. echo "cleanup_ci_proc - Cleans up the processes spawned for running the CI"
  201. echo "github_status_recovery - Sends Github status (refer to YETUS precommit for more details)"
  202. exit 1
  203. fi
  204. # Process arguments to jenkins.sh
  205. if [ "$1" == "run_ci" ]; then
  206. # Check if the CI needs to be run, if so, do so :)
  207. if check_ci_run; then
  208. run_ci
  209. else
  210. echo "No C/C++ file or C/C++ build or platform changes found, will not run CI for this platform"
  211. fi
  212. elif [ "$1" == "cleanup_ci_proc" ]; then
  213. cleanup_ci_proc
  214. elif [ "$1" == "github_status_recovery" ]; then
  215. github_status_recovery
  216. else
  217. echo "Don't know how to process $1"
  218. exit 1
  219. fi