-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathdetect_test_components.sh
More file actions
executable file
·154 lines (139 loc) · 4.98 KB
/
Copy pathdetect_test_components.sh
File metadata and controls
executable file
·154 lines (139 loc) · 4.98 KB
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
#!/bin/bash
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# Helper script to detect which test components should run based on changed files.
# Source this script to set the CUOPT_TEST_COMPONENTS variable.
#
# Usage: source ci/detect_test_components.sh
#
# Sets CUOPT_TEST_COMPONENTS to a comma-separated list of components (routing,lp,mip)
# or "all" if broad/shared changes are detected or if not in a pull-request build.
set -euo pipefail
detect_test_components() {
# If CUOPT_TEST_COMPONENTS is already set externally, respect it
if [[ -n "${CUOPT_TEST_COMPONENTS:-}" ]]; then
export CUOPT_TEST_COMPONENTS
return
fi
# Only apply selective testing for pull-request builds
if [[ "${RAPIDS_BUILD_TYPE:-}" != "pull-request" ]]; then
export CUOPT_TEST_COMPONENTS="all"
return
fi
# In RAPIDS CI pull-request builds, the branch is a merge commit so
# HEAD~1..HEAD gives the full PR diff. If the parent isn't reachable
# (e.g. shallow clone or non-merge workflow), fall back to running all.
local changed_files
if ! git rev-parse --verify HEAD~1 &>/dev/null; then
export CUOPT_TEST_COMPONENTS="all"
return
fi
if ! changed_files=$(git diff --name-only HEAD~1..HEAD 2>/dev/null); then
# If git diff fails, run all tests to be safe
export CUOPT_TEST_COMPONENTS="all"
return
fi
if [[ -z "${changed_files}" ]]; then
export CUOPT_TEST_COMPONENTS="all"
return
fi
local components=""
local run_all=false
# Check for shared/infrastructure changes that should trigger all tests
while IFS= read -r file; do
case "${file}" in
cpp/include/*|cpp/cmake/*|cpp/CMakeLists.txt|cpp/src/utilities/*)
run_all=true
break
;;
# Changes to test infrastructure
cpp/tests/CMakeLists.txt|cpp/tests/utilities/*)
run_all=true
break
;;
# Changes to CI infrastructure
ci/test_cpp.sh|ci/test_python.sh|ci/test_wheel_cuopt.sh|ci/run_ctests.sh|ci/run_cuopt_pytests.sh|ci/detect_test_components.sh)
run_all=true
break
;;
# Changes to conda/build config
conda/*|dependencies.yaml)
run_all=true
break
;;
esac
done <<< "${changed_files}"
if ${run_all}; then
export CUOPT_TEST_COMPONENTS="all"
return
fi
# Detect individual components
local has_routing=false
local has_lp=false
local has_mip=false
while IFS= read -r file; do
case "${file}" in
# Routing component
cpp/src/routing/*|cpp/src/distance/*|cpp/tests/routing/*|cpp/tests/distance_engine/*|cpp/tests/examples/routing/*)
has_routing=true
;;
python/cuopt/cuopt/routing/*|python/cuopt/cuopt/tests/routing/*)
has_routing=true
;;
regression/routing*)
has_routing=true
;;
# LP component
cpp/src/dual_simplex/*|cpp/src/barrier/*|cpp/src/pdlp/*|cpp/src/math_optimization/*)
has_lp=true
;;
cpp/tests/linear_programming/*|cpp/tests/dual_simplex/*|cpp/tests/qp/*)
has_lp=true
;;
python/cuopt/cuopt/tests/linear_programming/*|python/cuopt/cuopt/tests/quadratic_programming/*)
has_lp=true
;;
# LP regression
regression/lp*)
has_lp=true
;;
# MIP component
cpp/src/branch_and_bound/*|cpp/src/cuts/*|cpp/src/mip_heuristics/*)
has_mip=true
;;
cpp/tests/mip/*)
has_mip=true
;;
regression/mip*)
has_mip=true
;;
# Python source changes that could affect any component
python/cuopt/cuopt/*.py|python/cuopt/cuopt/distance_engine/*|python/cuopt/cuopt/utils/*)
has_routing=true
has_lp=true
;;
python/libcuopt/*)
has_routing=true
has_lp=true
has_mip=true
;;
esac
done <<< "${changed_files}"
# Build the components string
if ${has_routing}; then
components="${components:+${components},}routing"
fi
if ${has_lp}; then
components="${components:+${components},}lp"
fi
if ${has_mip}; then
components="${components:+${components},}mip"
fi
# If no specific component was detected, default to all
if [[ -z "${components}" ]]; then
components="all"
fi
export CUOPT_TEST_COMPONENTS="${components}"
}
detect_test_components
echo "CUOPT_TEST_COMPONENTS=${CUOPT_TEST_COMPONENTS}"