2019-03-15 22:23:54 -07:00
|
|
|
# Script used for checking changes for incremental testing cases
|
|
|
|
from __future__ import absolute_import
|
|
|
|
from __future__ import division
|
|
|
|
from __future__ import print_function
|
|
|
|
|
2021-10-19 13:33:02 -07:00
|
|
|
import argparse
|
2020-04-15 08:10:22 -07:00
|
|
|
import json
|
2019-03-15 22:23:54 -07:00
|
|
|
import os
|
2021-10-19 13:33:02 -07:00
|
|
|
from pprint import pformat
|
|
|
|
import py_dep_analysis as pda
|
2020-02-21 04:02:17 +01:00
|
|
|
import re
|
2019-03-15 22:23:54 -07:00
|
|
|
import subprocess
|
2019-09-13 21:36:56 -07:00
|
|
|
import sys
|
2019-03-15 22:23:54 -07:00
|
|
|
|
|
|
|
|
|
|
|
def list_changed_files(commit_range):
|
|
|
|
"""Returns a list of names of files changed in the given commit range.
|
|
|
|
|
|
|
|
The function works by opening a subprocess and running git. If an error
|
|
|
|
occurs while running git, the script will abort.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
commit_range (string): The commit range to diff, consisting of the two
|
|
|
|
commit IDs separated by \"..\"
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
list: List of changed files within the commit range
|
|
|
|
"""
|
|
|
|
|
2020-04-15 08:10:22 -07:00
|
|
|
command = ["git", "diff", "--name-only", commit_range, "--"]
|
2019-03-15 22:23:54 -07:00
|
|
|
out = subprocess.check_output(command)
|
|
|
|
return [s.strip() for s in out.decode().splitlines() if s is not None]
|
|
|
|
|
|
|
|
|
2021-01-29 15:48:02 -08:00
|
|
|
def is_pull_request():
|
|
|
|
event_type = None
|
|
|
|
|
|
|
|
for key in ["GITHUB_EVENT_NAME", "TRAVIS_EVENT_TYPE"]:
|
|
|
|
event_type = os.getenv(key, event_type)
|
|
|
|
|
2022-01-29 18:41:57 -08:00
|
|
|
if (
|
|
|
|
os.environ.get("BUILDKITE")
|
|
|
|
and os.environ.get("BUILDKITE_PULL_REQUEST") != "false"
|
|
|
|
):
|
2021-01-29 15:48:02 -08:00
|
|
|
event_type = "pull_request"
|
|
|
|
|
|
|
|
return event_type == "pull_request"
|
|
|
|
|
|
|
|
|
|
|
|
def get_commit_range():
|
|
|
|
commit_range = None
|
|
|
|
|
|
|
|
if os.environ.get("TRAVIS"):
|
|
|
|
commit_range = os.environ["TRAVIS_COMMIT_RANGE"]
|
|
|
|
elif os.environ.get("GITHUB_EVENT_PATH"):
|
|
|
|
with open(os.environ["GITHUB_EVENT_PATH"], "rb") as f:
|
|
|
|
event = json.loads(f.read())
|
|
|
|
base = event["pull_request"]["base"]["sha"]
|
|
|
|
commit_range = "{}...{}".format(base, event.get("after", ""))
|
|
|
|
elif os.environ.get("BUILDKITE"):
|
2021-08-01 22:10:03 -07:00
|
|
|
commit_range = "origin/{}...{}".format(
|
2021-01-29 15:48:02 -08:00
|
|
|
os.environ["BUILDKITE_PULL_REQUEST_BASE_BRANCH"],
|
|
|
|
os.environ["BUILDKITE_COMMIT"],
|
|
|
|
)
|
|
|
|
|
|
|
|
assert commit_range is not None
|
|
|
|
return commit_range
|
|
|
|
|
|
|
|
|
2019-03-15 22:23:54 -07:00
|
|
|
if __name__ == "__main__":
|
2021-01-29 15:48:02 -08:00
|
|
|
parser = argparse.ArgumentParser()
|
2022-01-29 18:41:57 -08:00
|
|
|
parser.add_argument("--output", type=str, help="json or envvars", default="envvars")
|
2021-01-29 15:48:02 -08:00
|
|
|
args = parser.parse_args()
|
2019-03-15 22:23:54 -07:00
|
|
|
|
|
|
|
RAY_CI_TUNE_AFFECTED = 0
|
2020-07-25 06:22:54 +02:00
|
|
|
RAY_CI_SGD_AFFECTED = 0
|
2021-10-18 22:27:46 -07:00
|
|
|
RAY_CI_TRAIN_AFFECTED = 0
|
2021-11-04 20:40:57 +01:00
|
|
|
# Whether only the most important (high-level) RLlib tests should be run.
|
|
|
|
# Set to 1 for any changes to Ray Tune or python source files that are
|
|
|
|
# NOT related to Serve, Dashboard, SGD, or Train.
|
|
|
|
RAY_CI_RLLIB_AFFECTED = 0
|
|
|
|
# Whether all RLlib tests should be run.
|
|
|
|
# Set to 1 only when a source file in `ray/rllib` has been changed.
|
|
|
|
RAY_CI_RLLIB_DIRECTLY_AFFECTED = 0
|
2019-09-13 21:36:56 -07:00
|
|
|
RAY_CI_SERVE_AFFECTED = 0
|
2021-10-29 16:47:54 -07:00
|
|
|
RAY_CI_CORE_CPP_AFFECTED = 0
|
|
|
|
RAY_CI_CPP_AFFECTED = 0
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_JAVA_AFFECTED = 0
|
|
|
|
RAY_CI_PYTHON_AFFECTED = 0
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 0
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 0
|
2020-06-03 09:04:55 -07:00
|
|
|
RAY_CI_DASHBOARD_AFFECTED = 0
|
2020-08-03 16:37:15 -07:00
|
|
|
RAY_CI_DOCKER_AFFECTED = 0
|
2020-08-07 23:05:18 -07:00
|
|
|
RAY_CI_DOC_AFFECTED = 0
|
2020-08-26 19:36:11 -07:00
|
|
|
RAY_CI_PYTHON_DEPENDENCIES_AFFECTED = 0
|
2019-03-15 22:23:54 -07:00
|
|
|
|
2021-01-29 15:48:02 -08:00
|
|
|
if is_pull_request():
|
|
|
|
commit_range = get_commit_range()
|
2020-04-15 08:10:22 -07:00
|
|
|
files = list_changed_files(commit_range)
|
2021-01-29 15:48:02 -08:00
|
|
|
print(pformat(commit_range), file=sys.stderr)
|
2019-09-13 21:36:56 -07:00
|
|
|
print(pformat(files), file=sys.stderr)
|
|
|
|
|
2021-10-19 13:33:02 -07:00
|
|
|
# Dry run py_dep_analysis.py to see which tests we would have run.
|
|
|
|
try:
|
|
|
|
graph = pda.build_dep_graph()
|
|
|
|
rllib_tests = pda.list_rllib_tests()
|
2022-01-29 18:41:57 -08:00
|
|
|
print("Total # of RLlib tests: ", len(rllib_tests), file=sys.stderr)
|
2021-10-19 13:33:02 -07:00
|
|
|
|
|
|
|
impacted = {}
|
|
|
|
for test in rllib_tests:
|
|
|
|
for file in files:
|
|
|
|
if pda.test_depends_on_file(graph, test, file):
|
|
|
|
impacted[test[0]] = True
|
|
|
|
|
|
|
|
print("RLlib tests impacted: ", len(impacted), file=sys.stderr)
|
|
|
|
for test in impacted.keys():
|
|
|
|
print(" ", test, file=sys.stderr)
|
|
|
|
except Exception as e:
|
|
|
|
print("Failed to dry run py_dep_analysis.py", file=sys.stderr)
|
|
|
|
print(e, file=sys.stderr)
|
|
|
|
# End of dry run.
|
|
|
|
|
2022-01-29 18:41:57 -08:00
|
|
|
skip_prefix_list = ["doc/", "examples/", "dev/", "kubernetes/", "site/"]
|
2019-03-15 22:23:54 -07:00
|
|
|
|
|
|
|
for changed_file in files:
|
2020-02-21 04:02:17 +01:00
|
|
|
if changed_file.startswith("python/ray/tune"):
|
2020-08-07 23:05:18 -07:00
|
|
|
RAY_CI_DOC_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_TUNE_AFFECTED = 1
|
|
|
|
RAY_CI_RLLIB_AFFECTED = 1
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2020-07-25 06:22:54 +02:00
|
|
|
elif changed_file.startswith("python/ray/util/sgd"):
|
|
|
|
RAY_CI_SGD_AFFECTED = 1
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2021-10-18 22:27:46 -07:00
|
|
|
elif changed_file.startswith("python/ray/train"):
|
|
|
|
RAY_CI_TRAIN_AFFECTED = 1
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2021-12-03 13:38:42 -08:00
|
|
|
elif changed_file.startswith("python/ray/util/ml_utils"):
|
|
|
|
RAY_CI_TRAIN_AFFECTED = 1
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_SGD_AFFECTED = 1
|
|
|
|
RAY_CI_TUNE_AFFECTED = 1
|
|
|
|
RAY_CI_RLLIB_AFFECTED = 1
|
2021-12-21 17:17:52 -08:00
|
|
|
RAY_CI_ML_UTILS_AFFECTED = 1
|
2020-02-21 04:02:17 +01:00
|
|
|
elif re.match("^(python/ray/)?rllib/", changed_file):
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_RLLIB_AFFECTED = 1
|
2021-11-04 20:40:57 +01:00
|
|
|
RAY_CI_RLLIB_DIRECTLY_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2020-02-18 13:43:19 -08:00
|
|
|
elif changed_file.startswith("python/ray/serve"):
|
2021-01-12 13:08:55 -08:00
|
|
|
RAY_CI_DOC_AFFECTED = 1
|
2019-09-13 21:36:56 -07:00
|
|
|
RAY_CI_SERVE_AFFECTED = 1
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2020-06-03 09:04:55 -07:00
|
|
|
elif changed_file.startswith("python/ray/dashboard"):
|
|
|
|
RAY_CI_DASHBOARD_AFFECTED = 1
|
2021-06-08 19:59:03 -07:00
|
|
|
# https://github.com/ray-project/ray/pull/15981
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2020-08-25 04:24:23 +08:00
|
|
|
elif changed_file.startswith("dashboard"):
|
|
|
|
RAY_CI_DASHBOARD_AFFECTED = 1
|
2021-06-08 19:59:03 -07:00
|
|
|
# https://github.com/ray-project/ray/pull/15981
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
elif changed_file.startswith("python/"):
|
|
|
|
RAY_CI_TUNE_AFFECTED = 1
|
2020-07-25 06:22:54 +02:00
|
|
|
RAY_CI_SGD_AFFECTED = 1
|
2021-10-18 22:27:46 -07:00
|
|
|
RAY_CI_TRAIN_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_RLLIB_AFFECTED = 1
|
2019-09-13 21:36:56 -07:00
|
|
|
RAY_CI_SERVE_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_PYTHON_AFFECTED = 1
|
2020-06-03 09:04:55 -07:00
|
|
|
RAY_CI_DASHBOARD_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2020-08-07 23:05:18 -07:00
|
|
|
RAY_CI_DOC_AFFECTED = 1
|
2021-06-08 19:59:03 -07:00
|
|
|
# Python changes might impact cross language stack in Java.
|
|
|
|
# Java also depends on Python CLI to manage processes.
|
|
|
|
RAY_CI_JAVA_AFFECTED = 1
|
2020-10-12 14:22:51 -07:00
|
|
|
if changed_file.startswith("python/setup.py") or re.match(
|
2022-01-29 18:41:57 -08:00
|
|
|
".*requirements.*\.txt", changed_file
|
|
|
|
):
|
2020-08-26 19:36:11 -07:00
|
|
|
RAY_CI_PYTHON_DEPENDENCIES_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
elif changed_file.startswith("java/"):
|
|
|
|
RAY_CI_JAVA_AFFECTED = 1
|
2021-10-29 16:47:54 -07:00
|
|
|
elif changed_file.startswith("cpp/"):
|
|
|
|
RAY_CI_CPP_AFFECTED = 1
|
2020-08-03 16:37:15 -07:00
|
|
|
elif changed_file.startswith("docker/"):
|
|
|
|
RAY_CI_DOCKER_AFFECTED = 1
|
2020-09-02 13:03:35 -07:00
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
2022-01-29 18:41:57 -08:00
|
|
|
elif changed_file.startswith("doc/") and changed_file.endswith(".py"):
|
2020-08-07 23:05:18 -07:00
|
|
|
RAY_CI_DOC_AFFECTED = 1
|
2022-01-29 18:41:57 -08:00
|
|
|
elif any(changed_file.startswith(prefix) for prefix in skip_prefix_list):
|
2019-03-15 22:23:54 -07:00
|
|
|
# nothing is run but linting in these cases
|
|
|
|
pass
|
2021-01-28 15:24:50 -08:00
|
|
|
elif changed_file.endswith("build-docker-images.py"):
|
|
|
|
RAY_CI_DOCKER_AFFECTED = 1
|
2021-05-03 16:18:25 -07:00
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
elif changed_file.startswith("src/"):
|
|
|
|
RAY_CI_TUNE_AFFECTED = 1
|
2020-07-25 06:22:54 +02:00
|
|
|
RAY_CI_SGD_AFFECTED = 1
|
2021-10-18 22:27:46 -07:00
|
|
|
RAY_CI_TRAIN_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_RLLIB_AFFECTED = 1
|
2019-09-13 21:36:56 -07:00
|
|
|
RAY_CI_SERVE_AFFECTED = 1
|
2021-10-29 16:47:54 -07:00
|
|
|
RAY_CI_CORE_CPP_AFFECTED = 1
|
|
|
|
RAY_CI_CPP_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_JAVA_AFFECTED = 1
|
|
|
|
RAY_CI_PYTHON_AFFECTED = 1
|
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2020-06-03 09:04:55 -07:00
|
|
|
RAY_CI_DASHBOARD_AFFECTED = 1
|
2020-08-07 23:05:18 -07:00
|
|
|
RAY_CI_DOC_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
else:
|
|
|
|
RAY_CI_TUNE_AFFECTED = 1
|
2020-07-25 06:22:54 +02:00
|
|
|
RAY_CI_SGD_AFFECTED = 1
|
2021-10-18 22:27:46 -07:00
|
|
|
RAY_CI_TRAIN_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_RLLIB_AFFECTED = 1
|
2019-09-13 21:36:56 -07:00
|
|
|
RAY_CI_SERVE_AFFECTED = 1
|
2021-10-29 16:47:54 -07:00
|
|
|
RAY_CI_CORE_CPP_AFFECTED = 1
|
|
|
|
RAY_CI_CPP_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_JAVA_AFFECTED = 1
|
|
|
|
RAY_CI_PYTHON_AFFECTED = 1
|
2020-08-07 23:05:18 -07:00
|
|
|
RAY_CI_DOC_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2021-01-15 09:43:34 -08:00
|
|
|
RAY_CI_DASHBOARD_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
else:
|
|
|
|
RAY_CI_TUNE_AFFECTED = 1
|
2020-07-25 06:22:54 +02:00
|
|
|
RAY_CI_SGD_AFFECTED = 1
|
2021-10-18 22:27:46 -07:00
|
|
|
RAY_CI_TRAIN_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_RLLIB_AFFECTED = 1
|
2021-11-04 20:40:57 +01:00
|
|
|
RAY_CI_RLLIB_DIRECTLY_AFFECTED = 1
|
2019-09-13 21:36:56 -07:00
|
|
|
RAY_CI_SERVE_AFFECTED = 1
|
2021-10-29 16:47:54 -07:00
|
|
|
RAY_CI_CPP_AFFECTED = 1
|
|
|
|
RAY_CI_CORE_CPP_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_JAVA_AFFECTED = 1
|
|
|
|
RAY_CI_PYTHON_AFFECTED = 1
|
2020-08-07 23:05:18 -07:00
|
|
|
RAY_CI_DOC_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
RAY_CI_LINUX_WHEELS_AFFECTED = 1
|
|
|
|
RAY_CI_MACOS_WHEELS_AFFECTED = 1
|
2021-01-15 09:43:34 -08:00
|
|
|
RAY_CI_DASHBOARD_AFFECTED = 1
|
2019-03-15 22:23:54 -07:00
|
|
|
|
2019-09-13 21:36:56 -07:00
|
|
|
# Log the modified environment variables visible in console.
|
2022-01-29 18:41:57 -08:00
|
|
|
output_string = " ".join(
|
|
|
|
[
|
|
|
|
"RAY_CI_TUNE_AFFECTED={}".format(RAY_CI_TUNE_AFFECTED),
|
|
|
|
"RAY_CI_SGD_AFFECTED={}".format(RAY_CI_SGD_AFFECTED),
|
|
|
|
"RAY_CI_TRAIN_AFFECTED={}".format(RAY_CI_TRAIN_AFFECTED),
|
|
|
|
"RAY_CI_RLLIB_AFFECTED={}".format(RAY_CI_RLLIB_AFFECTED),
|
|
|
|
"RAY_CI_RLLIB_DIRECTLY_AFFECTED={}".format(RAY_CI_RLLIB_DIRECTLY_AFFECTED),
|
|
|
|
"RAY_CI_SERVE_AFFECTED={}".format(RAY_CI_SERVE_AFFECTED),
|
|
|
|
"RAY_CI_DASHBOARD_AFFECTED={}".format(RAY_CI_DASHBOARD_AFFECTED),
|
|
|
|
"RAY_CI_DOC_AFFECTED={}".format(RAY_CI_DOC_AFFECTED),
|
|
|
|
"RAY_CI_CORE_CPP_AFFECTED={}".format(RAY_CI_CORE_CPP_AFFECTED),
|
|
|
|
"RAY_CI_CPP_AFFECTED={}".format(RAY_CI_CPP_AFFECTED),
|
|
|
|
"RAY_CI_JAVA_AFFECTED={}".format(RAY_CI_JAVA_AFFECTED),
|
|
|
|
"RAY_CI_PYTHON_AFFECTED={}".format(RAY_CI_PYTHON_AFFECTED),
|
|
|
|
"RAY_CI_LINUX_WHEELS_AFFECTED={}".format(RAY_CI_LINUX_WHEELS_AFFECTED),
|
|
|
|
"RAY_CI_MACOS_WHEELS_AFFECTED={}".format(RAY_CI_MACOS_WHEELS_AFFECTED),
|
|
|
|
"RAY_CI_DOCKER_AFFECTED={}".format(RAY_CI_DOCKER_AFFECTED),
|
|
|
|
"RAY_CI_PYTHON_DEPENDENCIES_AFFECTED={}".format(
|
|
|
|
RAY_CI_PYTHON_DEPENDENCIES_AFFECTED
|
|
|
|
),
|
|
|
|
]
|
|
|
|
)
|
2021-01-29 15:48:02 -08:00
|
|
|
|
|
|
|
# Debug purpose
|
|
|
|
print(output_string, file=sys.stderr)
|
|
|
|
|
|
|
|
# Used by buildkite log format
|
|
|
|
if args.output.lower() == "json":
|
|
|
|
pairs = [item.split("=") for item in output_string.split(" ")]
|
|
|
|
affected_vars = [key for key, affected in pairs if affected == "1"]
|
|
|
|
print(json.dumps(affected_vars))
|
|
|
|
else:
|
|
|
|
print(output_string)
|