-
Notifications
You must be signed in to change notification settings - Fork 30
532 lines (469 loc) · 19.8 KB
/
main.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
name: main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
on:
pull_request_target:
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
workflow_dispatch:
inputs:
test_targets:
default: "__ALL__"
description: "Comma separated list to run pytest on, e.g.: `lib/dl_api_lib,lib/dl_core`. Use __ALL__ to run all tests"
run_mypy_only:
type: boolean
default: false
description: "Check to only run mypy"
mypy_timeout_minutes:
type: number
default: 20
description: "Timeout for pytest JOB in minutes"
jobs:
drop-ci-approved-label:
name: Drop CI Allowed label if PR branch changed
runs-on: ubuntu-22.04
permissions:
contents: read
pull-requests: write
steps:
- name: Drop label
env:
GH_TOKEN: ${{ github.token }}
run: |
[[ ${{ github.event_name }} != "pull_request_target" ]] && exit 0
action=${{ github.event.action }}
[[ $action == "labeled" || $action == "unlabeled" || $action == "opened" ]] && exit 0
gh pr edit \
--repo ${{ github.event.repository.full_name }} \
--remove-label "ci-approved" \
${{ github.event.pull_request.number }}
check-ci-allowed:
name: Check if CI allowed for PR
runs-on: ubuntu-22.04
needs: [ drop-ci-approved-label ]
permissions:
contents: read
pull-requests: read
env:
GH_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check user permissions
id: check_user_permissions
working-directory: .github/.scripts
env:
USER: ${{ github.actor }}
PERMISSION: "write"
run: echo "result=$(./gh_user_check_permission.sh)" >> $GITHUB_OUTPUT
- name: Check PR permissions
id: check_pr_permissions
working-directory: .github/.scripts
env:
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
LABEL: "ci-approved"
run: echo "result=$(./gh_pull_request_check_label.sh)" >> $GITHUB_OUTPUT
- name: Combine permissions
run: |
user_allowed=${{ steps.check_user_permissions.outputs.result }}
pr_allowed=${{ steps.check_pr_permissions.outputs.result }}
[[ $user_allowed == "true" || $pr_allowed == "true" ]] && exit 0
echo "ERROR: User have no permissions to run CI and PR is not approved"
exit 1
- name: Checkout branch code
uses: actions/checkout@v4
if: ${{ github.event_name != 'workflow_dispatch' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
path: branch_code
fetch-depth: 0
- name: Check fork PR branch contains latest base sha
if: ${{ github.event_name != 'workflow_dispatch' && github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name }}
working-directory: branch_code
run: git branch --contains ${{ github.event.pull_request.base.sha }}
gh_build_image:
runs-on: ubuntu-22.04
needs: [ check-ci-allowed ]
permissions:
packages: write
contents: read
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/debian_docker:latest"
options: -v /var/run/docker.sock:/var/run/docker.sock
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
env:
REPO_OWNER: ${{ github.repository_owner }}
REPO_NAME: ${{ github.event.repository.name }}
GIT_SHA: "${{ github.sha }}"
steps:
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.ROBOT_GITHUB_PACKAGES_WRITE_TOKEN }}
- uses: datalens-tech/cleanup-folder-action@v1
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
- uses: datalens-tech/fix-dubious-ownership-action@v1
- run: |
export ROOT_DIR="$(realpath .)"
/bin/bash ci/build_naive.sh
router:
runs-on: ubuntu-22.04
needs: gh_build_image
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
outputs:
affected: ${{ steps.get_affected.outputs.affected }}
all_affected_with_skips: ${{ steps.get_affected.outputs.all_affected_with_skips }}
steps:
- uses: datalens-tech/cleanup-folder-action@v1
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- uses: datalens-tech/fix-dubious-ownership-action@v1
- run: git fetch origin main
- name: Extract base commit
run: |
result="${{ github.event.pull_request.base.sha }}"
if [ -z "$result" ]; then
result=$(git rev-parse origin/main)
fi
echo "result=$result" >> $GITHUB_OUTPUT
id: extract_base_commit
- name: Extract head commit
run: |
result="${{ github.event.pull_request.head.sha }}"
if [ -z "$result" ]; then
result=$(git rev-parse HEAD)
fi
echo "result=$result" >> $GITHUB_OUTPUT
id: extract_head_commit
- name: Get packages affected by changes in the current commit
id: get_affected
run: |
TARGET_DATA=$(. /venv/bin/activate && dl-git range-diff-paths --only-added-commits --base ${{ steps.extract_base_commit.outputs.result }} --head ${{ steps.extract_head_commit.outputs.result }})
echo "$TARGET_DATA" > /tmp/targets.json
cat /tmp/targets.json
. /venv/bin/activate && detect-affected-packages \
--repo=/src \
--changes_file="/tmp/targets.json" \
--root_pkgs="lib,app" | tee -a >> "$GITHUB_OUTPUT"
env:
TEST_TARGET_OVERRIDE: ${{ github.event.inputs.test_targets }}
- name: Print affected packages
run: |
echo "Affected packages: ${{ steps.get_affected.outputs.affected }}"
echo "Affected packages, including skipped in CI: ${{ steps.get_affected.outputs.all_affected_with_skips }}"
check-skip-tests-label:
name: Check PR skip tests label
runs-on: ubuntu-22.04
needs: [ check-ci-allowed ]
permissions:
contents: read
pull-requests: read
outputs:
result: ${{ steps.check_skip_label.outputs.result }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check PR skip label
id: check_skip_label
working-directory: .github/.scripts
env:
GH_TOKEN: ${{ github.token }}
OWNER: ${{ github.repository_owner }}
REPO: ${{ github.event.repository.name }}
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
LABEL: "tests-force-skipped"
run: echo "result=$(./gh_pull_request_check_label.sh)" >> $GITHUB_OUTPUT
pytest_split:
name: Split pytest into jobs for each test type
runs-on: ubuntu-22.04
needs: [ router, check-skip-tests-label ]
if: ${{ needs.check-skip-tests-label.outputs.result != 'true' }}
# if: ${{ github.event.inputs.run_mypy_only != 'true' }}
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
outputs:
split_base: ${{ steps.get_split.outputs.split_base }}
split_fat: ${{ steps.get_split.outputs.split_fat }}
split_ext_public: ${{ steps.get_split.outputs.split_ext_public }}
split_no_compose: ${{ steps.get_split.outputs.split_no_compose }}
steps:
- uses: datalens-tech/cleanup-folder-action@v1
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 1
- uses: datalens-tech/fix-dubious-ownership-action@v1
- name: Run python script to split job for general and fat runners
id: get_split
run: |
. /venv/bin/activate && echo '${{ needs.router.outputs.affected }}' >> /tmp/dl_test_targets.json
split-pytest-tasks base,fat,ext_public,no_compose /src /tmp/dl_test_targets.json true true >> "$GITHUB_OUTPUT"
run_tests_base:
name: "🐍[pytest]${{ matrix.value }}"
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read
needs: pytest_split
if: ${{ needs.pytest_split.outputs.split_base != '[]' }}
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
options: -v /var/run/docker.sock:/var/run/docker.sock
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
value: ${{fromJson(needs.pytest_split.outputs.split_base)}}
steps:
- run: echo "Going to run tests for ${{ matrix.value }}"
- run: echo "Running py tests for ${{ matrix.value }}"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: echo compose_path="/src/$(echo ${{ matrix.value }} | cut -d ":" -f1)/" >> "$GITHUB_ENV"
- run: cd "${{ env.compose_path }}" && echo compose_prj="$(basename "$PWD")_$(shuf -i 1000000-1000000000 -n 1)" >> "$GITHUB_ENV"
# We need to set custom compose project name to ensure "unique" container names in the host docker env
- name: run bash script with all logic for starting compose and running tests
run: |
bash /src/ci/execute_test_with_docker_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}" \
WE_ARE_IN_CI=1
- name: Stop compose if provided
# We could not put this into bash script, since job could be cancelled by user request
if: always() # yes! always
run: bash /src/ci/stop_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}"
run_tests_no_compose:
name: "🐍[pytest][no_compose]${{ matrix.value }}"
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read
needs: pytest_split
if: ${{ needs.pytest_split.outputs.split_no_compose != '[]' }}
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
options: -v /var/run/docker.sock:/var/run/docker.sock
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
value: ${{fromJson(needs.pytest_split.outputs.split_no_compose)}}
steps:
- run: echo "Going to run tests for ${{ matrix.value }}"
- run: echo "Running py tests for ${{ matrix.value }}"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: echo compose_path="/src/$(echo ${{ matrix.value }} | cut -d ":" -f1)/" >> "$GITHUB_ENV"
- run: cd "${{ env.compose_path }}" && echo compose_prj="$(basename "$PWD")_$(shuf -i 1000000-1000000000 -n 1)" >> "$GITHUB_ENV"
# We need to set custom compose project name to ensure "unique" container names in the host docker env
- name: run bash script with all logic for starting compose and running tests
run: |
bash /src/ci/execute_test_with_docker_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}" \
WE_ARE_IN_CI=1
- name: Stop compose if provided
# We could not put this into bash script, since job could be cancelled by user request
if: always() # yes! always
run: bash /src/ci/stop_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}"
run_tests_fat:
name: "🐍[pytest][fat]${{ matrix.value }}"
runs-on: ubuntu-22.04
permissions:
packages: write
contents: read
needs: pytest_split
if: ${{ needs.pytest_split.outputs.split_fat != '[]' }}
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
options: -v /var/run/docker.sock:/var/run/docker.sock
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
value: ${{fromJson(needs.pytest_split.outputs.split_fat)}}
steps:
- run: echo "Going to run tests for ${{ matrix.value }}"
- run: echo "Running py tests for ${{ matrix.value }}"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: echo compose_path="/src/$(echo ${{ matrix.value }} | cut -d ":" -f1)/" >> "$GITHUB_ENV"
- run: cd "${{ env.compose_path }}" && echo compose_prj="$(basename "$PWD")_$(shuf -i 1000000-1000000000 -n 1)" >> "$GITHUB_ENV"
# We need to set custom compose project name to ensure "unique" container names in the host docker env
- name: run bash script with all logic for starting compose and running tests
run: |
bash /src/ci/execute_test_with_docker_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}" \
WE_ARE_IN_CI=1
- name: Stop compose if provided
# We could not put this into bash script, since job could be cancelled by user request
if: always() # yes! always
run: bash /src/ci/stop_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}"
run_tests_ext_public:
name: "🐍[pytest][ext_public]${{ matrix.value }}"
# using light runners for now, TBD: change when we have ext_public
runs-on: ubuntu-22.04
permissions:
packages: read
contents: read
needs: pytest_split
if: ${{ needs.pytest_split.outputs.split_ext_public != '[]' }}
container:
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
options: -v /var/run/docker.sock:/var/run/docker.sock
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
value: ${{fromJson(needs.pytest_split.outputs.split_ext_public)}}
steps:
- run: echo "Going to run tests for ${{ matrix.value }}"
- run: echo "Running py tests for ${{ matrix.value }}"
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: "ghcr.io"
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- run: echo compose_path="/src/$(echo ${{ matrix.value }} | cut -d ":" -f1)/" >> "$GITHUB_ENV"
- run: cd "${{ env.compose_path }}" && echo compose_prj="$(basename "$PWD")_$(shuf -i 1000000-1000000000 -n 1)" >> "$GITHUB_ENV"
# We need to set custom compose project name to ensure "unique" container names in the host docker env
- name: run bash script with all logic for starting compose and running tests
run: |
bash /src/ci/execute_test_with_docker_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}" \
WE_ARE_IN_CI=1
env:
GOOGLE_API_KEY: "${{ secrets.EXT_GOOGLE_API_KEY }}"
BITRIX_DATALENS_TOKEN: "${{ secrets.EXT_BITRIX_DATALENS_TOKEN }}"
METRIKA_OAUTH: "${{ secrets.EXT_METRIKA_OAUTH }}"
YA_DOCS_API_KEY: "${{ secrets.EXT_YA_DOCS_API_KEY }}"
- name: Stop compose if provided
# We could not put this into bash script, since job could be cancelled by user request
if: always() # yes! always
run: bash /src/ci/stop_compose.sh "${{ matrix.value }}" "${{ job.container.network }}" "${{ env.compose_prj }}"
mypy:
runs-on: ubuntu-22.04
needs: gh_build_image
container:
# until https://github.com/github/docs/issues/25520 is resolved, using vars
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
volumes:
- /var/run/docker.sock:/var/run/docker.sock
name: "🐲 mypy"
timeout-minutes: ${{ inputs.mypy_timeout_minutes && fromJSON(inputs.mypy_timeout_minutes ) || 20 }}
steps:
- uses: datalens-tech/cleanup-folder-action@v1
- name: Checkout code, just to get access to .github/execute_mypy...
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 1
- name: run mypy
run: |
. /venv/bin/activate
execute-mypy-multi /src --processes=5
env:
PYTHONUNBUFFERED: "1"
test-results:
name: Test results
runs-on: ubuntu-22.04
needs:
- check-skip-tests-label
- pytest_split
- run_tests_base
- run_tests_fat
- run_tests_no_compose
- run_tests_ext_public
if: always() && !cancelled()
steps:
- name: Collect Result
uses: ovsds/collect-needs-result-action@v1
with:
needs_json: ${{ toJson(needs) }}
codestyle_all:
runs-on: ubuntu-22.04
needs: gh_build_image
container:
# until https://github.com/github/docs/issues/25520 is resolved, using vars
image: "ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}/datalens_ci_with_code:${{ github.sha }}"
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: datalens-tech/cleanup-folder-action@v1
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 1
- run: |
task cq:check_dir -- .
task cq:check_dir_strict -- .
env:
VENV_PATH: /venv
- name: Find directories and check requirements
run: |
task cq:find_and_check_requirements
env:
VENV_PATH: /venv