-
Notifications
You must be signed in to change notification settings - Fork 4
238 lines (232 loc) · 9.52 KB
/
pr-checks.yml
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
name: PR Checks
on:
pull_request_target:
branches:
- "main*"
permissions:
id-token: write # This is required for requesting the JWT
contents: read
packages: 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.GITHUB_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(error)
console.log("${{ github.event.pull_request.user.login }} is not a collaborator for "+ context.repo.repo + ". 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 Integration tests"
integ-tests:
runs-on: ubuntu-latest
needs: [wait-for-approval]
strategy:
fail-fast: false
matrix:
python-version: [ "3.12" ]
env:
SUBNET_ONE: ${{ secrets.SUBNET_ONE }}
SUBNET_TWO: ${{ secrets.SUBNET_TWO }}
SECURITY_GROUP_ONE: ${{ secrets.SECURITY_GROUP_ONE }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
export PYTHONPATH="$PYTHONPATH:$PWD"
python -m pip install --upgrade pip
pip install scikit-learn sagemaker setuptools awscli
pip install -e ".[codegen]"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.INTEG_TEST_ROLE_ARN }}
aws-region: us-west-2
role-duration-seconds: 10800
- name: Run Integration Tests
id: run-integration-tests
run: |
pytest integ
- name: Put Failure Metrics to CloudWatch
if: ${{ failure() }}
run: |
if [[ "${{ github.event.pull_request.user.login }}" == ${{ secrets.SAGEMAKER_BOT_USER_LOGIN }} ]]; then
echo "Integration test Failed. Putting Failure Metrics onto Cloudwatch"
aws cloudwatch put-metric-data --metric-name IntegrationTestFailure --namespace SageMakerPySdkCoreMonitoringMetrics --value 1 --unit Count --dimensions MetricCategory=Integration
else
echo "Putting metrics has been skipped"
fi
- name: Put Success Metrics to CloudWatch
if: ${{ success() }}
run: |
if [[ "${{ github.event.pull_request.user.login }}" == ${{ secrets.SAGEMAKER_BOT_USER_LOGIN }} ]]; then
echo "Integration test Succeeded. Putting Success Metrics onto Cloudwatch"
aws cloudwatch put-metric-data --metric-name IntegrationTestSuccess --namespace SageMakerPySdkCoreMonitoringMetrics --value 1 --unit Count --dimensions MetricCategory=Integration
else
echo "Putting metrics has been skipped"
fi
unit-tests:
runs-on: ubuntu-latest
needs: [wait-for-approval]
strategy:
fail-fast: false
matrix:
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
export PYTHONPATH="$PYTHONPATH:$PWD"
python -m pip install --upgrade pip
pip install -e ".[codegen]"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.INTEG_TEST_ROLE_ARN }}
aws-region: us-west-2
role-duration-seconds: 10800
- name: Run Unit Tests
run: |
pytest tst
- name: Put Failure Metrics
if: ${{ failure() }}
run: |
if [[ "${{ github.event.pull_request.user.login }}" == ${{ secrets.SAGEMAKER_BOT_USER_LOGIN }} ]]; then
echo "Unit test run Failed. Putting Failure Metrics onto Cloudwatch"
aws cloudwatch put-metric-data --metric-name UnitTestFailure --namespace SageMakerPySdkCoreMonitoringMetrics --value 1 --unit Count --dimensions MetricCategory=Unit-${{ matrix.python-version }}
else
echo "Putting metrics has been skipped"
fi
- name: Put Success Metrics
if: ${{ success() }}
run: |
if [[ "${{ github.event.pull_request.user.login }}" == ${{ secrets.SAGEMAKER_BOT_USER_LOGIN }} ]]; then
echo "Unit test run Succeeded. Putting Success Metrics onto Cloudwatch"
aws cloudwatch put-metric-data --metric-name UnitTestSuccess --namespace SageMakerPySdkCoreMonitoringMetrics --value 1 --unit Count --dimensions MetricCategory=Unit-${{ matrix.python-version }}
else
echo "Putting metrics has been skipped"
fi
resources-coverage:
runs-on: ubuntu-latest
needs: [wait-for-approval]
strategy:
fail-fast: false
matrix:
python-version: [ "3.12" ]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.INTEG_TEST_ROLE_ARN }}
aws-region: us-west-2
role-duration-seconds: 10800
- name: Install dependencies
run: |
export PYTHONPATH="$PYTHONPATH:$PWD"
python -m pip install --upgrade pip
pip install coverage
pip install pytest-cov
pip install -e ".[codegen]"
- name: Run Unit Tests
run: |
pytest --cov-report json --cov=src tst/generated/test_resources.py
- name: Execute Python Coverage compute script and capture output
id: execute_coverage_parse_script
run: |
if [[ "${{ github.event.pull_request.user.login }}" == ${{ secrets.SAGEMAKER_BOT_USER_LOGIN }}* ]]; then
aws cloudwatch put-metric-data --metric-name UnitTestCoverage --namespace SageMakerPySdkCoreMonitoringMetrics --value $(python workflow_helper/compute_resource_coverage.py) --unit Count --dimensions MetricCategory=Unit-${{ matrix.python-version }}
else
echo "Putting metrics has been skipped"
fi
put-api-coverage:
runs-on: ubuntu-latest
needs: [wait-for-approval]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Install dependencies
run: |
export PYTHONPATH="$PYTHONPATH:$PWD"
python -m pip install --upgrade pip
pip install -e ".[codegen]"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.INTEG_TEST_ROLE_ARN }}
aws-region: us-west-2
role-duration-seconds: 10800
- name: Execute Boto API Coverage compute script and capture output
run: |
if [[ "${{ github.event.pull_request.user.login }}" == ${{ secrets.SAGEMAKER_BOT_USER_LOGIN }}* ]]; then
output=$(python workflow_helper/compute_boto_api_coverage.py)
unsupported_apis=$(echo $output | cut -d ' ' -f1)
supported_apis=$(echo $output | cut -d ' ' -f2)
aws cloudwatch put-metric-data --metric-name UnsupportedAPIs --namespace SageMakerPySdkCoreMonitoringMetrics --value $unsupported_apis --unit Count --dimensions MetricCategory=BotocoreAPICoverage
aws cloudwatch put-metric-data --metric-name SupportedAPIs --namespace SageMakerPySdkCoreMonitoringMetrics --value $supported_apis --unit Count --dimensions MetricCategory=BotocoreAPICoverage
else
echo "Putting metrics has been skipped"
fi
pylint-codestyle:
runs-on: ubuntu-latest
needs: [wait-for-approval]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- name: Install dependencies
run: |
export PYTHONPATH="$PYTHONPATH:$PWD"
python -m pip install --upgrade pip
pip install -e ".[codegen]"
- name: Run Pylint
run: |
python_files=$(find . -name '*.py')
pylint $python_files --persistent=y --fail-under=8
- name: Run Black Check
run: |
black --check .