forked from ray-project/ray
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetermine_tests_to_run.py
279 lines (251 loc) · 11 KB
/
determine_tests_to_run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# Script used for checking changes for incremental testing cases
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import json
import os
from pprint import pformat
import py_dep_analysis as pda
import re
import subprocess
import sys
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
"""
command = ["git", "diff", "--name-only", commit_range, "--"]
out = subprocess.check_output(command)
return [s.strip() for s in out.decode().splitlines() if s is not None]
def is_pull_request():
event_type = None
for key in ["GITHUB_EVENT_NAME", "TRAVIS_EVENT_TYPE"]:
event_type = os.getenv(key, event_type)
if (os.environ.get("BUILDKITE")
and os.environ.get("BUILDKITE_PULL_REQUEST") != "false"):
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"):
commit_range = "origin/{}...{}".format(
os.environ["BUILDKITE_PULL_REQUEST_BASE_BRANCH"],
os.environ["BUILDKITE_COMMIT"],
)
assert commit_range is not None
return commit_range
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--output", type=str, help="json or envvars", default="envvars")
args = parser.parse_args()
RAY_CI_TUNE_AFFECTED = 0
RAY_CI_SGD_AFFECTED = 0
RAY_CI_TRAIN_AFFECTED = 0
# 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
RAY_CI_SERVE_AFFECTED = 0
RAY_CI_CORE_CPP_AFFECTED = 0
RAY_CI_CPP_AFFECTED = 0
RAY_CI_JAVA_AFFECTED = 0
RAY_CI_PYTHON_AFFECTED = 0
RAY_CI_LINUX_WHEELS_AFFECTED = 0
RAY_CI_MACOS_WHEELS_AFFECTED = 0
RAY_CI_DASHBOARD_AFFECTED = 0
RAY_CI_DOCKER_AFFECTED = 0
RAY_CI_DOC_AFFECTED = 0
RAY_CI_PYTHON_DEPENDENCIES_AFFECTED = 0
if is_pull_request():
commit_range = get_commit_range()
files = list_changed_files(commit_range)
print(pformat(commit_range), file=sys.stderr)
print(pformat(files), file=sys.stderr)
# 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()
print(
"Total # of RLlib tests: ", len(rllib_tests), file=sys.stderr)
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.
skip_prefix_list = [
"doc/", "examples/", "dev/", "kubernetes/", "site/"
]
for changed_file in files:
if changed_file.startswith("python/ray/tune"):
RAY_CI_DOC_AFFECTED = 1
RAY_CI_TUNE_AFFECTED = 1
RAY_CI_RLLIB_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
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
elif changed_file.startswith("python/ray/train"):
RAY_CI_TRAIN_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
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
RAY_CI_ML_UTILS_AFFECTED = 1
elif re.match("^(python/ray/)?rllib/", changed_file):
RAY_CI_RLLIB_AFFECTED = 1
RAY_CI_RLLIB_DIRECTLY_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
elif changed_file.startswith("python/ray/serve"):
RAY_CI_DOC_AFFECTED = 1
RAY_CI_SERVE_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
elif changed_file.startswith("python/ray/dashboard"):
RAY_CI_DASHBOARD_AFFECTED = 1
# https://github.com/ray-project/ray/pull/15981
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
elif changed_file.startswith("dashboard"):
RAY_CI_DASHBOARD_AFFECTED = 1
# https://github.com/ray-project/ray/pull/15981
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
elif changed_file.startswith("python/"):
RAY_CI_TUNE_AFFECTED = 1
RAY_CI_SGD_AFFECTED = 1
RAY_CI_TRAIN_AFFECTED = 1
RAY_CI_RLLIB_AFFECTED = 1
RAY_CI_SERVE_AFFECTED = 1
RAY_CI_PYTHON_AFFECTED = 1
RAY_CI_DASHBOARD_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
RAY_CI_DOC_AFFECTED = 1
# Python changes might impact cross language stack in Java.
# Java also depends on Python CLI to manage processes.
RAY_CI_JAVA_AFFECTED = 1
if changed_file.startswith("python/setup.py") or re.match(
".*requirements.*\.txt", changed_file):
RAY_CI_PYTHON_DEPENDENCIES_AFFECTED = 1
elif changed_file.startswith("java/"):
RAY_CI_JAVA_AFFECTED = 1
elif changed_file.startswith("cpp/"):
RAY_CI_CPP_AFFECTED = 1
elif changed_file.startswith("docker/"):
RAY_CI_DOCKER_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
elif changed_file.startswith("doc/") and changed_file.endswith(
".py"):
RAY_CI_DOC_AFFECTED = 1
elif any(
changed_file.startswith(prefix)
for prefix in skip_prefix_list):
# nothing is run but linting in these cases
pass
elif changed_file.endswith("build-docker-images.py"):
RAY_CI_DOCKER_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
elif changed_file.startswith("src/"):
RAY_CI_TUNE_AFFECTED = 1
RAY_CI_SGD_AFFECTED = 1
RAY_CI_TRAIN_AFFECTED = 1
RAY_CI_RLLIB_AFFECTED = 1
RAY_CI_SERVE_AFFECTED = 1
RAY_CI_CORE_CPP_AFFECTED = 1
RAY_CI_CPP_AFFECTED = 1
RAY_CI_JAVA_AFFECTED = 1
RAY_CI_PYTHON_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
RAY_CI_DASHBOARD_AFFECTED = 1
RAY_CI_DOC_AFFECTED = 1
else:
RAY_CI_TUNE_AFFECTED = 1
RAY_CI_SGD_AFFECTED = 1
RAY_CI_TRAIN_AFFECTED = 1
RAY_CI_RLLIB_AFFECTED = 1
RAY_CI_SERVE_AFFECTED = 1
RAY_CI_CORE_CPP_AFFECTED = 1
RAY_CI_CPP_AFFECTED = 1
RAY_CI_JAVA_AFFECTED = 1
RAY_CI_PYTHON_AFFECTED = 1
RAY_CI_DOC_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
RAY_CI_DASHBOARD_AFFECTED = 1
else:
RAY_CI_TUNE_AFFECTED = 1
RAY_CI_SGD_AFFECTED = 1
RAY_CI_TRAIN_AFFECTED = 1
RAY_CI_RLLIB_AFFECTED = 1
RAY_CI_RLLIB_DIRECTLY_AFFECTED = 1
RAY_CI_SERVE_AFFECTED = 1
RAY_CI_CPP_AFFECTED = 1
RAY_CI_CORE_CPP_AFFECTED = 1
RAY_CI_JAVA_AFFECTED = 1
RAY_CI_PYTHON_AFFECTED = 1
RAY_CI_DOC_AFFECTED = 1
RAY_CI_LINUX_WHEELS_AFFECTED = 1
RAY_CI_MACOS_WHEELS_AFFECTED = 1
RAY_CI_DASHBOARD_AFFECTED = 1
# Log the modified environment variables visible in console.
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),
])
# 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)