@@ -74,32 +74,79 @@ jobs:
7474 echo "Changed files:"
7575 echo "$CHANGES"
7676
77- SUBMODULES=[]
77+ # Function to extract dependencies from pyproject.toml
78+ get_dependencies() {
79+ local module=$1
80+ grep "sagemaker-" "$module/pyproject.toml" | grep -o 'sagemaker-[a-z]*' | sort -u
81+ }
82+
83+ # Function to find all modules that depend on a given module (recursively)
84+ find_dependents() {
85+ local target=$1
86+ local all_modules=("sagemaker-core" "sagemaker-train" "sagemaker-serve" "sagemaker-mlops")
87+ local dependents=()
88+
89+ for module in "${all_modules[@]}"; do
90+ if [ "$module" != "$target" ]; then
91+ if get_dependencies "$module" | grep -q "^$target$"; then
92+ dependents+=("$module")
93+ fi
94+ fi
95+ done
96+
97+ echo "${dependents[@]}"
98+ }
99+
100+ # Initialize set of submodules to test (using associative array)
101+ declare -A SUBMODULES_SET
102+
103+ # Function to recursively add module and all its dependents
104+ add_module_and_dependents() {
105+ local module=$1
106+
107+ if [ -z "${SUBMODULES_SET[$module]}" ]; then
108+ SUBMODULES_SET["$module"]=1
109+ echo "Adding $module to test set"
110+
111+ # Find all modules that depend on this one and add them recursively
112+ local dependents=$(find_dependents "$module")
113+ for dependent in $dependents; do
114+ add_module_and_dependents "$dependent"
115+ done
116+ fi
117+ }
118+
119+ # Check which submodules changed and add them plus their dependents
120+ if echo "$CHANGES" | grep -q "^sagemaker-core/"; then
121+ echo "sagemaker-core changed - will add core and all dependents"
122+ add_module_and_dependents "sagemaker-core"
123+ fi
78124
79125 if echo "$CHANGES" | grep -q "^sagemaker-train/"; then
80- SUBMODULES='["sagemaker-train"]'
126+ echo "sagemaker-train changed - will add train and all dependents"
127+ add_module_and_dependents "sagemaker-train"
81128 fi
129+
82130 if echo "$CHANGES" | grep -q "^sagemaker-serve/"; then
83- if [ "$SUBMODULES" = '[]' ]; then
84- SUBMODULES='["sagemaker-serve"]'
85- else
86- SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-serve"\]/')
87- fi
131+ echo "sagemaker-serve changed - will add serve and all dependents"
132+ add_module_and_dependents "sagemaker-serve"
88133 fi
134+
89135 if echo "$CHANGES" | grep -q "^sagemaker-mlops/"; then
90- if [ "$SUBMODULES" = '[]' ]; then
91- SUBMODULES='["sagemaker-mlops"]'
92- else
93- SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-mlops"\]/')
94- fi
136+ echo "sagemaker-mlops changed - will add mlops"
137+ add_module_and_dependents "sagemaker-mlops"
95138 fi
96- if echo "$CHANGES" | grep -q "^sagemaker-core/"; then
139+
140+ # Convert associative array to JSON array
141+ SUBMODULES='[]'
142+ for submodule in "${!SUBMODULES_SET[@]}"; do
97143 if [ "$SUBMODULES" = '[]' ]; then
98- SUBMODULES='["sagemaker-core"]'
144+ SUBMODULES="[\"$submodule\"]"
99145 else
100- SUBMODULES=$(echo $SUBMODULES | sed ' s/\]$/,"sagemaker-core "\]/' )
146+ SUBMODULES=$(echo $SUBMODULES | sed " s/\]$/,\"$submodule\ "\]/" )
101147 fi
102- fi
148+ done
149+
103150 echo "Final SUBMODULES: $SUBMODULES"
104151 echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT
105152
0 commit comments