-
Notifications
You must be signed in to change notification settings - Fork 22
124 lines (118 loc) · 4.29 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
name: PR-check
on:
pull_request_target:
branches:
- 'main'
- 'stable-*'
paths-ignore:
- 'ydb/docs/**'
- '.github/**'
- 'example/**'
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@v6
with:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
script: |
// This is used primarily in forks. Repository owner
// should be allowed to run anything.
const whiteListedUsers = [
'qkrorlqr', 'budevg', 'jkuradobery', 'debnatkh', 'librarian',
'sharpeye', 'SvartMetal', '0x2493', 'sanek325', 'asorotsky',
'dvrazumov', 'WilyTiger',
'EvgeniyKozev', 'BarkovBG', 'gy2411', 'leftmain', 'v131v',
'yegorskii', 'drbasic', 'umed', 'slipstak2', 'NewBediver'
]
const userLogin = context.payload.pull_request.user.login;
if (whiteListedUsers.includes(userLogin)) {
console.log('User is whitelisted')
return true
}
// 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 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@v6
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-test-label
uses: actions/github-script@v6
with:
script: |
const { owner, repo } = context.repo;
const prNumber = context.payload.pull_request.number;
const labelToRemove = 'ok-to-test';
try {
const result = await github.rest.issues.removeLabel({
owner,
repo,
issue_number: prNumber,
name: labelToRemove
});
} catch(e) {
// ignore the 404 error that arises
// when the label did not exist for the
// organization member
console.log(e);
}
build_and_test:
needs:
- check-running-allowed
if: needs.check-running-allowed.outputs.result == 'true'
name: Build and test
uses: ./.github/workflows/build_and_test_on_demand.yaml
with:
build_preset: "relwithdebinfo"
test_size: "small,medium"
test_type: "unittest,py3test,py2test,pytest"
run_tests: true
update_bazel_cache: false
secrets: inherit