paddlenlp

Форк
0
/
gen_allure_report.py 
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

15
import os
16
import stat
17
import subprocess
18
import tarfile
19
import time
20
import zipfile
21

22
import wget
23

24

25
def gen_allure_report():
26
    """
27
    generate allure report
28
    """
29
    # install allure
30
    exit_code, output = subprocess.getstatusoutput("allure --version")
31
    if exit_code == 0:
32
        print("allure version is:{}".format(output))
33
        allure_bin = "allure"
34
    else:
35
        if os.path.exists("allure-2.19.0.zip") is False:
36
            bin_src = "https://xly-devops.bj.bcebos.com/tools/allure-2.19.0.zip"
37
            bin_file = wget.download(bin_src)
38
            zip_file = zipfile.ZipFile(bin_file, "a")
39
            zip_file.extractall()
40
        allure_bin_f = "%s/allure-2.19.0/bin/allure" % (os.getcwd())
41
        st = os.stat(allure_bin_f)
42
        os.chmod(allure_bin_f, st.st_mode | stat.S_IEXEC)
43
        allure_bin = "%s/allure-2.19.0/bin/allure" % (os.getcwd())
44
        exit_code, output = subprocess.getstatusoutput("java -version")
45
        if exit_code == 0:
46
            print("java version is:{}".format(output))
47
        else:  # install java
48
            if os.path.exists("java_linux.tar.gz") is False:
49
                java_src = "https://paddle-qa.bj.bcebos.com/java/java_linux.tar.gz"
50
                wget.download(java_src)
51
                tf = tarfile.open("java_linux.tar.gz")
52
                tf.extractall(os.getcwd())
53
            os.environ["JAVA_HOME"] = os.path.join(os.getcwd(), "jdk1.8.0_351")
54
            os.environ["JRE_HOME"] = os.path.join(os.getenv("JAVA_HOME"), "jre")
55
            os.environ["CLASSPATH"] = os.path.join(os.getenv("JAVA_HOME"), "lib")
56
            os.environ["PATH"] += os.pathsep + os.path.join(os.getenv("JAVA_HOME"), "bin")
57
            exit_code, output = subprocess.getstatusoutput("java -version")
58
            print("java version is:{}".format(output))
59
    exit_code, output = subprocess.getstatusoutput("%s --version" % allure_bin)
60
    if exit_code == 0:
61
        print("allure version is:{}".format(output))
62
        cmd = "%s generate result -o report" % allure_bin
63
        ret = os.system(cmd)
64
        if ret:
65
            print("allure generate report failed")
66
        else:
67
            print("allure generate report sucess")
68
        os.environ["REPORT_SERVER_USERNAME"] = os.getenv("REPORT_SERVER_USERNAME")
69
        os.environ["REPORT_SERVER_PASSWORD"] = os.getenv("REPORT_SERVER_PASSWORD")
70
        os.environ["REPORT_SERVER"] = os.getenv("REPORT_SERVER")
71
        job_build_id = os.getenv("AGILE_JOB_BUILD_ID")
72
        REPORT_SERVER = os.getenv("REPORT_SERVER")
73

74
        cmd = "curl -s {}/report/upload.sh | bash -s ./report {} report".format(REPORT_SERVER, job_build_id)
75

76
        if job_build_id:
77
            # upload allure report
78
            cmd = "curl -s {}/report/upload.sh | bash -s ./report {} report".format(REPORT_SERVER, job_build_id)
79
            print("upload cmd is {}".format(cmd))
80
            ret = os.system(cmd)
81
        else:
82
            print("非流水线任务,请补充9位数字流水线任务id")
83

84
        if os.path.exists("allure-2.19.0.zip"):
85
            time.sleep(1)
86
            try:
87
                os.remove("allure-2.19.0.zip")
88
            except:
89
                print("#### can not remove allure-2.19.0.zip")
90
        if os.path.exists("java_linux.tar.gz"):
91
            time.sleep(1)
92
            try:
93
                os.remove("java_linux.tar.gz")
94
            except:
95
                print("#### can not remove java_linux.tar.gz")
96
        if os.path.exists("bos_new.tar.gz"):
97
            time.sleep(1)
98
            try:
99
                os.remove("bos_new.tar.gz")
100
            except:
101
                print("#### can not remove bos_new.tar.gz")
102
        return ret
103
    else:
104
        print("allure is not config correctly:{}, please config allure manually!".format(output))
105
        return 1
106

107

108
if __name__ == "__main__":
109
    gen_allure_report()
110

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.