From ac14d108ca1f87a281eed907a585782e8e8aae03 Mon Sep 17 00:00:00 2001 From: silingtong123 <35439432+silingtong123@users.noreply.github.com> Date: Tue, 2 Jun 2020 19:42:45 +0800 Subject: [PATCH] add a CI rule: You must have Superjomn approval for change 20+ files or add than 1000+ lines of content (#3727) * test=develop, add a CI rule * test=develop, remove the debug messages --- lite/tools/check_api_approvals.sh | 43 ++++++++++++++++++++++++++ lite/tools/check_pr_approval.py | 51 +++++++++++++++++++++++++++++++ lite/tools/ci_build.sh | 9 ++++++ 3 files changed, 103 insertions(+) create mode 100644 lite/tools/check_api_approvals.sh create mode 100644 lite/tools/check_pr_approval.py diff --git a/lite/tools/check_api_approvals.sh b/lite/tools/check_api_approvals.sh new file mode 100644 index 0000000000..6100558d68 --- /dev/null +++ b/lite/tools/check_api_approvals.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +if [ -z ${BRANCH} ]; then + BRANCH="develop" +fi + +LITE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../.." && pwd )" + +approval_line=`curl -H "Authorization: token ${GITHUB_API_TOKEN}" https://api.github.com/repos/PaddlePaddle/Paddle-Lite/pulls/${GIT_PR_ID}/reviews?per_page=10000` +git_files=`git diff --numstat upstream/$BRANCH| wc -l` +git_count=`git diff --numstat upstream/$BRANCH| awk '{sum+=$1}END{print sum}'` +failed_num=0 +echo_list=() + +function add_failed(){ + failed_num=`expr $failed_num + 1` + echo_list="${echo_list[@]}$1" +} + +function check_approval(){ + person_num=`echo $@|awk '{for (i=2;i<=NF;i++)print $i}'` + APPROVALS=`echo ${approval_line}|python ${LITE_ROOT}/lite/tools/check_pr_approval.py $1 $person_num` + if [[ "${APPROVALS}" == "FALSE" && "${echo_line}" != "" ]]; then + add_failed "${failed_num}. ${echo_line}" + fi +} + + +if [[ $git_files -gt 19 || $git_count -gt 999 ]];then + echo_line="You must have Superjomn (Yunchunwei) approval for change 20+ files or add than 1000+ lines of content.\n" + check_approval 1 328693 +fi + +if [ -n "${echo_list}" ];then + echo "****************" + echo -e "${echo_list[@]}" + echo "There are ${failed_num} approved errors." + echo "****************" +fi + +if [ -n "${echo_list}" ]; then + exit 1 +fi diff --git a/lite/tools/check_pr_approval.py b/lite/tools/check_pr_approval.py new file mode 100644 index 0000000000..b05a422a86 --- /dev/null +++ b/lite/tools/check_pr_approval.py @@ -0,0 +1,51 @@ +# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from __future__ import print_function +import sys +import json + + +def check_approval(count, required_reviewers): + json_buff = "" + for line in sys.stdin: + json_buff = "".join([json_buff, line]) + json_resp = json.loads(json_buff) +# print(type(json_resp)) +# print(json_resp) + approves = 0 + approved_user_ids = [] + for review in json_resp: + if review["state"] == "APPROVED": + approves += 1 + approved_user_ids.append(review["user"]["id"]) + + # convert to int + required_reviewers_int = set() + for rr in required_reviewers: + required_reviewers_int.add(int(rr)) + + if len(set(approved_user_ids) & required_reviewers_int) >= count: + print("TRUE") + else: + print("FALSE") + + +if __name__ == "__main__": + if len(sys.argv) > 1 and sys.argv[1].isdigit(): + check_approval(int(sys.argv[1]), sys.argv[2:]) + else: + print( + "Usage: python check_pr_approval.py [count] [required reviewer id] ..." + ) diff --git a/lite/tools/ci_build.sh b/lite/tools/ci_build.sh index 94416f681a..29ed9100f9 100755 --- a/lite/tools/ci_build.sh +++ b/lite/tools/ci_build.sh @@ -5,6 +5,7 @@ set -ex TESTS_FILE="./lite_tests.txt" LIBS_FILE="./lite_libs.txt" CUDNN_ROOT="/usr/local/cudnn" +LITE_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}")/../../" && pwd )" readonly ADB_WORK_DIR="/data/local/tmp" readonly common_flags="-DWITH_LITE=ON -DLITE_WITH_LIGHT_WEIGHT_FRAMEWORK=OFF -DWITH_PYTHON=OFF -DWITH_TESTING=ON -DLITE_WITH_ARM=OFF" @@ -277,11 +278,19 @@ function test_server { done } +function assert_api_spec_approvals() { + /bin/bash ${LITE_ROOT}/lite/tools/check_api_approvals.sh + if [ "$?" != 0 ];then + exit 1 + fi +} + # Build the code and run lite server tests. This is executed in the CI system. function build_test_server { mkdir -p ./build cd ./build export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$PWD/third_party/install/mklml/lib" + assert_api_spec_approvals cmake_x86_for_CI build -- GitLab