-
Notifications
You must be signed in to change notification settings - Fork 23
324 lines (318 loc) · 14.4 KB
/
build_and_test_on_demand.yaml
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
name: Build and test NBS on demand
on:
workflow_dispatch:
inputs:
build_target:
type: string
default: "cloud/blockstore/apps/,cloud/filestore/apps/,cloud/disk_manager/,cloud/tasks/"
description: "limit build to specific target"
test_target:
type: string
default: "cloud/blockstore/,cloud/filestore/,cloud/disk_manager/,cloud/tasks/"
description: "limit test to specific target"
build_preset:
type: choice
default: "relwithdebinfo"
description: "Build preset"
options:
- debug
- relwithdebinfo
- release-asan
- release-tsan
- release-msan
- release-ubsan
cache_update:
type: boolean
default: false
description: "Update build cache for build and cache"
test_size:
type: choice
default: "small"
description: "test size to run"
options:
- small
- small,medium
- small,medium,large
test_type:
type: choice
default: "unittest"
description: "type of tests to run"
options:
- unittest,clang_tidy,gtest
- py3test,py2test,pytest,flake8,black,py2_flake8
- go_test,gofmt
- unittest,clang_tidy,gtest,py3test,py2test,pytest,flake8,black,py2_flake8,go_test,gofmt
sleep_after_tests:
type: string
default: "0"
description: "Amount of seconds to sleep after tests"
run_build:
type: boolean
default: true
description: "run build"
run_tests:
type: boolean
default: true
description: "run tests"
nebius:
description: "Run on new nebius runners"
type: choice
default: "no"
options:
- "yes"
- "no"
workflow_call:
inputs:
build_target:
type: string
default: "cloud/blockstore/apps/,cloud/filestore/apps/,cloud/disk_manager/,cloud/tasks/"
description: "limit build to specific target"
test_target:
type: string
default: "cloud/blockstore/,cloud/filestore/,cloud/disk_manager/,cloud/tasks/"
description: "limit test to specific target"
build_preset:
type: string
default: "relwithdebinfo"
vm_name_suffix:
type: string
default: ""
test_size:
type: string
default: "small,medium,large"
test_type:
type: string
default: "unittest,clang_tidy,gtest,py3test,py2test,pytest,flake8,black,py2_flake8,go_test,gofmt"
run_build:
type: boolean
default: true
run_tests:
type: boolean
default: true
sleep_after_tests:
type: string
default: "0"
description: "Amount of seconds to sleep after tests"
cache_update_build:
type: boolean
default: false
description: "Update build cache in build stage"
cache_update_tests:
type: boolean
default: false
description: "Update build cache in test stage"
link_threads:
type: string
default: "24"
description: "--link-threads in ya make"
test_threads:
type: string
default: "32"
description: "--test-threads in ya test"
upload_ya_dir:
type: string
default: "no"
description: "Upload ya dir to s3"
clean_ya_dir:
type: string
default: "no"
description: "Clean ya dir from image before building"
use_network_cache:
type: string
default: "yes"
description: "Use network cache"
disk_type:
type: string
default: "network-ssd-nonreplicated"
description: "Disk type for VM"
allow_downgrade:
type: string
default: "no"
description: "Allow downgrade of VM"
nebius:
type: string
default: "no"
description: "Run on new nebius runners"
env:
nebius: ${{ vars.GLOBAL_RUN_ON_NEBIUS == 'yes' || ((github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'nebius')) || inputs.nebius == 'yes') }}
allow_downgrade: ${{ vars.GLOBAL_ALLOW_DOWNGRADE == 'yes' || ((github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'allow-downgrade')) || inputs.allow_downgrade == 'yes') }}
jobs:
provide-runner:
name: Start self-hosted runner (${{ inputs.build_preset }})
timeout-minutes: 60
if: always()
runs-on: ubuntu-latest
outputs:
label: ${{ steps.start-runner.outputs.label || steps.start-runner-nebius.outputs.label }}
instance-id: ${{ steps.start-runner.outputs.instance-id || steps.start-runner-nebius.outputs.instance-id }}
runner_ipv4: ${{ steps.start-runner.outputs.external-ipv4 || steps.start-runner-nebius.outputs.external-ipv4 }}
runner_local_ipv4: ${{ steps.start-runner.outputs.local-ipv4 || steps.start-runner-nebius.outputs.local-ipv4 }}
build_threads: ${{ steps.calculate-threads.outputs.build_threads || '60' }}
test_threads: ${{ steps.calculate-threads.outputs.test_threads || '32' }}
link_threads: ${{ steps.calculate-threads.outputs.link_threads || '24' }}
nebius: ${{ env.nebius == 'false' && 'no' || 'yes' }}
steps:
- name: checkout PR
uses: actions/checkout@v4
if: github.event.pull_request.head.sha != ''
with:
submodules: true
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ !contains(github.event.pull_request.labels.*.name, 'rebase') && 1 || 0 }}
- name: rebase PR
if: ${{ github.event.pull_request.head.sha != '' && contains(github.event.pull_request.labels.*.name, 'rebase') }}
shell: bash
run: |
git config user.email "[email protected]"
git config user.name "Rebase Robotovich"
git fetch origin ${{ github.event.pull_request.base.ref }}
git rebase origin/${{ github.event.pull_request.base.ref }}
- name: checkout
uses: actions/checkout@v4
if: github.event.pull_request.head.sha == ''
with:
submodules: true
- name: Start runner
id: start-runner
if: env.nebius == 'false' && always() || false
uses: ./.github/actions/runner_create
timeout-minutes: 60
with:
repo_owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
service_account_key: ${{ secrets.NEBIUS_SA_JSON_CREDENTIALS }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
vm_folder: bjeuq5o166dq4ukv3eec
vm_name: ${{ github.event.pull_request.number && format('pr-{0}{1}-{2}-{3}', github.event.pull_request.number, inputs.vm_name_suffix, github.run_id, github.run_attempt) || format('run-{0}-{1}', github.run_id, github.run_attempt) }}
vm_zone: eu-north1-c
vm_cpu: 60
vm_memory: 420
vm_disk_type: ${{ inputs.disk_type || 'network-ssd-nonreplicated' }}
vm_disk_size: 1023
vm_subnet: f8uh0ml4rhb45nde9p75
vm_image: ${{ vars.IMAGE_ID_2204 }}
vm_labels: ${{ github.event.pull_request.number && format('pr={0},run={1}-{2},repo={3},owner={4}', github.event.pull_request.number, github.run_id, github.run_attempt, github.event.repository.name, github.repository_owner) || format('run={0}-{1},repo={2},owner={3}', github.run_id, github.run_attempt, github.event.repository.name, github.repository_owner) }}
vm_user_passwd: ${{ secrets.VM_USER_PASSWD }}
- name: Start runner (nebius)
id: start-runner-nebius
if: env.nebius == 'true' && always() || false
uses: ./.github/actions/nebius_runner_create
timeout-minutes: 60
with:
org: ydb-platform
team: nbs
repo_owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
service_account_key: ${{ secrets.NEW_NEBIUS_SA_JSON_CREDENTIALS }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
vm_parent_id: ${{ vars.NEBIUS_PARENT_ID }}
vm_name: ${{ github.event.pull_request.number && format('pr-{0}{1}-{2}-{3}', github.event.pull_request.number, inputs.vm_name_suffix, github.run_id, github.run_attempt) || format('run-{0}-{1}', github.run_id, github.run_attempt) }}
vm_preset: ${{ vars.NEBIUS_VM_PRESET }}
vm_disk_type: ${{ inputs.disk_type || 'network-ssd-nonreplicated' }}
vm_disk_size: 1023
vm_subnet: ${{ vars.NEBIUS_SUBNET_ID }}
vm_image: ${{ vars.NEBIUS_IMAGE_ID_2204 }}
vm_labels: ${{ github.event.pull_request.number && format('pr={0},run={1}-{2},repo={3},owner={4}', github.event.pull_request.number, github.run_id, github.run_attempt, github.event.repository.name, github.repository_owner) || format('run={0}-{1},repo={2},owner={3}', github.run_id, github.run_attempt, github.event.repository.name, github.repository_owner) }}
vm_user_passwd: ${{ secrets.VM_USER_PASSWD }}
vm_allow_downgrade: ${{ env.allow_downgrade == 'true' && 'yes' || 'no' }}
- name: Calculate threads
id: calculate-threads
if: env.nebius == 'true' && always() || false
uses: ./.github/actions/nebius_threads_calculator
with:
vm_preset: ${{ steps.start-runner-nebius.outputs.vm-preset }}
tests_size: ${{ inputs.test_size }}
build-and-test:
name: Build and test NBS (${{ inputs.build_preset }}) [id=${{ needs.provide-runner.outputs.instance-id }} local_ip=${{ needs.provide-runner.outputs.runner_local_ipv4 }} ip=${{ needs.provide-runner.outputs.runner_ipv4 }}]
uses: ./.github/workflows/build_and_test_ya.yaml
needs:
- provide-runner
with:
runner_kind: self-hosted
runner_label: ${{ needs.provide-runner.outputs.label }}
runner_instance_id: ${{ needs.provide-runner.outputs.instance-id }}
runner_ipv4: ${{ needs.provide-runner.outputs.runner_ipv4 }}
build_target: ${{ inputs.build_target }}
test_target: ${{ inputs.test_target }}
build_preset: ${{ inputs.build_preset }}
run_build: ${{ inputs.run_build }}
run_tests: ${{ inputs.run_tests }}
test_size: ${{ inputs.test_size }}
test_type: ${{ inputs.test_type }}
build_threads: ${{ needs.provide-runner.outputs.build_threads || '60' }}
link_threads: ${{ needs.provide-runner.outputs.link_threads || '24' }}
test_threads: ${{ needs.provide-runner.outputs.test_threads || '12' }}
sleep_after_tests: ${{ inputs.sleep_after_tests }}
cache_update_build: ${{ fromJson(github.event_name == 'workflow_dispatch' && format('{0}', inputs.cache_update) || format('{0}', inputs.cache_update_build)) }}
cache_update_tests: ${{ fromJson(github.event_name == 'workflow_dispatch' && format('{0}', inputs.cache_update) || format('{0}', inputs.cache_update_tests)) }}
upload_ya_dir: ${{ github.event == 'workflow_dispatch' && 'no' || inputs.upload_ya_dir}}
clean_ya_dir: ${{ github.event == 'workflow_dispatch' && 'no' || inputs.clean_ya_dir }}
use_network_cache: ${{ github.event == 'workflow_dispatch' && 'yes'|| inputs.use_network_cache }}
nebius: ${{ needs.provide-runner.outputs.nebius }}
secrets: inherit
sleep-if-needed:
name: Sleep ${{ needs.build-and-test.outputs.sleep_after_tests || '0' }}s if build failed
if: ${{ !cancelled() }}
needs:
- provide-runner # required to get output from the start-runner job
- build-and-test # required to wait when the main job is done
runs-on: ubuntu-latest
steps:
- name: Sleep ${{ needs.build-and-test.outputs.sleep_after_tests || '0' }}s if build failed
shell: bash
if: ${{ needs.build-and-test.outputs.sleep_after_tests && needs.build-and-test.outputs.sleep_after_tests != '0' }}
# we need to use binary because builting doesn't produce process
# which we can kill to stop the vm before it's done
run: |
echo "sleeping ${{ needs.build-and-test.outputs.sleep_after_tests }}s"
/usr/bin/sleep ${{ needs.build-and-test.outputs.sleep_after_tests }}
release-runner:
name: Release self-hosted runner (${{ inputs.build_preset }}) [id=${{ needs.provide-runner.outputs.instance-id }} local_ip=${{ needs.provide-runner.outputs.runner_local_ipv4 }} ip=${{ needs.provide-runner.outputs.runner_ipv4 }}]
needs:
- provide-runner # required to get output from the start-runner job
- build-and-test # required to wait when the main job is done
- sleep-if-needed # required to wait until all debug is done
runs-on: ubuntu-latest
if: always()
steps:
- name: checkout PR
uses: actions/checkout@v4
if: github.event.pull_request.head.sha != ''
with:
submodules: true
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ !contains(github.event.pull_request.labels.*.name, 'rebase') && 1 || 0 }}
- name: rebase PR
if: ${{ github.event.pull_request.head.sha != '' && contains(github.event.pull_request.labels.*.name, 'rebase') }}
shell: bash
run: |
git config user.email "[email protected]"
git config user.name "Rebase Robotovich"
git fetch origin ${{ github.event.pull_request.base.ref }}
git rebase origin/${{ github.event.pull_request.base.ref }}
- name: checkout
uses: actions/checkout@v4
if: github.event.pull_request.head.sha == ''
with:
submodules: true
- name: Stop runner
uses: ./.github/actions/runner_remove
if: env.nebius == 'false' && always() || false
timeout-minutes: 60
with:
service_account_key: ${{ secrets.NEBIUS_SA_JSON_CREDENTIALS }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
repo_owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
vm_id: ${{ needs.provide-runner.outputs.instance-id }}
- name: Stop runner (nebius)
uses: ./.github/actions/nebius_runner_remove
if: env.nebius == 'true' && always() || false
timeout-minutes: 60
with:
service_account_key: ${{ secrets.NEW_NEBIUS_SA_JSON_CREDENTIALS }}
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
repo_owner: ${{ github.repository_owner }}
repo: ${{ github.event.repository.name }}
vm_parent_id: ${{ vars.NEBIUS_PARENT_ID }}
vm_id: ${{ needs.provide-runner.outputs.instance-id }}