-
Notifications
You must be signed in to change notification settings - Fork 22
253 lines (243 loc) · 11.1 KB
/
pr.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
name: PR-check
on:
pull_request_target:
branches:
- 'main'
paths-ignore:
- 'ydb/docs/**'
- '.github/**'
- 'example/**'
- 'doc/**'
- '**.md'
types:
- 'opened'
- 'synchronize'
- 'reopened'
- 'labeled'
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
check-running-allowed:
runs-on: ubuntu-latest
outputs:
result: ${{ steps.check-ownership-membership.outputs.result }}
steps:
- name: Check if running tests is allowed
id: check-ownership-membership
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
script: |
// How to interpret membership status code:
// https://docs.github.com/en/rest/orgs/members?apiVersion=2022-11-28#check-organization-membership-for-a-user
const userLogin = context.payload.pull_request.user.login;
const isOrgMember = async function () {
try {
const response = await github.rest.orgs.checkMembershipForUser({
org: context.payload.organization.login,
username: userLogin,
});
return response.status == 204;
} catch (error) {
if (error.status && error.status == 404) {
return false;
}
throw error;
}
}
if (context.payload.repository.owner.login == userLogin) {
console.log('User is repo owner')
return true;
}
if (await isOrgMember()) {
console.log('User is member')
return true;
}
const labels = context.payload.pull_request.labels;
const okToTestLabel = labels.find(
label => label.name == 'ok-to-test'
);
return okToTestLabel !== undefined;
- name: comment-if-waiting-on-ok
if: steps.check-ownership-membership.outputs.result == 'false' &&
github.event.action == 'opened'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: 'Hi! Thank you for contributing!\nThe tests on this PR will run after a maintainer adds an `ok-to-test` label to this PR manually. Thank you for your patience!'
});
- name: cleanup-labels
uses: actions/github-script@v7
with:
script: |
let labelsToRemove = ['ok-to-test', 'recheck'];
const prNumber = context.payload.pull_request.number;
const prLabels = new Set(context.payload.pull_request.labels.map(l => l.name));
for await (const label of labelsToRemove.filter(l => prLabels.has(l))) {
core.info(`remove label=${label} for pr=${prNumber}`);
try {
const result = await github.rest.issues.removeLabel({
...context.repo,
issue_number: prNumber,
name: label
});
} catch(error) {
// ignore the 404 error that arises
// when the label did not exist for the
// organization member
if (error.status && error.status != 404) {
throw error;
}
}
}
create-build-and-test-target-var:
needs:
- check-running-allowed
if: needs.check-running-allowed.outputs.result == 'true'
outputs:
build_target: ${{ steps.set-build-and-test-targets.outputs.build_target }}
test_target: ${{ steps.set-build-and-test-targets.outputs.test_target }}
runs-on: ubuntu-latest
steps:
- name: Set build and test targets
id: set-build-and-test-targets
shell: bash
run: |
# Initialize variables
build_target_components=""
test_target_components=""
true_count=0
false_count=0
# Function to add components
add_components() {
if [ "$1" = "true" ]; then
build_target_components="${build_target_components}$2,"
test_target_components="${test_target_components}$3,"
true_count=$((true_count + 1))
else
false_count=$((false_count + 1))
fi
}
# Add components based on conditions
add_components "$contains_blockstore" "cloud/blockstore/apps/" "cloud/blockstore/"
add_components "$contains_filestore" "cloud/filestore/apps/" "cloud/filestore/"
add_components "$contains_disk_manager" "cloud/disk_manager/" "cloud/disk_manager/"
add_components "$contains_tasks" "cloud/tasks/" "cloud/tasks/"
# Remove trailing commas
build_target_components=${build_target_components%,}
test_target_components=${test_target_components%,}
# Determine build_target and test_target based on conditions
if [ "$true_count" -eq 4 ] || [ "$false_count" -eq 4 ]; then
build_target="cloud/blockstore/apps/,cloud/filestore/apps/,cloud/disk_manager/,cloud/tasks/"
test_target="cloud/blockstore/,cloud/filestore/,cloud/disk_manager/,cloud/tasks/"
else
build_target=$build_target_components
test_target=$test_target_components
fi
# Output to GitHub environment file
echo "build_target=\"$build_target\"" >> $GITHUB_OUTPUT
echo "test_target=\"$test_target\"" >> $GITHUB_OUTPUT
env:
contains_blockstore: ${{ contains(github.event.pull_request.labels.*.name, 'blockstore') && 'true' || 'false' }}
contains_filestore: ${{ contains(github.event.pull_request.labels.*.name, 'filestore') && 'true' || 'false' }}
contains_disk_manager: ${{ contains(github.event.pull_request.labels.*.name, 'disk_manager') && 'true' || 'false' }}
contains_tasks: ${{ contains(github.event.pull_request.labels.*.name, 'tasks') && 'true' || 'false' }}
build_and_test:
needs:
- check-running-allowed
- create-build-and-test-target-var
if: needs.check-running-allowed.outputs.result == 'true'
name: Build and test
uses: ./.github/workflows/build_and_test_on_demand.yaml
with:
build_target: ${{ needs.create-build-and-test-target-var.outputs.build_target }}
test_target: ${{ needs.create-build-and-test-target-var.outputs.test_target }}
build_preset: "relwithdebinfo"
test_size: ${{ contains(github.event.pull_request.labels.*.name, 'large-tests') && 'small,medium,large' || 'small,medium' }}
test_type: "unittest,clang_tidy,gtest,py3test,py2test,pytest,flake8,black,py2_flake8,go_test,gofmt"
run_tests: true
cache_update_build: false
cache_update_tests: false
sleep_after_tests: ${{ contains(github.event.pull_request.labels.*.name, 'sleep') && '7200' || '1' }}
secrets: inherit
build_and_test_asan:
needs:
- check-running-allowed
- create-build-and-test-target-var
if: needs.check-running-allowed.outputs.result == 'true' && contains(github.event.pull_request.labels.*.name, 'asan')
name: Build and test (asan)
uses: ./.github/workflows/build_and_test_on_demand.yaml
with:
build_target: ${{ needs.create-build-and-test-target-var.outputs.build_target }}
test_target: ${{ needs.create-build-and-test-target-var.outputs.test_target }}
build_preset: release-asan
vm_name_suffix: "-asan"
test_size: ${{ contains(github.event.pull_request.labels.*.name, 'large-tests') && 'small,medium,large' || 'small,medium' }}
test_type: "unittest,clang_tidy,gtest,py3test,py2test,pytest,flake8,black,py2_flake8,gofmt"
run_tests: true
cache_update_build: false
cache_update_tests: false
sleep_after_tests: ${{ contains(github.event.pull_request.labels.*.name, 'sleep') && '7200' || '1' }}
secrets: inherit
build_and_test_tsan:
needs:
- check-running-allowed
- create-build-and-test-target-var
if: needs.check-running-allowed.outputs.result == 'true' && contains(github.event.pull_request.labels.*.name, 'tsan')
name: Build and test (tsan)
uses: ./.github/workflows/build_and_test_on_demand.yaml
with:
build_target: ${{ needs.create-build-and-test-target-var.outputs.build_target }}
test_target: ${{ needs.create-build-and-test-target-var.outputs.test_target }}
build_preset: release-tsan
vm_name_suffix: "-tsan"
test_size: ${{ contains(github.event.pull_request.labels.*.name, 'large-tests') && 'small,medium,large' || 'small,medium' }}
test_type: "unittest,clang_tidy,gtest,py3test,py2test,pytest,flake8,black,py2_flake8,gofmt"
run_tests: true
cache_update_build: false
cache_update_tests: false
sleep_after_tests: ${{ contains(github.event.pull_request.labels.*.name, 'sleep') && '7200' || '1' }}
secrets: inherit
build_and_test_msan:
needs:
- check-running-allowed
- create-build-and-test-target-var
if: needs.check-running-allowed.outputs.result == 'true' && contains(github.event.pull_request.labels.*.name, 'msan')
name: Build and test (msan)
uses: ./.github/workflows/build_and_test_on_demand.yaml
with:
build_target: ${{ needs.create-build-and-test-target-var.outputs.build_target }}
test_target: ${{ needs.create-build-and-test-target-var.outputs.test_target }}
build_preset: release-msan
vm_name_suffix: "-msan"
test_size: ${{ contains(github.event.pull_request.labels.*.name, 'large-tests') && 'small,medium,large' || 'small,medium' }}
test_type: "unittest,clang_tidy,gtest,py3test,py2test,pytest,flake8,black,py2_flake8,gofmt"
run_tests: true
cache_update_build: false
cache_update_tests: false
sleep_after_tests: ${{ contains(github.event.pull_request.labels.*.name, 'sleep') && '7200' || '1' }}
secrets: inherit
build_and_test_ubsan:
needs:
- check-running-allowed
- create-build-and-test-target-var
if: needs.check-running-allowed.outputs.result == 'true' && contains(github.event.pull_request.labels.*.name, 'ubsan')
name: Build and test (ubsan)
uses: ./.github/workflows/build_and_test_on_demand.yaml
with:
build_target: ${{ needs.create-build-and-test-target-var.outputs.build_target }}
test_target: ${{ needs.create-build-and-test-target-var.outputs.test_target }}
build_preset: release-ubsan
vm_name_suffix: "-ubsan"
test_size: ${{ contains(github.event.pull_request.labels.*.name, 'large-tests') && 'small,medium,large' || 'small,medium' }}
test_type: "unittest,clang_tidy,gtest,py3test,py2test,pytest,flake8,black,py2_flake8,gofmt"
run_tests: true
cache_update_build: false
cache_update_tests: false
sleep_after_tests: ${{ contains(github.event.pull_request.labels.*.name, 'sleep') && '7200' || '1' }}
secrets: inherit