Skip to content

Commit acc5c0a

Browse files
authored
add ci for custom op approve (PaddlePaddle#3079)
1 parent d89b6dd commit acc5c0a

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

scripts/check_approval.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
if [ -z ${BRANCH} ]; then
16+
BRANCH="develop"
17+
fi
18+
19+
FD_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../" && pwd )"
20+
21+
approval_line=`curl -H "Authorization: token ${GITHUB_TOKEN}" https://api.github.com/repos/PaddlePaddle/Paddle/pulls/${PR_ID}/reviews?per_page=10000`
22+
failed_num=0
23+
echo_list=()
24+
25+
26+
function check_approval(){
27+
person_num=`echo $@|awk '{for (i=2;i<=NF;i++)print $i}'`
28+
APPROVALS=`echo ${approval_line}|python ${PADDLE_ROOT}/tools/check_pr_approval.py $1 $person_num`
29+
if [[ "${APPROVALS}" == "FALSE" && "${echo_line}" != "" ]]; then
30+
add_failed "${failed_num}. ${echo_line}"
31+
fi
32+
}
33+
34+
35+
function add_failed(){
36+
failed_num=`expr $failed_num + 1`
37+
echo_list="${echo_list[@]}$1"
38+
}
39+
40+
41+
HAS_CUSTOM_REGISTRER=`git diff -U0 upstream/$BRANCH | grep '^\+' | grep -zoE "PD_BUILD_(STATIC_)?OP" || true`
42+
if [ ${HAS_CUSTOM_REGISTRER} ] && [ "${PR_ID}" != "" ]; then
43+
echo_line="You must have one FastDeploy RD (qingqing01(dangqingqing), Jiang-Jia-Jun(jiangjiajun), heavengate(zhenkaipeng)) one QA(DDDivano(zhengtianyu)) one PaddlePaddle RD (XiaoguangHu01(huxiaoguang), jeff41404(gaoxiang), phlrain(liuhongyu)) approval for adding custom op.\n"
44+
check_approval 1 qingqing01, Jiang-Jia-Jun, heavengate
45+
check_approval 1 XiaoguangHu01 zhiqiu Xreki zhangbo9674 zyfncg phlrain
46+
check_approval 1 XiaoguangHu01, jeff41404, phlrain
47+
fi
48+
49+
50+
if [ -n "${echo_list}" ];then
51+
echo "****************"
52+
echo -e "${echo_list[@]}"
53+
echo "There are ${failed_num} approved errors."
54+
echo "****************"
55+
fi
56+
57+
if [ -n "${echo_list}" ]; then
58+
exit 6
59+
fi

scripts/check_pr_approval.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import json
16+
import sys
17+
18+
19+
def check_approval(count, required_reviewers):
20+
json_buff = ""
21+
for line in sys.stdin:
22+
json_buff = "".join([json_buff, line])
23+
json_resp = json.loads(json_buff)
24+
approves = 0
25+
approved_user_ids = []
26+
approved_user_logins = set()
27+
for review in json_resp:
28+
if review["state"] == "APPROVED":
29+
approves += 1
30+
approved_user_ids.append(review["user"]["id"])
31+
approved_user_logins.add(review["user"]["login"])
32+
33+
# convert to int
34+
required_reviewers_int = set()
35+
required_reviewers_login = set()
36+
for rr in required_reviewers:
37+
if rr.isdigit():
38+
required_reviewers_int.add(int(rr))
39+
else:
40+
required_reviewers_login.add(rr)
41+
42+
if (
43+
len(set(approved_user_ids) & required_reviewers_int) + len(approved_user_logins & required_reviewers_login)
44+
>= count
45+
):
46+
print("TRUE")
47+
else:
48+
print("FALSE")
49+
50+
51+
if __name__ == "__main__":
52+
if len(sys.argv) > 1 and sys.argv[1].isdigit():
53+
check_approval(int(sys.argv[1]), sys.argv[2:])
54+
else:
55+
print("Usage: python check_pr_approval.py [count] [required reviewer id] ...")

0 commit comments

Comments
 (0)