paddlenlp
109 строк · 4.3 Кб
1# Copyright (c) 2023 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
15import os16import stat17import subprocess18import tarfile19import time20import zipfile21
22import wget23
24
25def gen_allure_report():26"""27generate allure report
28"""
29# install allure30exit_code, output = subprocess.getstatusoutput("allure --version")31if exit_code == 0:32print("allure version is:{}".format(output))33allure_bin = "allure"34else:35if os.path.exists("allure-2.19.0.zip") is False:36bin_src = "https://xly-devops.bj.bcebos.com/tools/allure-2.19.0.zip"37bin_file = wget.download(bin_src)38zip_file = zipfile.ZipFile(bin_file, "a")39zip_file.extractall()40allure_bin_f = "%s/allure-2.19.0/bin/allure" % (os.getcwd())41st = os.stat(allure_bin_f)42os.chmod(allure_bin_f, st.st_mode | stat.S_IEXEC)43allure_bin = "%s/allure-2.19.0/bin/allure" % (os.getcwd())44exit_code, output = subprocess.getstatusoutput("java -version")45if exit_code == 0:46print("java version is:{}".format(output))47else: # install java48if os.path.exists("java_linux.tar.gz") is False:49java_src = "https://paddle-qa.bj.bcebos.com/java/java_linux.tar.gz"50wget.download(java_src)51tf = tarfile.open("java_linux.tar.gz")52tf.extractall(os.getcwd())53os.environ["JAVA_HOME"] = os.path.join(os.getcwd(), "jdk1.8.0_351")54os.environ["JRE_HOME"] = os.path.join(os.getenv("JAVA_HOME"), "jre")55os.environ["CLASSPATH"] = os.path.join(os.getenv("JAVA_HOME"), "lib")56os.environ["PATH"] += os.pathsep + os.path.join(os.getenv("JAVA_HOME"), "bin")57exit_code, output = subprocess.getstatusoutput("java -version")58print("java version is:{}".format(output))59exit_code, output = subprocess.getstatusoutput("%s --version" % allure_bin)60if exit_code == 0:61print("allure version is:{}".format(output))62cmd = "%s generate result -o report" % allure_bin63ret = os.system(cmd)64if ret:65print("allure generate report failed")66else:67print("allure generate report sucess")68os.environ["REPORT_SERVER_USERNAME"] = os.getenv("REPORT_SERVER_USERNAME")69os.environ["REPORT_SERVER_PASSWORD"] = os.getenv("REPORT_SERVER_PASSWORD")70os.environ["REPORT_SERVER"] = os.getenv("REPORT_SERVER")71job_build_id = os.getenv("AGILE_JOB_BUILD_ID")72REPORT_SERVER = os.getenv("REPORT_SERVER")73
74cmd = "curl -s {}/report/upload.sh | bash -s ./report {} report".format(REPORT_SERVER, job_build_id)75
76if job_build_id:77# upload allure report78cmd = "curl -s {}/report/upload.sh | bash -s ./report {} report".format(REPORT_SERVER, job_build_id)79print("upload cmd is {}".format(cmd))80ret = os.system(cmd)81else:82print("非流水线任务,请补充9位数字流水线任务id")83
84if os.path.exists("allure-2.19.0.zip"):85time.sleep(1)86try:87os.remove("allure-2.19.0.zip")88except:89print("#### can not remove allure-2.19.0.zip")90if os.path.exists("java_linux.tar.gz"):91time.sleep(1)92try:93os.remove("java_linux.tar.gz")94except:95print("#### can not remove java_linux.tar.gz")96if os.path.exists("bos_new.tar.gz"):97time.sleep(1)98try:99os.remove("bos_new.tar.gz")100except:101print("#### can not remove bos_new.tar.gz")102return ret103else:104print("allure is not config correctly:{}, please config allure manually!".format(output))105return 1106
107
108if __name__ == "__main__":109gen_allure_report()110