-
Notifications
You must be signed in to change notification settings - Fork 1.2k
217 lines (191 loc) · 8.01 KB
/
pr-checks-master.yml
File metadata and controls
217 lines (191 loc) · 8.01 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
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
name: Sagemaker PR Checks (Master)
on:
pull_request_target:
branches:
- "master"
paths:
- 'sagemaker-train/**'
- 'sagemaker-serve/**'
- 'sagemaker-mlops/**'
- 'sagemaker-core/**'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.head_ref }}
cancel-in-progress: true
permissions:
id-token: write
jobs:
collab-check:
runs-on: ubuntu-latest
outputs:
approval-env: ${{ steps.collab-check.outputs.result }}
steps:
- name: Collaborator Check
uses: actions/github-script@v7
id: collab-check
with:
github-token: ${{ secrets.COLLAB_CHECK_TOKEN }}
result-encoding: string
script: |
try {
const res = await github.rest.repos.checkCollaborator({
owner: context.repo.owner,
repo: context.repo.repo,
username: "${{ github.event.pull_request.user.login }}",
});
console.log("Verifed ${{ github.event.pull_request.user.login }} is a repo collaborator. Auto Approving PR Checks.")
return res.status == "204" ? "auto-approve" : "manual-approval"
} catch (error) {
console.log("${{ github.event.pull_request.user.login }} is not a collaborator. Requiring Manual Approval to run PR Checks.")
return "manual-approval"
}
wait-for-approval:
runs-on: ubuntu-latest
needs: [ collab-check ]
environment: ${{ needs.collab-check.outputs.approval-env }}
steps:
- run: echo "Workflow Approved! Starting PR Checks."
detect-changes:
runs-on: ubuntu-latest
needs: [wait-for-approval]
outputs:
submodules: ${{ steps.check-changes.outputs.submodules }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.GH_PAT }}
ref: ${{ github.event.pull_request.base.ref }}
- name: Detect Changes
id: check-changes
run: |
set -e
echo "Target Branch: ${{ github.event.pull_request.base.ref }}"
echo "Current Target SHA: $(git rev-parse HEAD)"
echo "PR Number: ${{ github.event.pull_request.number }}"
echo "PR Latest SHA: ${{ github.event.pull_request.head.sha }}"
git fetch origin pull/${{ github.event.pull_request.number }}/head
CHANGES=$(git diff --name-only HEAD FETCH_HEAD)
echo "Changed files:"
echo "$CHANGES"
# Function to extract dependencies from pyproject.toml
get_dependencies() {
local module=$1
grep "sagemaker-" "$module/pyproject.toml" | grep -o 'sagemaker-[a-z]*' | sort -u
}
# Function to find all modules that depend on a given module (recursively)
find_dependents() {
local target=$1
local all_modules=("sagemaker-core" "sagemaker-train" "sagemaker-serve" "sagemaker-mlops")
local dependents=()
for module in "${all_modules[@]}"; do
if [ "$module" != "$target" ]; then
if get_dependencies "$module" | grep -q "^$target$"; then
dependents+=("$module")
fi
fi
done
echo "${dependents[@]}"
}
# Initialize set of submodules to test (using associative array)
declare -A SUBMODULES_SET
# Function to recursively add module and all its dependents
add_module_and_dependents() {
local module=$1
if [ -z "${SUBMODULES_SET[$module]}" ]; then
SUBMODULES_SET["$module"]=1
echo "Adding $module to test set"
# Find all modules that depend on this one and add them recursively
local dependents=$(find_dependents "$module")
for dependent in $dependents; do
add_module_and_dependents "$dependent"
done
fi
}
# Check which submodules changed and add them plus their dependents
if echo "$CHANGES" | grep -q "^sagemaker-core/"; then
echo "sagemaker-core changed - will add core and all dependents"
add_module_and_dependents "sagemaker-core"
fi
if echo "$CHANGES" | grep -q "^sagemaker-train/"; then
echo "sagemaker-train changed - will add train and all dependents"
add_module_and_dependents "sagemaker-train"
fi
if echo "$CHANGES" | grep -q "^sagemaker-serve/"; then
echo "sagemaker-serve changed - will add serve and all dependents"
add_module_and_dependents "sagemaker-serve"
fi
if echo "$CHANGES" | grep -q "^sagemaker-mlops/"; then
echo "sagemaker-mlops changed - will add mlops"
add_module_and_dependents "sagemaker-mlops"
fi
# Convert associative array to JSON array
SUBMODULES='[]'
for submodule in "${!SUBMODULES_SET[@]}"; do
if [ "$SUBMODULES" = '[]' ]; then
SUBMODULES="[\"$submodule\"]"
else
SUBMODULES=$(echo $SUBMODULES | sed "s/\]$/,\"$submodule\"\]/")
fi
done
echo "Final SUBMODULES: $SUBMODULES"
echo "submodules=$SUBMODULES" >> $GITHUB_OUTPUT
codestyle-doc-tests:
runs-on: ubuntu-latest
needs: [detect-changes]
if: needs.detect-changes.outputs.submodules != '[]'
strategy:
fail-fast: false
matrix:
submodule: ${{ fromJson(needs.detect-changes.outputs.submodules) }}
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
aws-region: us-west-2
role-duration-seconds: 10800
- name: Run CodeBuild for ${{ matrix.submodule }}
uses: aws-actions/aws-codebuild-run-build@v1
with:
project-name: ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-codestyle-doc-tests
source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}'
unit-tests:
runs-on: ubuntu-latest
needs: [detect-changes]
if: needs.detect-changes.outputs.submodules != '[]'
strategy:
fail-fast: false
matrix:
submodule: ${{ fromJson(needs.detect-changes.outputs.submodules) }}
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
aws-region: us-west-2
role-duration-seconds: 10800
- name: Run Unit Tests for ${{ matrix.submodule }}
uses: aws-actions/aws-codebuild-run-build@v1
with:
project-name: ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-unit-tests
source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}'
integ-tests:
runs-on: ubuntu-latest
needs: [detect-changes]
if: needs.detect-changes.outputs.submodules != '[]'
strategy:
fail-fast: false
matrix:
submodule: ${{ fromJson(needs.detect-changes.outputs.submodules) }}
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.CI_AWS_ROLE_ARN }}
aws-region: us-west-2
role-duration-seconds: 10800
- name: Run Integ Tests for ${{ matrix.submodule }}
uses: aws-actions/aws-codebuild-run-build@v1
with:
project-name: ${{ github.event.repository.name }}-ci-${{ matrix.submodule }}-integ-tests
source-version-override: 'refs/pull/${{ github.event.pull_request.number }}/head^{${{ github.event.pull_request.head.sha }}}'