ci.sh 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. #!/usr/bin/env bash
  2. # Push caller's shell options (quietly)
  3. { SHELLOPTS_STACK="${SHELLOPTS_STACK-}|$(set +o); set -$-"; } 2> /dev/null
  4. set -eo pipefail
  5. if [ -z "${TRAVIS_PULL_REQUEST-}" ] || [ -n "${OSTYPE##darwin*}" ]; then set -ux; fi
  6. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)"
  7. WORKSPACE_DIR="${ROOT_DIR}/.."
  8. suppress_output() {
  9. "${WORKSPACE_DIR}"/ci/suppress_output "$@"
  10. }
  11. keep_alive() {
  12. "${WORKSPACE_DIR}"/ci/keep_alive "$@"
  13. }
  14. # Calls the provided command with set -x temporarily suppressed
  15. suppress_xtrace() {
  16. {
  17. local restore_shell_state=""
  18. if [ -o xtrace ]; then set +x; restore_shell_state="set -x"; fi
  19. } 2> /dev/null
  20. local status=0
  21. "$@" || status=$?
  22. ${restore_shell_state}
  23. { return "${status}"; } 2> /dev/null
  24. }
  25. # If provided the names of one or more environment variables, returns 0 if any of them is triggered.
  26. # Usage: should_run_job [VAR_NAME]...
  27. should_run_job() {
  28. local skip=0
  29. if [ -n "${1-}" ]; then # were any triggers provided? (if not, then the job will always run)
  30. local envvar active_triggers=()
  31. for envvar in "$@"; do
  32. if [ "${!envvar}" = 1 ]; then
  33. # success! we found at least one of the given triggers is occurring
  34. active_triggers+=("${envvar}=${!envvar}")
  35. fi
  36. done
  37. if [ 0 -eq "${#active_triggers[@]}" ]; then
  38. echo "Job is not triggered by any of $1; skipping job."
  39. sleep 15 # make sure output is flushed
  40. skip=1
  41. else
  42. echo "Job is triggered by: ${active_triggers[*]}"
  43. fi
  44. fi
  45. return "${skip}"
  46. }
  47. # Idempotent environment loading
  48. reload_env() {
  49. # Try to only modify CI-specific environment variables here (TRAVIS_... or GITHUB_...),
  50. # e.g. for CI cross-compatibility.
  51. # Normal environment variables should be set up at software installation time, not here.
  52. if [ -n "${GITHUB_PULL_REQUEST-}" ]; then
  53. case "${GITHUB_PULL_REQUEST}" in
  54. [1-9]*) TRAVIS_PULL_REQUEST="${GITHUB_PULL_REQUEST}";;
  55. *) TRAVIS_PULL_REQUEST=false;;
  56. esac
  57. export TRAVIS_PULL_REQUEST
  58. fi
  59. if [ "${GITHUB_ACTIONS-}" = true ] && [ -z "${TRAVIS_BRANCH-}" ]; then
  60. # Define TRAVIS_BRANCH to make Travis scripts run on GitHub Actions.
  61. TRAVIS_BRANCH="${GITHUB_BASE_REF:-${GITHUB_REF}}" # For pull requests, the base branch name
  62. TRAVIS_BRANCH="${TRAVIS_BRANCH#refs/heads/}" # Remove refs/... prefix
  63. # TODO(mehrdadn): Make TRAVIS_BRANCH be a named ref (e.g. 'master') like it's supposed to be.
  64. # For now we use a hash because GitHub Actions doesn't clone refs the same way as Travis does.
  65. TRAVIS_BRANCH="${GITHUB_HEAD_SHA:-${TRAVIS_BRANCH}}"
  66. export TRAVIS_BRANCH
  67. fi
  68. }
  69. need_wheels() {
  70. local error_code=1
  71. case "${OSTYPE}" in
  72. linux*) if [ "${LINUX_WHEELS-}" = 1 ]; then error_code=0; fi;;
  73. darwin*) if [ "${MAC_WHEELS-}" = 1 ]; then error_code=0; fi;;
  74. msys*) if [ "${WINDOWS_WHEELS-}" = 1 ]; then error_code=0; fi;;
  75. esac
  76. return "${error_code}"
  77. }
  78. upload_wheels() {
  79. local branch="" commit
  80. commit="$(git rev-parse --verify HEAD)"
  81. if [ -z "${branch}" ]; then branch="${GITHUB_BASE_REF-}"; fi
  82. if [ -z "${branch}" ]; then branch="${GITHUB_REF#refs/heads/}"; fi
  83. if [ -z "${branch}" ]; then branch="${TRAVIS_BRANCH-}"; fi
  84. if [ -z "${branch}" ]; then echo "Unable to detect branch name" 1>&2; return 1; fi
  85. local local_dir="python/dist"
  86. if [ -d "${local_dir}" ]; then
  87. ls -a -l -- "${local_dir}"
  88. local remote_dir
  89. for remote_dir in latest "${branch}/${commit}"; do
  90. if command -V aws; then
  91. aws s3 sync --acl public-read --no-progress "${local_dir}" "s3://ray-wheels/${remote_dir}"
  92. fi
  93. done
  94. fi
  95. (
  96. cd "${WORKSPACE_DIR}"/python
  97. if ! python -s -c "import ray, sys; sys.exit(0 if ray._raylet.OPTIMIZED else 1)"; then
  98. echo "ERROR: Uploading non-optimized wheels! Performance will suffer for users!"
  99. false
  100. fi
  101. )
  102. }
  103. test_core() {
  104. local args=(
  105. "//:*"
  106. )
  107. case "${OSTYPE}" in
  108. msys)
  109. args+=(
  110. -//:core_worker_test
  111. -//:event_test
  112. -//:gcs_server_rpc_test
  113. -//:ray_syncer_test # TODO (iycheng): it's flaky on windows. Add it back once we figure out the cause
  114. -//:gcs_client_reconnection_test
  115. )
  116. ;;
  117. esac
  118. # shellcheck disable=SC2046
  119. bazel test --config=ci --build_tests_only $(./ci/run/bazel_export_options) -- "${args[@]}"
  120. }
  121. prepare_docker() {
  122. rm "${WORKSPACE_DIR}"/python/dist/* ||:
  123. pushd "${WORKSPACE_DIR}/python"
  124. pip install -e . --verbose
  125. python setup.py bdist_wheel
  126. tmp_dir="/tmp/prepare_docker_$RANDOM"
  127. mkdir -p $tmp_dir
  128. cp "${WORKSPACE_DIR}"/python/dist/*.whl $tmp_dir
  129. wheel=$(ls "${WORKSPACE_DIR}"/python/dist/)
  130. base_image=$(python -c "import sys; print(f'rayproject/ray-deps:nightly-py{sys.version_info[0]}{sys.version_info[1]}-cpu')")
  131. echo "
  132. FROM $base_image
  133. ENV LC_ALL=C.UTF-8
  134. ENV LANG=C.UTF-8
  135. COPY ./*.whl /
  136. EXPOSE 8000
  137. EXPOSE 10001
  138. RUN pip install /${wheel}[serve]
  139. RUN sudo apt update && sudo apt install curl -y
  140. " > $tmp_dir/Dockerfile
  141. pushd $tmp_dir
  142. docker build . -t ray_ci:v1
  143. popd
  144. popd
  145. }
  146. # For running Python tests on Windows.
  147. test_python() {
  148. local pathsep=":" args=()
  149. if [ "${OSTYPE}" = msys ]; then
  150. pathsep=";"
  151. args+=(
  152. python/ray/serve/...
  153. python/ray/tests/...
  154. -python/ray/serve:conda_env # pip field in runtime_env not supported
  155. -python/ray/serve:test_cross_language # Ray java not built on Windows yet.
  156. -python/ray/serve:test_gcs_failure # Fork not supported in windows
  157. -python/ray/serve:test_standalone2 # Multinode not supported on Windows
  158. -python/ray/serve:test_gradio
  159. -python/ray/tests:test_actor_advanced # crashes in shutdown
  160. -python/ray/tests:test_autoscaler # We don't support Autoscaler on Windows
  161. -python/ray/tests:test_autoscaler_aws
  162. -python/ray/tests:test_cli
  163. -python/ray/tests:test_client_init # timeout
  164. -python/ray/tests:test_command_runner # We don't support Autoscaler on Windows
  165. -python/ray/tests:test_gcs_fault_tolerance # flaky
  166. -python/ray/serve:test_get_deployment # address violation
  167. -python/ray/tests:test_global_gc
  168. -python/ray/tests:test_job
  169. -python/ray/tests:test_memstat
  170. -python/ray/tests:test_multi_node_3
  171. -python/ray/tests:test_object_manager # OOM on test_object_directory_basic
  172. -python/ray/tests:test_resource_demand_scheduler
  173. -python/ray/tests:test_stress # timeout
  174. -python/ray/tests:test_stress_sharded # timeout
  175. -python/ray/tests:test_k8s_operator_unit_tests
  176. -python/ray/tests:test_tracing # tracing not enabled on windows
  177. -python/ray/tests:kuberay/test_autoscaling_e2e # irrelevant on windows
  178. -python/ray/tests/xgboost/... # Requires ML dependencies, should not be run on Windows
  179. -python/ray/tests/lightgbm/... # Requires ML dependencies, should not be run on Windows
  180. -python/ray/tests/horovod/... # Requires ML dependencies, should not be run on Windows
  181. -python/ray/tests/ray_lightning/... # Requires ML dependencies, should not be run on Windows
  182. )
  183. fi
  184. if [ 0 -lt "${#args[@]}" ]; then # Any targets to test?
  185. install_ray
  186. # Shard the args.
  187. BUILDKITE_PARALLEL_JOB=${BUILDKITE_PARALLEL_JOB:-'0'}
  188. BUILDKITE_PARALLEL_JOB_COUNT=${BUILDKITE_PARALLEL_JOB_COUNT:-'1'}
  189. test_shard_selection=$(python ./ci/run/bazel-sharding.py --exclude_manual --index "${BUILDKITE_PARALLEL_JOB}" --count "${BUILDKITE_PARALLEL_JOB_COUNT}" "${args[@]}")
  190. # TODO(mehrdadn): We set PYTHONPATH here to let Python find our pickle5 under pip install -e.
  191. # It's unclear to me if this should be necessary, but this is to make tests run for now.
  192. # Check why this issue doesn't arise on Linux/Mac.
  193. # Ideally importing ray.cloudpickle should import pickle5 automatically.
  194. # shellcheck disable=SC2046,SC2086
  195. bazel test --config=ci \
  196. --build_tests_only $(./ci/run/bazel_export_options) \
  197. --test_env=PYTHONPATH="${PYTHONPATH-}${pathsep}${WORKSPACE_DIR}/python/ray/pickle5_files" \
  198. --test_env=CI="1" \
  199. --test_env=RAY_CI_POST_WHEEL_TESTS="1" \
  200. --test_env=USERPROFILE="${USERPROFILE}" \
  201. --test_output=streamed \
  202. -- \
  203. ${test_shard_selection};
  204. fi
  205. }
  206. # For running large Python tests on Linux and MacOS.
  207. test_large() {
  208. # shellcheck disable=SC2046
  209. bazel test --config=ci $(./ci/run/bazel_export_options) --test_env=CONDA_EXE --test_env=CONDA_PYTHON_EXE \
  210. --test_env=CONDA_SHLVL --test_env=CONDA_PREFIX --test_env=CONDA_DEFAULT_ENV --test_env=CONDA_PROMPT_MODIFIER \
  211. --test_env=CI --test_tag_filters="large_size_python_tests_shard_${BUILDKITE_PARALLEL_JOB}" "$@" \
  212. -- python/ray/tests/...
  213. }
  214. test_cpp() {
  215. # C++ worker example need _GLIBCXX_USE_CXX11_ABI flag, but if we put the flag into .bazelrc, the linux ci can't pass.
  216. # So only set the flag in c++ worker example. More details: https://github.com/ray-project/ray/pull/18273
  217. echo build --cxxopt="-D_GLIBCXX_USE_CXX11_ABI=0" >> ~/.bazelrc
  218. bazel build --config=ci //cpp:all
  219. # shellcheck disable=SC2046
  220. bazel test --config=ci $(./ci/run/bazel_export_options) --test_strategy=exclusive //cpp:all --build_tests_only
  221. # run cluster mode test with external cluster
  222. bazel test //cpp:cluster_mode_test --test_arg=--external_cluster=true --test_arg=--redis_password="1234" \
  223. --test_arg=--ray_redis_password="1234"
  224. bazel test --test_output=all //cpp:test_python_call_cpp
  225. # run the cpp example
  226. rm -rf ray-template && mkdir ray-template
  227. ray cpp --generate-bazel-project-template-to ray-template
  228. pushd ray-template && bash run.sh
  229. }
  230. test_wheels() {
  231. local result=0 flush_logs=0
  232. if need_wheels; then
  233. "${WORKSPACE_DIR}"/ci/build/test-wheels.sh || { result=$? && flush_logs=1; }
  234. fi
  235. if [ 0 -ne "${flush_logs}" ]; then
  236. cat -- /tmp/ray/session_latest/logs/* || true
  237. sleep 60 # Explicitly sleep 60 seconds for logs to go through
  238. fi
  239. return "${result}"
  240. }
  241. install_npm_project() {
  242. if [ "${OSTYPE}" = msys ]; then
  243. # Not Windows-compatible: https://github.com/npm/cli/issues/558#issuecomment-584673763
  244. { echo "WARNING: Skipping NPM due to module incompatibilities with Windows"; } 2> /dev/null
  245. else
  246. npm i -g yarn
  247. yarn
  248. fi
  249. }
  250. build_dashboard_front_end() {
  251. if [ "${OSTYPE}" = msys ]; then
  252. { echo "WARNING: Skipping dashboard due to NPM incompatibilities with Windows"; } 2> /dev/null
  253. else
  254. (
  255. cd ray/dashboard/client
  256. # skip nvm activation on buildkite linux instances.
  257. if [ -z "${BUILDKITE-}" ] || [[ "${OSTYPE}" != linux* ]]; then
  258. set +x # suppress set -x since it'll get very noisy here
  259. . "${HOME}/.nvm/nvm.sh"
  260. NODE_VERSION="14"
  261. nvm install $NODE_VERSION
  262. nvm use --silent $NODE_VERSION
  263. fi
  264. install_npm_project
  265. yarn build
  266. )
  267. fi
  268. }
  269. build_sphinx_docs() {
  270. (
  271. cd "${WORKSPACE_DIR}"/doc
  272. if [ "${OSTYPE}" = msys ]; then
  273. echo "WARNING: Documentation not built on Windows due to currently-unresolved issues"
  274. else
  275. make html
  276. make doctest
  277. fi
  278. )
  279. }
  280. check_sphinx_links() {
  281. (
  282. cd "${WORKSPACE_DIR}"/doc
  283. if [ "${OSTYPE}" = msys ]; then
  284. echo "WARNING: Documentation not built on Windows due to currently-unresolved issues"
  285. else
  286. make linkcheck
  287. fi
  288. )
  289. }
  290. install_cython_examples() {
  291. (
  292. cd "${WORKSPACE_DIR}"/doc/examples/cython
  293. pip install scipy
  294. python setup.py install --user
  295. )
  296. }
  297. install_go() {
  298. local gimme_url="https://raw.githubusercontent.com/travis-ci/gimme/master/gimme"
  299. suppress_xtrace eval "$(curl -f -s -L "${gimme_url}" | GIMME_GO_VERSION=1.18.3 bash)"
  300. if [ -z "${GOPATH-}" ]; then
  301. GOPATH="${GOPATH:-${HOME}/go_dir}"
  302. export GOPATH
  303. fi
  304. }
  305. _bazel_build_before_install() {
  306. local target
  307. if [ "${OSTYPE}" = msys ]; then
  308. # On Windows, we perform as full of a build as possible, to ensure the repository always remains buildable on Windows.
  309. # (Pip install will not perform a full build.)
  310. target="//:*"
  311. else
  312. # Just build Python on other platforms.
  313. # This because pip install captures & suppresses the build output, which causes a timeout on CI.
  314. target="//:ray_pkg"
  315. fi
  316. # NOTE: Do not add build flags here. Use .bazelrc and --config instead.
  317. if [ -z "${RAY_DEBUG_BUILD-}" ]; then
  318. bazel build "${target}"
  319. elif [ "${RAY_DEBUG_BUILD}" = "asan" ]; then
  320. # bazel build --config asan "${target}"
  321. echo "Not needed"
  322. elif [ "${RAY_DEBUG_BUILD}" = "debug" ]; then
  323. bazel build --config debug "${target}"
  324. else
  325. echo "Invalid config given"
  326. exit 1
  327. fi
  328. }
  329. _bazel_build_protobuf() {
  330. bazel build "//:install_py_proto"
  331. }
  332. install_ray() {
  333. # TODO(mehrdadn): This function should be unified with the one in python/build-wheel-windows.sh.
  334. (
  335. cd "${WORKSPACE_DIR}"/python
  336. build_dashboard_front_end
  337. keep_alive pip install -v -e .
  338. )
  339. (
  340. # For runtime_env tests, wheels are needed
  341. cd "${WORKSPACE_DIR}"
  342. keep_alive pip wheel -e python -w .whl
  343. )
  344. }
  345. validate_wheels_commit_str() {
  346. if [ "${OSTYPE}" = msys ]; then
  347. echo "Windows builds do not set the commit string, skipping wheel commit validity check."
  348. return 0
  349. fi
  350. if [ -n "${BUILDKITE_COMMIT}" ]; then
  351. EXPECTED_COMMIT=${BUILDKITE_COMMIT:-}
  352. else
  353. EXPECTED_COMMIT=${TRAVIS_COMMIT:-}
  354. fi
  355. if [ -z "$EXPECTED_COMMIT" ]; then
  356. echo "Could not validate expected wheel commits: TRAVIS_COMMIT is empty."
  357. return 0
  358. fi
  359. for whl in .whl/*.whl; do
  360. basename=${whl##*/}
  361. if [[ "$basename" =~ "_cpp" ]]; then
  362. # cpp wheels cannot be checked this way
  363. echo "Skipping CPP wheel ${basename} for wheel commit validation."
  364. continue
  365. fi
  366. folder=${basename%%-cp*}
  367. WHL_COMMIT=$(unzip -p "$whl" "${folder}.data/purelib/ray/__init__.py" | grep "__commit__" | awk -F'"' '{print $2}')
  368. if [ "${WHL_COMMIT}" != "${EXPECTED_COMMIT}" ]; then
  369. echo "Error: Observed wheel commit (${WHL_COMMIT}) is not expected commit (${EXPECTED_COMMIT}). Aborting."
  370. exit 1
  371. fi
  372. echo "Wheel ${basename} has the correct commit: ${WHL_COMMIT}"
  373. done
  374. echo "All wheels passed the sanity check and have the correct wheel commit set."
  375. }
  376. build_wheels() {
  377. # Create wheel output directory and empty contents
  378. # If buildkite runners are re-used, wheels from previous builds might be here, so we delete them.
  379. mkdir -p .whl
  380. rm -rf .whl/* || true
  381. case "${OSTYPE}" in
  382. linux*)
  383. # Mount bazel cache dir to the docker container.
  384. # For the linux wheel build, we use a shared cache between all
  385. # wheels, but not between different travis runs, because that
  386. # caused timeouts in the past. See the "cache: false" line below.
  387. local MOUNT_BAZEL_CACHE=(
  388. -v "${HOME}/ray-bazel-cache":/root/ray-bazel-cache
  389. -e "TRAVIS=true"
  390. -e "TRAVIS_PULL_REQUEST=${TRAVIS_PULL_REQUEST:-false}"
  391. -e "encrypted_1c30b31fe1ee_key=${encrypted_1c30b31fe1ee_key-}"
  392. -e "encrypted_1c30b31fe1ee_iv=${encrypted_1c30b31fe1ee_iv-}"
  393. -e "TRAVIS_COMMIT=${TRAVIS_COMMIT}"
  394. -e "CI=${CI}"
  395. -e "RAY_INSTALL_JAVA=${RAY_INSTALL_JAVA:-}"
  396. -e "BUILDKITE=${BUILDKITE:-}"
  397. -e "BUILDKITE_PULL_REQUEST=${BUILDKITE_PULL_REQUEST:-}"
  398. -e "BUILDKITE_BAZEL_CACHE_URL=${BUILDKITE_BAZEL_CACHE_URL:-}"
  399. -e "RAY_DEBUG_BUILD=${RAY_DEBUG_BUILD:-}"
  400. )
  401. if [ -z "${BUILDKITE-}" ]; then
  402. # This command should be kept in sync with ray/python/README-building-wheels.md,
  403. # except the "${MOUNT_BAZEL_CACHE[@]}" part.
  404. docker run --rm -w /ray -v "${PWD}":/ray "${MOUNT_BAZEL_CACHE[@]}" \
  405. quay.io/pypa/manylinux2014_x86_64:2021-11-07-28723f3 /ray/python/build-wheel-manylinux2014.sh
  406. else
  407. rm -rf /ray-mount/*
  408. rm -rf /ray-mount/.whl || true
  409. rm -rf /ray/.whl || true
  410. cp -rT /ray /ray-mount
  411. ls -a /ray-mount
  412. docker run --rm -v /ray:/ray-mounted ubuntu:focal ls /
  413. docker run --rm -v /ray:/ray-mounted ubuntu:focal ls /ray-mounted
  414. docker run --rm -w /ray -v /ray:/ray "${MOUNT_BAZEL_CACHE[@]}" \
  415. quay.io/pypa/manylinux2014_x86_64:2021-11-07-28723f3 /ray/python/build-wheel-manylinux2014.sh
  416. cp -rT /ray-mount /ray # copy new files back here
  417. find . | grep whl # testing
  418. # Sync the directory to buildkite artifacts
  419. rm -rf /artifact-mount/.whl || true
  420. if [ "${UPLOAD_WHEELS_AS_ARTIFACTS-}" = "1" ]; then
  421. cp -r .whl /artifact-mount/.whl
  422. chmod -R 777 /artifact-mount/.whl
  423. fi
  424. validate_wheels_commit_str
  425. fi
  426. ;;
  427. darwin*)
  428. # This command should be kept in sync with ray/python/README-building-wheels.md.
  429. "${WORKSPACE_DIR}"/python/build-wheel-macos.sh
  430. mkdir -p /tmp/artifacts/.whl
  431. rm -rf /tmp/artifacts/.whl || true
  432. if [ "${UPLOAD_WHEELS_AS_ARTIFACTS-}" = "1" ]; then
  433. cp -r .whl /tmp/artifacts/.whl
  434. chmod -R 777 /tmp/artifacts/.whl
  435. fi
  436. validate_wheels_commit_str
  437. ;;
  438. msys*)
  439. keep_alive "${WORKSPACE_DIR}"/python/build-wheel-windows.sh
  440. ;;
  441. esac
  442. }
  443. lint_readme() {
  444. if python -s -c "import docutils" >/dev/null 2>/dev/null; then
  445. (
  446. cd "${WORKSPACE_DIR}"/python
  447. python setup.py check --restructuredtext --strict --metadata
  448. )
  449. else
  450. echo "Skipping README lint because the docutils package is not installed" 1>&2
  451. fi
  452. }
  453. lint_scripts() {
  454. FORMAT_SH_PRINT_DIFF=1 "${ROOT_DIR}"/lint/format.sh --all-scripts
  455. }
  456. lint_banned_words() {
  457. "${ROOT_DIR}"/lint/check-banned-words.sh
  458. }
  459. lint_annotations() {
  460. "${ROOT_DIR}"/lint/check_api_annotations.py
  461. }
  462. lint_bazel() {
  463. # Run buildifier without affecting external environment variables
  464. (
  465. mkdir -p -- "${GOPATH}"
  466. export PATH="${GOPATH}/bin:${GOROOT}/bin:${PATH}"
  467. # Build buildifier
  468. go install github.com/bazelbuild/buildtools/buildifier@latest
  469. # Now run buildifier
  470. "${ROOT_DIR}"/lint/bazel-format.sh
  471. )
  472. }
  473. lint_bazel_pytest() {
  474. pip install yq
  475. cd "${WORKSPACE_DIR}"
  476. for team in "team:ml" "team:rllib" "team:serve"; do
  477. # this does the following:
  478. # - find all py_test rules in bazel that have the specified team tag EXCEPT ones with "no_main" tag and outputs them as xml
  479. # - converts the xml to json
  480. # - feeds the json into pytest_checker.py
  481. bazel query "kind(py_test.*, tests(python/...) intersect attr(tags, \"\b$team\b\", python/...) except attr(tags, \"\bno_main\b\", python/...))" --output xml | xq | python scripts/pytest_checker.py
  482. done
  483. }
  484. lint_web() {
  485. (
  486. cd "${WORKSPACE_DIR}"/python/ray/dashboard/client
  487. set +x # suppress set -x since it'll get very noisy here
  488. if [ -z "${BUILDKITE-}" ]; then
  489. . "${HOME}/.nvm/nvm.sh"
  490. NODE_VERSION="14"
  491. nvm install $NODE_VERSION
  492. nvm use --silent $NODE_VERSION
  493. fi
  494. install_npm_project
  495. local filenames
  496. # shellcheck disable=SC2207
  497. filenames=($(find src -name "*.ts" -or -name "*.tsx"))
  498. node_modules/.bin/eslint --max-warnings 0 "${filenames[@]}"
  499. node_modules/.bin/prettier --check "${filenames[@]}"
  500. node_modules/.bin/prettier --check public/index.html
  501. )
  502. }
  503. lint_copyright() {
  504. (
  505. "${ROOT_DIR}"/lint/copyright-format.sh -c
  506. )
  507. }
  508. _lint() {
  509. local platform=""
  510. case "${OSTYPE}" in
  511. linux*) platform=linux;;
  512. esac
  513. if command -v clang-format > /dev/null; then
  514. "${ROOT_DIR}"/lint/check-git-clang-format-output.sh
  515. else
  516. { echo "WARNING: Skipping linting C/C++ as clang-format is not installed."; } 2> /dev/null
  517. fi
  518. if command -v clang-tidy > /dev/null; then
  519. pushd "${WORKSPACE_DIR}"
  520. "${ROOT_DIR}"/env/install-llvm-binaries.sh
  521. popd
  522. # Disable clang-tidy until ergonomic issues are resolved.
  523. # "${ROOT_DIR}"/lint/check-git-clang-tidy-output.sh
  524. else
  525. { echo "WARNING: Skipping running clang-tidy which is not installed."; } 2> /dev/null
  526. fi
  527. # Run script linting
  528. lint_scripts
  529. # Run banned words check.
  530. lint_banned_words
  531. # Run annotations check.
  532. lint_annotations
  533. # Make sure that the README is formatted properly.
  534. lint_readme
  535. if [ "${platform}" = linux ]; then
  536. # Run Bazel linter Buildifier.
  537. lint_bazel
  538. # Check if py_test files have the if __name__... snippet
  539. lint_bazel_pytest
  540. # Run TypeScript and HTML linting.
  541. lint_web
  542. # lint copyright
  543. lint_copyright
  544. # lint test script
  545. pushd "${WORKSPACE_DIR}"
  546. bazel query 'kind("cc_test", //...)' --output=xml | python "${ROOT_DIR}"/lint/check-bazel-team-owner.py
  547. bazel query 'kind("py_test", //...)' --output=xml | python "${ROOT_DIR}"/lint/check-bazel-team-owner.py
  548. popd
  549. # Make sure tests will be run by CI.
  550. python "${ROOT_DIR}"/pipeline/check-test-run.py
  551. fi
  552. }
  553. lint() {
  554. install_go
  555. # Checkout a clean copy of the repo to avoid seeing changes that have been made to the current one
  556. (
  557. WORKSPACE_DIR="$(TMPDIR="${WORKSPACE_DIR}/.." mktemp -d)"
  558. # shellcheck disable=SC2030
  559. ROOT_DIR="${WORKSPACE_DIR}"/ci
  560. git worktree add -q "${WORKSPACE_DIR}"
  561. pushd "${WORKSPACE_DIR}"
  562. . "${ROOT_DIR}"/ci.sh _lint
  563. popd # this is required so we can remove the worktree when we're done
  564. git worktree remove --force "${WORKSPACE_DIR}"
  565. )
  566. }
  567. _check_job_triggers() {
  568. local job_names
  569. job_names="$1"
  570. local variable_definitions
  571. if command -v python3; then
  572. # shellcheck disable=SC2031
  573. variable_definitions=($(python3 "${ROOT_DIR}"/pipeline/determine_tests_to_run.py))
  574. else
  575. # shellcheck disable=SC2031
  576. variable_definitions=($(python "${ROOT_DIR}"/pipeline/determine_tests_to_run.py))
  577. fi
  578. if [ 0 -lt "${#variable_definitions[@]}" ]; then
  579. local expression restore_shell_state=""
  580. if [ -o xtrace ]; then set +x; restore_shell_state="set -x;"; fi # Disable set -x (noisy here)
  581. {
  582. expression="$(printf "%q " "${variable_definitions[@]}")"
  583. printf "%s\n" "${expression}" >> ~/.bashrc
  584. }
  585. eval "${restore_shell_state}" "${expression}" # Restore set -x, then evaluate expression
  586. fi
  587. # shellcheck disable=SC2086
  588. if ! (set +x && should_run_job ${job_names//,/ }); then
  589. if [ "${GITHUB_ACTIONS-}" = true ]; then
  590. # If this job is to be skipped, emit 'exit' into .bashrc to quickly exit all following steps.
  591. # This isn't needed on Travis (since everything runs in one shell), but is on GitHub Actions.
  592. cat <<EOF1 >> ~/.bashrc
  593. cat <<EOF2 1>&2
  594. Exiting shell as no triggers were active for this job:
  595. ${job_names//,/}
  596. The active triggers during job initialization were the following:
  597. ${variable_definitions[*]}
  598. EOF2
  599. exit 0
  600. EOF1
  601. fi
  602. exit 0
  603. fi
  604. }
  605. configure_system() {
  606. git config --global advice.detachedHead false
  607. git config --global core.askpass ""
  608. git config --global credential.helper ""
  609. git config --global credential.modalprompt false
  610. # Requests library need root certificates.
  611. if [ "${OSTYPE}" = msys ]; then
  612. certutil -generateSSTFromWU roots.sst && certutil -addstore -f root roots.sst && rm roots.sst
  613. fi
  614. }
  615. # Initializes the environment for the current job. Performs the following tasks:
  616. # - Calls 'exit 0' in this job step and all subsequent steps to quickly exit if provided a list of
  617. # job names and none of them has been triggered.
  618. # - Sets variables to indicate the job names that have been triggered.
  619. # Note: Please avoid exporting these variables. Instead, source any callees that need to use them.
  620. # This helps reduce implicit coupling of callees to their parents, as they will be unable to run
  621. # when not sourced, (especially with set -u).
  622. # - Installs dependencies for the current job.
  623. # - Exports any environment variables necessary to run the build.
  624. # Usage: init [JOB_NAMES]
  625. # - JOB_NAMES (optional): Comma-separated list of job names to trigger on.
  626. init() {
  627. # TODO(jjyao): fix it for windows
  628. if [ "${OSTYPE}" != msys ]; then
  629. _check_job_triggers "${1-}"
  630. fi
  631. configure_system
  632. # shellcheck disable=SC2031
  633. . "${ROOT_DIR}"/env/install-dependencies.sh # Script is sourced to propagate up environment changes
  634. }
  635. build() {
  636. if [ "${LINT-}" != 1 ]; then
  637. _bazel_build_before_install
  638. else
  639. _bazel_build_protobuf
  640. fi
  641. if ! need_wheels; then
  642. install_ray
  643. if [ "${LINT-}" = 1 ]; then
  644. # Try generating Sphinx documentation. To do this, we need to install Ray first.
  645. build_sphinx_docs
  646. fi
  647. fi
  648. if [ "${RAY_CYTHON_EXAMPLES-}" = 1 ]; then
  649. install_cython_examples
  650. fi
  651. if [ "${LINT-}" = 1 ]; then
  652. install_go
  653. fi
  654. if need_wheels; then
  655. build_wheels
  656. fi
  657. }
  658. test_minimal() {
  659. ./ci/env/install-minimal.sh "$1"
  660. ./ci/env/env_info.sh
  661. python ./ci/env/check_minimal_install.py
  662. BAZEL_EXPORT_OPTIONS="$(./ci/run/bazel_export_options)"
  663. # Ignoring shellcheck is necessary because if ${BAZEL_EXPORT_OPTIONS} is wrapped by the double quotation,
  664. # bazel test cannot recognize the option.
  665. # shellcheck disable=SC2086
  666. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic
  667. # shellcheck disable=SC2086
  668. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 --test_env=TEST_EXTERNAL_REDIS=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic
  669. # shellcheck disable=SC2086
  670. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_2
  671. # shellcheck disable=SC2086
  672. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 --test_env=TEST_EXTERNAL_REDIS=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_2
  673. # shellcheck disable=SC2086
  674. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_3
  675. # shellcheck disable=SC2086
  676. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 --test_env=TEST_EXTERNAL_REDIS=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_3
  677. # shellcheck disable=SC2086
  678. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_4
  679. # shellcheck disable=SC2086
  680. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 --test_env=TEST_EXTERNAL_REDIS=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_4
  681. # shellcheck disable=SC2086
  682. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_5
  683. # shellcheck disable=SC2086
  684. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 --test_env=TEST_EXTERNAL_REDIS=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_basic_5
  685. # shellcheck disable=SC2086
  686. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_output
  687. # shellcheck disable=SC2086
  688. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_runtime_env_ray_minimal
  689. # shellcheck disable=SC2086
  690. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_runtime_env
  691. # shellcheck disable=SC2086
  692. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_runtime_env_2
  693. # shellcheck disable=SC2086
  694. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_runtime_env_complicated
  695. # shellcheck disable=SC2086
  696. bazel test --test_output=streamed --config=ci ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_runtime_env_validation
  697. # shellcheck disable=SC2086
  698. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_serve_ray_minimal
  699. # shellcheck disable=SC2086
  700. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 ${BAZEL_EXPORT_OPTIONS} python/ray/dashboard/test_dashboard
  701. # shellcheck disable=SC2086
  702. bazel test --test_output=streamed --config=ci --test_env=RAY_MINIMAL=1 ${BAZEL_EXPORT_OPTIONS} python/ray/tests/test_usage_stats
  703. }
  704. _main() {
  705. if [ "${GITHUB_ACTIONS-}" = true ]; then
  706. exec 2>&1 # Merge stdout and stderr to prevent out-of-order buffering issues
  707. reload_env
  708. fi
  709. "$@"
  710. }
  711. _main "$@"
  712. # Pop caller's shell options (quietly)
  713. { set -vx; eval "${SHELLOPTS_STACK##*|}"; SHELLOPTS_STACK="${SHELLOPTS_STACK%|*}"; } 2> /dev/null