Skip to content

Commit 6e3a6b4

Browse files
authored
chore: Run only the changed submodule's tests for test-only PRs (#5936)
Previously detect-changes treated any change under a submodule as a source change, recursively pulling in all dependent submodules. For PRs that only touch a submodule's tests/ directory this ran the full suite unnecessarily. Add is_source_changed() and split detection into two passes: source changes still propagate to dependents, while test-only changes add just the changed submodule without propagation.
1 parent 63ac789 commit 6e3a6b4

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

.github/workflows/pr-checks-master.yml

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,40 @@ jobs:
118118
fi
119119
}
120120
121-
# Check which submodules changed and add them plus their dependents
122-
if echo "$CHANGES" | grep -q "^sagemaker-core/"; then
123-
echo "sagemaker-core changed - will add core and all dependents"
124-
add_module_and_dependents "sagemaker-core"
125-
fi
121+
# Determine whether a module has any non-test changes. A change counts
122+
# as a source change if it touches anything under the module other than
123+
# its tests/ directory (e.g. src/, pyproject.toml, tox.ini, VERSION).
124+
# This is intentionally conservative: only changes confined entirely to
125+
# tests/ are treated as test-only.
126+
is_source_changed() {
127+
local module=$1
128+
echo "$CHANGES" | grep "^$module/" | grep -qv "^$module/tests/"
129+
}
126130
127-
if echo "$CHANGES" | grep -q "^sagemaker-train/"; then
128-
echo "sagemaker-train changed - will add train and all dependents"
129-
add_module_and_dependents "sagemaker-train"
130-
fi
131+
all_modules=("sagemaker-core" "sagemaker-train" "sagemaker-serve" "sagemaker-mlops")
131132
132-
if echo "$CHANGES" | grep -q "^sagemaker-serve/"; then
133-
echo "sagemaker-serve changed - will add serve and all dependents"
134-
add_module_and_dependents "sagemaker-serve"
135-
fi
133+
# Pass 1: modules with source changes pull in themselves plus every
134+
# module that (transitively) depends on them, since a source change can
135+
# affect downstream behaviour. This preserves the original logic.
136+
for module in "${all_modules[@]}"; do
137+
if is_source_changed "$module"; then
138+
echo "$module has source changes - adding it and all dependents"
139+
add_module_and_dependents "$module"
140+
fi
141+
done
136142
137-
if echo "$CHANGES" | grep -q "^sagemaker-mlops/"; then
138-
echo "sagemaker-mlops changed - will add mlops"
139-
add_module_and_dependents "sagemaker-mlops"
140-
fi
143+
# Pass 2: modules with test-only changes add only themselves and skip
144+
# dependency propagation, since changing a module's tests cannot affect
145+
# other modules. Run after Pass 1 so source-change propagation is never
146+
# short-circuited by a test-only module already being in the set.
147+
for module in "${all_modules[@]}"; do
148+
if echo "$CHANGES" | grep -q "^$module/" && ! is_source_changed "$module"; then
149+
if [ -z "${SUBMODULES_SET[$module]}" ]; then
150+
echo "$module has test-only changes - adding only $module"
151+
SUBMODULES_SET["$module"]=1
152+
fi
153+
fi
154+
done
141155
142156
# Convert associative array to JSON array
143157
SUBMODULES='[]'

0 commit comments

Comments
 (0)