-
Notifications
You must be signed in to change notification settings - Fork 30
317 lines (278 loc) · 13.2 KB
/
e2e_tests.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# several test modes:
# - ALL: run all modes below (only useful for manual trigger)
# - CUSTOM: choose git branch and endpoint (only useful for manual trigger)
# - MAIN_STAGING: main branch against STAGING
# - RELEASE_PREPROD: latest release branch against PREPROD
# - MAIN_LTS: main branch against LTS
# - PREV_RELEASE_TESTS_STAGING: SDK from main, previous release tests against STAGING
# - LTS_CYCLE_FIRST_SDK_STAGING: test with first SDK of LTS cycle, against STAGING
name: E2E tests
on:
workflow_dispatch:
inputs:
runE2ETests:
description: "Run E2E tests?"
required: true
type: boolean
default: true
runNotebookTests:
description: "Run notebook tests?"
required: true
type: boolean
default: true
testMode:
description: "Test mode: ALL (run all modes), CUSTOM (specify branch and endpoint), MAIN_STAGING (main branch against STAGING), RELEASE_PREPROD (latest release branch against PREPROD), MAIN_LTS (main branch against LTS), PREV_RELEASE_TESTS_STAGING (SDK from main, previous release tests against STAGING), LTS_CYCLE_FIRST_SDK_STAGING (test with first SDK of LTS cycle, against STAGING)"
required: true
type: choice
default: "MAIN_STAGING"
options:
- ALL
- CUSTOM
- MAIN_STAGING
- RELEASE_PREPROD
- MAIN_LTS
- PREV_RELEASE_TESTS_STAGING
- LTS_CYCLE_FIRST_SDK_STAGING
customBranch:
description: "Custom branch to test a PR (only used if test mode is CUSTOM)"
required: false
type: string
default: ""
customEndpoint:
description: "Custom endpoint to test a PR (only used if test mode is CUSTOM)"
required: false
type: choice
default: "STAGING"
options:
- "STAGING"
- "PROD"
- "PREPROD"
- "LTS"
push:
branches:
- "release/**"
- main
schedule:
- cron: "0 7,15 * * 1-5" # MAIN_STAGING
- cron: "0 11 * * 1-5" # PREV_RELEASE_TESTS_STAGING
- cron: "0 13 * * 1-5" # LTS_CYCLE_FIRST_SDK_STAGING
jobs:
test_setup:
name: E2E tests setup
if: github.repository == 'kili-technology/kili-python-sdk'
runs-on: ubuntu-latest
outputs:
test_mode_array: ${{ steps.setup_step.outputs.TEST_MODE_ARRAY }}
steps:
- name: Setup test mode
id: setup_step
shell: bash
run: |
if [[ "${{ github.event_name }}" == "push" ]]; then
if [[ "${{ github.ref_name }}" == release/* ]]; then
# if the push was on a release branch, it can be either
# the lts branch -> LTS_CYCLE_FIRST_SDK_STAGING mode
# or the latest release branch -> RELEASE_PREPROD mode
if [[ "${{ github.ref_name }}" == release/2.146.0 ]]; then
json_str="{\"array\": [\"LTS_CYCLE_FIRST_SDK_STAGING\"]}"
else
json_str="{\"array\": [\"RELEASE_PREPROD\"]}"
fi
else
json_str="{\"array\": [\"MAIN_STAGING\"]}"
fi
elif [[ "${{ github.event_name }}" == "schedule" ]]; then
if [[ "${{ github.event.schedule }}" == "0 7,15 * * 1-5" ]]; then
json_str="{\"array\": [\"MAIN_STAGING\"]}"
elif [[ "${{ github.event.schedule }}" == "0 9 * * 1-5" ]]; then
json_str="{\"array\": [\"MAIN_LTS\"]}"
elif [[ "${{ github.event.schedule }}" == "0 11 * * 1-5" ]]; then
json_str="{\"array\": [\"PREV_RELEASE_TESTS_STAGING\"]}"
elif [[ "${{ github.event.schedule }}" == "0 13 * * 1-5" ]]; then
json_str="{\"array\": [\"LTS_CYCLE_FIRST_SDK_STAGING\"]}"
fi
elif [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
if [[ "${{ github.event.inputs.testMode }}" == "ALL" ]]; then
json_str="{\"array\": [\"MAIN_STAGING\", \"RELEASE_PREPROD\", \"MAIN_LTS\", \"PREV_RELEASE_TESTS_STAGING\", \"LTS_CYCLE_FIRST_SDK_STAGING\"]}"
else
json_str="{\"array\": [\"${{ github.event.inputs.testMode }}\"]}"
fi
fi
echo "TEST_MODE_ARRAY=$json_str" >> $GITHUB_OUTPUT
tests:
name: ${{ matrix.test_mode }}, ${{ matrix.os }}, ${{ matrix.python-version }}
if: github.repository == 'kili-technology/kili-python-sdk'
strategy:
max-parallel: 1
matrix:
test_mode: ${{ fromJson(needs.test_setup.outputs.test_mode_array).array }}
os:
- ubuntu-latest
- windows-latest
include:
- os: ubuntu-latest
python-version: 3.8
- os: windows-latest
python-version: 3.12
runs-on: ${{ matrix.os }}
needs: [test_setup]
steps:
- name: Set test mode
shell: bash
run: echo "TEST_MODE=${{ matrix.test_mode }}" >> $GITHUB_ENV
- name: Check that test mode is valid
shell: bash
run: |
if [[ ${{ env.TEST_MODE }} != "MAIN_STAGING" ]] && \
[[ ${{ env.TEST_MODE }} != "CUSTOM" ]] && \
[[ ${{ env.TEST_MODE }} != "RELEASE_PREPROD" ]] && \
[[ ${{ env.TEST_MODE }} != "MAIN_LTS" ]] && \
[[ ${{ env.TEST_MODE }} != "PREV_RELEASE_TESTS_STAGING" ]] && \
[[ ${{ env.TEST_MODE }} != "LTS_CYCLE_FIRST_SDK_STAGING" ]]; then
echo "TEST_MODE is not valid: ${{ env.TEST_MODE }}"
exit 1
fi
- name: Set first SDK version of LTS cycle
if: env.TEST_MODE == 'LTS_CYCLE_FIRST_SDK_STAGING'
shell: bash
run: echo "LTS_CYCLE_FIRST_SDK_REF=release/2.146.0" >> $GITHUB_ENV # this should be updated when a new LTS cycle starts
- name: Add latest release branch to github env
shell: bash
timeout-minutes: 3
run: |
curl https://raw.githubusercontent.com/kili-technology/kili-python-sdk/main/.github/scripts/add_latest_release_branch_to_github_env.py --output add_latest_release_branch_to_github_env.py
python add_latest_release_branch_to_github_env.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Set checkout branch/tag and endpoint
shell: bash
run: |
if [[ "${{ env.TEST_MODE }}" == "MAIN_STAGING" ]]; then
echo "REF=main" >> $GITHUB_ENV
echo "TEST_AGAINST=STAGING" >> $GITHUB_ENV
elif [[ "${{ env.TEST_MODE }}" == "RELEASE_PREPROD" ]]; then
echo "REF=${{ env.LASTEST_RELEASE_BRANCH }}" >> $GITHUB_ENV
echo "TEST_AGAINST=PREPROD" >> $GITHUB_ENV
elif [[ "${{ env.TEST_MODE }}" == "MAIN_LTS" ]]; then
echo "REF=main" >> $GITHUB_ENV
echo "TEST_AGAINST=LTS" >> $GITHUB_ENV
elif [[ "${{ env.TEST_MODE }}" == "PREV_RELEASE_TESTS_STAGING" ]]; then
echo "REF=${{ env.LASTEST_RELEASE_BRANCH }}" >> $GITHUB_ENV
echo "TEST_AGAINST=STAGING" >> $GITHUB_ENV
elif [[ "${{ env.TEST_MODE }}" == "LTS_CYCLE_FIRST_SDK_STAGING" ]]; then
echo "REF=${{ env.LTS_CYCLE_FIRST_SDK_REF }}" >> $GITHUB_ENV
echo "TEST_AGAINST=STAGING" >> $GITHUB_ENV
elif [[ "${{ env.TEST_MODE }}" == "CUSTOM" ]]; then
echo "REF=${{ github.event.inputs.customBranch }}" >> $GITHUB_ENV
echo "TEST_AGAINST=${{ github.event.inputs.customEndpoint }}" >> $GITHUB_ENV
fi
- name: Set KILI_API_ENDPOINT
shell: bash
run: |
if [[ "${{ env.TEST_AGAINST }}" == "STAGING" ]]; then
echo "KILI_API_ENDPOINT=https://staging.cloud.kili-technology.com/api/label/v2/graphql" >> $GITHUB_ENV
elif [[ "${{ env.TEST_AGAINST }}" == "PREPROD" ]]; then
echo "KILI_API_ENDPOINT=https://preproduction.cloud.kili-technology.com/api/label/v2/graphql" >> $GITHUB_ENV
elif [[ "${{ env.TEST_AGAINST }}" == "LTS" ]]; then
echo "KILI_API_ENDPOINT=https://lts.cloud.kili-technology.com/api/label/v2/graphql" >> $GITHUB_ENV
elif [[ "${{ env.TEST_AGAINST }}" == "PROD" ]]; then
echo "KILI_API_ENDPOINT=https://cloud.kili-technology.com/api/label/v2/graphql" >> $GITHUB_ENV
else
echo "TEST_AGAINST is not valid: ${{ env.TEST_AGAINST }}"
exit 1
fi
- name: Check REF is set
shell: bash
run: |
if [[ -z "${{ env.REF }}" ]]; then
echo "REF is not set"
exit 1
fi
- name: Checkout repo
uses: actions/checkout@v4
with:
ref: ${{ env.REF }}
- name: Delete src for PREV_RELEASE_TESTS_STAGING mode
if: env.TEST_MODE == 'PREV_RELEASE_TESTS_STAGING'
shell: bash
run: rm -rf src # we want the previous release tests but the kili from main
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Upgrade pip
run: python -m pip install --upgrade pip
- name: Install kili
shell: bash
run: |
if [[ "${{ env.TEST_MODE }}" == "PREV_RELEASE_TESTS_STAGING" ]]; then
pip install "kili[dev] @ git+https://github.com/kili-technology/kili-python-sdk.git@main"
else
pip install -e ".[dev]"
fi
- name: Get kili SDK version
shell: bash
run: echo "KILI_SDK_VERSION=$(python -c "from kili import __version__; print(__version__)")" >> $GITHUB_ENV
- name: E2E tests
id: e2e
if: github.event.inputs.runE2ETests != 'false'
timeout-minutes: 60
run: pytest --timeout=600 -ra -sv --color yes --code-highlight yes --durations=0 -vv --ignore tests/e2e/test_notebooks.py tests/e2e
env:
KILI_API_CLOUD_VISION: ${{ secrets.KILI_API_CLOUD_VISION }}
KILI_API_ENDPOINT: ${{ env.KILI_API_ENDPOINT }}
KILI_API_KEY: ${{ secrets[format('KILI_USER_API_KEY_{0}', env.TEST_AGAINST)] }}
KILI_USER_EMAIL: ${{ secrets[format('KILI_USER_EMAIL_{0}', env.TEST_AGAINST)] }}
KILI_USER_ID: ${{ secrets[format('KILI_USER_ID_{0}', env.TEST_AGAINST)] }}
KILI_TEST_DATA_INTEGRATION_ID: ${{ secrets.KILI_TEST_DATA_INTEGRATION_ID }}
KILI_TEST_ORGANIZATION_ID: ${{ secrets[format('KILI_TEST_ORGANIZATION_ID_{0}', env.TEST_AGAINST)] }}
KILI_TEST_AWS_ACCESS_POINT_ARN: ${{ secrets.KILI_TEST_AWS_ACCESS_POINT_ARN }}
KILI_TEST_AWS_ROLE_ARN: ${{ secrets.KILI_TEST_AWS_ROLE_ARN }}
KILI_TEST_AWS_ROLE_EXTERNAL_ID: ${{ secrets.KILI_TEST_AWS_ROLE_EXTERNAL_ID }}
- name: Notebook tests
# we don't run notebook tests on push to main
# we run regardless of the outcome of the e2e tests
if: ${{ !cancelled() && github.event.inputs.runNotebookTests != 'false' && (github.event_name != 'push' || github.ref_name != 'main') && (steps.e2e.outcome != 'cancelled') }}
timeout-minutes: 60
run: pytest --timeout=600 -ra -sv --color yes --code-highlight yes --durations=0 -vv tests/e2e/test_notebooks.py
env:
KILI_API_CLOUD_VISION: ${{ secrets.KILI_API_CLOUD_VISION }}
KILI_API_ENDPOINT: ${{ env.KILI_API_ENDPOINT }}
KILI_API_KEY: ${{ secrets[format('KILI_USER_API_KEY_{0}', env.TEST_AGAINST)] }}
KILI_USER_EMAIL: ${{ secrets[format('KILI_USER_EMAIL_{0}', env.TEST_AGAINST)] }}
KILI_USER_ID: ${{ secrets[format('KILI_USER_ID_{0}', env.TEST_AGAINST)] }}
KILI_TEST_DATA_INTEGRATION_ID: ${{ secrets.KILI_TEST_DATA_INTEGRATION_ID }}
PYDEVD_DISABLE_FILE_VALIDATION: true
- name: Check that kili SDK version has not changed
shell: bash
run: |
kili_sdk_version=$(python -c "from kili import __version__; print(__version__)")
if [[ "${{ env.KILI_SDK_VERSION }}" != "$kili_sdk_version" ]]; then
echo "Kili has been updated (maybe by notebooks)."
echo "The version should not be updated during tests."
echo "version before: ${{ env.KILI_SDK_VERSION }}"
echo "version after: $kili_sdk_version"
exit 1
fi
- name: Slack notification if failure
if: failure() && (github.event_name != 'workflow_dispatch') # doesn't notify for manual runs
id: slack
uses: slackapi/[email protected]
with:
payload: |
{
"text": "E2E tests '${{ env.TEST_MODE }}' (branch '${{ env.REF }}' against endpoint '${{ env.TEST_AGAINST }}') failed with status '${{ job.status }}'\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "E2E tests '${{ env.TEST_MODE }}' (branch '${{ env.REF }}' against endpoint '${{ env.TEST_AGAINST }}') failed with status '${{ job.status }}'\n${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
}
]
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL_PYTHON_SDK_ALARMING }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK