|
1 | | -name: Sagemaker PR Checks |
| 1 | +name: Sagemaker PR Checks (Master) |
2 | 2 | on: |
3 | 3 | pull_request_target: |
4 | 4 | branches: |
5 | | - - "master*" |
| 5 | + - "master" |
6 | 6 | paths: |
7 | 7 | - 'sagemaker-train/**' |
8 | 8 | - 'sagemaker-serve/**' |
@@ -56,51 +56,97 @@ jobs: |
56 | 56 | - uses: actions/checkout@v3 |
57 | 57 | with: |
58 | 58 | fetch-depth: 0 |
59 | | - token: ${{ secrets.GH_PAT }} # or use appropriate token |
60 | | - ref: ${{ github.event.pull_request.base.ref }} # Target branch (master-v3) |
| 59 | + token: ${{ secrets.GH_PAT }} |
| 60 | + ref: ${{ github.event.pull_request.base.ref }} |
61 | 61 | - name: Detect Changes |
62 | 62 | id: check-changes |
63 | 63 | run: | |
64 | | - set -e # Exit on error |
| 64 | + set -e |
65 | 65 | |
66 | | - # Debug information |
67 | 66 | echo "Target Branch: ${{ github.event.pull_request.base.ref }}" |
68 | 67 | echo "Current Target SHA: $(git rev-parse HEAD)" |
69 | 68 | echo "PR Number: ${{ github.event.pull_request.number }}" |
70 | 69 | echo "PR Latest SHA: ${{ github.event.pull_request.head.sha }}" |
71 | | - # Fetch PR without creating a branch |
| 70 | + |
72 | 71 | git fetch origin pull/${{ github.event.pull_request.number }}/head |
73 | 72 | CHANGES=$(git diff --name-only HEAD FETCH_HEAD) |
74 | 73 | |
75 | 74 | echo "Changed files:" |
76 | 75 | echo "$CHANGES" |
77 | 76 | |
78 | | - 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 |
79 | 124 | |
80 | 125 | if echo "$CHANGES" | grep -q "^sagemaker-train/"; then |
81 | | - SUBMODULES='["sagemaker-train"]' |
| 126 | + echo "sagemaker-train changed - will add train and all dependents" |
| 127 | + add_module_and_dependents "sagemaker-train" |
82 | 128 | fi |
| 129 | + |
83 | 130 | if echo "$CHANGES" | grep -q "^sagemaker-serve/"; then |
84 | | - if [ "$SUBMODULES" = '[]' ]; then |
85 | | - SUBMODULES='["sagemaker-serve"]' |
86 | | - else |
87 | | - SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-serve"\]/') |
88 | | - fi |
| 131 | + echo "sagemaker-serve changed - will add serve and all dependents" |
| 132 | + add_module_and_dependents "sagemaker-serve" |
89 | 133 | fi |
| 134 | + |
90 | 135 | if echo "$CHANGES" | grep -q "^sagemaker-mlops/"; then |
91 | | - if [ "$SUBMODULES" = '[]' ]; then |
92 | | - SUBMODULES='["sagemaker-mlops"]' |
93 | | - else |
94 | | - SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-mlops"\]/') |
95 | | - fi |
| 136 | + echo "sagemaker-mlops changed - will add mlops" |
| 137 | + add_module_and_dependents "sagemaker-mlops" |
96 | 138 | fi |
97 | | - 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 |
98 | 143 | if [ "$SUBMODULES" = '[]' ]; then |
99 | | - SUBMODULES='["sagemaker-core"]' |
| 144 | + SUBMODULES="[\"$submodule\"]" |
100 | 145 | else |
101 | | - SUBMODULES=$(echo $SUBMODULES | sed 's/\]$/,"sagemaker-core"\]/') |
| 146 | + SUBMODULES=$(echo $SUBMODULES | sed "s/\]$/,\"$submodule\"\]/") |
102 | 147 | fi |
103 | | - fi |
| 148 | + done |
| 149 | + |
104 | 150 | echo "Final SUBMODULES: $SUBMODULES" |
105 | 151 | echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT |
106 | 152 |
|
|
0 commit comments