From 359cf5fb96b400e20eabe969c46f33e607b2da05 Mon Sep 17 00:00:00 2001 From: Xue Li Date: Thu, 12 Sep 2024 11:50:30 +0800 Subject: [PATCH] OCM-11096 | ci: Fix the result reporting issue --- tests/prow_ci.sh | 4 +++- .../utils/exec/reportportal/report_portal.go | 24 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/tests/prow_ci.sh b/tests/prow_ci.sh index 2bbee9583e..19a7fe67ee 100644 --- a/tests/prow_ci.sh +++ b/tests/prow_ci.sh @@ -221,12 +221,14 @@ upload_junit_result () { exit 1 fi filePath=$1 + fileParantPath=$(dirname $filePath) uploadDir=$2 archiveDir=$3 filename=$(echo "${filePath%.*}" | awk -F "/" '{print $NF}') + fullFileName=$(basename $filePath) tarPath=${uploadDir}/${filename}.tar.gz echo "[CI] going to zip the junit file $filePath to $tarPath" - tar -zcvf $tarPath $filePath + tar -C $fileParantPath -zcvf $tarPath $fullFileName echo "[CI] archiving the the testing result" # copy the junit.tar.gz to ARTIFACT_DIR cp $tarPath ${archiveDir} diff --git a/tests/utils/exec/reportportal/report_portal.go b/tests/utils/exec/reportportal/report_portal.go index 3af906d5a4..e9481b8ed8 100644 --- a/tests/utils/exec/reportportal/report_portal.go +++ b/tests/utils/exec/reportportal/report_portal.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "path" + "path/filepath" "regexp" "strings" @@ -133,7 +134,7 @@ func GenerateReportXMLFile() (int, int, map[string][]Testcase, map[string][]Test passedNum := 0 issuedNum := 0 - xmlFileList := ListFiles(config.Test.ArtifactDir, ".xml") + xmlFileList := ListFiles(config.Test.OutputDir, ".xml") for _, xmlFile := range xmlFileList { xmlFilename := path.Base(xmlFile) xmlFilePrefix := strings.TrimSuffix(xmlFilename, ".xml") @@ -183,21 +184,20 @@ func GenerateReportXMLFile() (int, int, map[string][]Testcase, map[string][]Test return passedNum, issuedNum, issuedTCList, successedTCList } -func ListFiles(dir string, subfix string) []string { +func ListFiles(dir string, suffix string) []string { var Files []string - fs, err := os.ReadDir(dir) - if err != nil { - panic(fmt.Sprintf("Failed to open the directory %s: %v\n", dir, err)) + if _, err := os.Stat(dir); err != nil { + panic(fmt.Sprintf("provided dir %s not exist", dir)) } - for _, f := range fs { - if path.Ext(f.Name()) != subfix { - continue + err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + if strings.HasSuffix(info.Name(), suffix) { + Files = append(Files, path) } - - filename := path.Join(dir, f.Name()) - Files = append(Files, filename) + return nil + }) + if err != nil { + panic(fmt.Sprintf("Failed to open the directory %s: %v\n", dir, err)) } - return Files }