• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
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
16import { executeCommand } from "src/util";
17import { CONFIG_PATH, COMPILE_SH_PATH, TEST_TOOL_PATH, PROJECT_PATH } from 'config.dev';
18import { editLinuxContains } from "./editLinuxContains";
19import { commitPRRequest } from '../../util/index';
20
21interface TestResultProps {
22    successNum?: string;
23    failNum?: string;
24    diedNum?: string;
25    specialNum?: string;
26    testNum?: string;
27    testSuccessNum?: string;
28    testFailNum?: string;
29    testErrorNum?: string
30};
31
32export async function buildListProject(PRId: number, projectPath: Array<string>) {
33    let resultArray: Array<string> = [];
34    let result: string = '';
35    await executeCommand('cd ~');
36    for (const item of projectPath) {
37        result = await executeCommand(`${COMPILE_SH_PATH} --p=${CONFIG_PATH} --compile_dir=${item}`);
38
39        if (result.includes('hap_build success')) {
40            resultArray.push(item + ' build success!\n');
41        } else {
42            resultArray.push(item + ' build fail!\n');
43        };
44
45        // 测试
46        editLinuxContains(item);
47        const testResult: string = await executeCommand(`python3 ${TEST_TOOL_PATH}`);
48        const textResultObj: TestResultProps = {} as TestResultProps;
49        ('successNum' + testResult.split('successNum')[1]).replace(/[\n\r]/g, '').split(' ').forEach(val => {
50            const [key, value] = val.split(':');
51            textResultObj[key] = value;
52        });
53        if (textResultObj.successNum == '1') {
54            resultArray.push(item + ' test success!\n');
55        } else {
56            resultArray.push(item + ' test fail!\n');
57        };
58        console.log(resultArray);
59    }
60
61    console.log(resultArray);
62    let comment = resultArray.join('');
63    commitPRRequest(PRId, comment);
64    return resultArray;
65}