From d01a71413fb499e1985332eb828723c1d0430298 Mon Sep 17 00:00:00 2001 From: Prudhvi Godithi Date: Wed, 24 Jul 2024 10:30:24 -0700 Subject: [PATCH] Publish Bug Signed-off-by: Prudhvi Godithi --- ...TestPublishDistributionBuildResults.groovy | 39 +++++++++++++++++ .../TestPublishIntegTestResults.groovy | 42 +++++++++++++++++++ vars/publishDistributionBuildResults.groovy | 18 +++++--- vars/publishIntegTestResults.groovy | 7 ++-- 4 files changed, 97 insertions(+), 9 deletions(-) diff --git a/tests/jenkins/TestPublishDistributionBuildResults.groovy b/tests/jenkins/TestPublishDistributionBuildResults.groovy index 0d99ade6..87f8c50f 100644 --- a/tests/jenkins/TestPublishDistributionBuildResults.groovy +++ b/tests/jenkins/TestPublishDistributionBuildResults.groovy @@ -209,4 +209,43 @@ class TestPublishDistributionBuildResults extends BuildPipelineTest { ]) assert result == expectedJson } + + @Test + void testExtractComponentsForFailureMessages() { + List failureMessages = [ + "Error building componentA, caused by ...", + "Error building componentB due to ...", + "Error building componentA because ..." + ] + List expectedComponents = ["componentA", "componentB"] + def script = loadScript('vars/publishDistributionBuildResults.groovy') + List result = script.extractComponents(failureMessages, /(?<=\bError building\s).*/, 0) + assert result == expectedComponents + } + + @Test + void testExtractComponentsForPassMessages() { + List passMessages = [ + "Successfully built componentA", + "Successfully built componentB", + "Successfully built componentC" + ] + List expectedComponents = ["componentA", "componentB", "componentC"] + def script = loadScript('vars/publishDistributionBuildResults.groovy') + List result = script.extractComponents(passMessages, /(?<=\bSuccessfully built\s).*/, 0) + assert result == expectedComponents + } + + @Test + void testExtractComponentsWithDuplicates() { + List messages = [ + "Successfully built componentA", + "Successfully built componentA", + "Successfully built componentB" + ] + List expectedComponents = ["componentA", "componentB"] + def script = loadScript('vars/publishDistributionBuildResults.groovy') + List result = script.extractComponents(messages, /(?<=\bSuccessfully built\s).*/, 0) + assert result == expectedComponents + } } diff --git a/tests/jenkins/TestPublishIntegTestResults.groovy b/tests/jenkins/TestPublishIntegTestResults.groovy index dff548b6..a21ac6df 100644 --- a/tests/jenkins/TestPublishIntegTestResults.groovy +++ b/tests/jenkins/TestPublishIntegTestResults.groovy @@ -208,6 +208,48 @@ class TestPublishIntegTestResults extends BuildPipelineTest { assert parsedResult == expectedJson } + @Test + void testCallWithMissingArgs() { + def script = loadScript('vars/publishIntegTestResults.groovy') + def args = [ + version: "1.0", + distributionBuildNumber: null, // Missing required argument + distributionBuildUrl: "http://example.com/distribution/456", + rc: "rc1", + rcNumber: "1", + platform: "linux", + architecture: "x64", + distribution: "tar", + testReportManifestYml: "path/to/testReportManifest.yml", + jobName: "test-job" + ] + + def result = script.call(args) + + assert result == null + } + + @Test + void testCallWithEmptyArgs() { + def script = loadScript('vars/publishIntegTestResults.groovy') + def args = [ + version: "1.0", + distributionBuildNumber: "", // Empty required argument + distributionBuildUrl: "http://example.com/distribution/456", + rc: "rc1", + rcNumber: "1", + platform: "linux", + architecture: "x64", + distribution: "tar", + testReportManifestYml: "path/to/testReportManifest.yml", + jobName: "test-job" + ] + + def result = script.call(args) + + assert result == null + } + def normalizeString(String str) { return str.replaceAll(/\s+/, " ").trim() } diff --git a/vars/publishDistributionBuildResults.groovy b/vars/publishDistributionBuildResults.groovy index ed601bbc..56727184 100644 --- a/vars/publishDistributionBuildResults.groovy +++ b/vars/publishDistributionBuildResults.groovy @@ -37,8 +37,8 @@ void call(Map args = [:]) { def inputManifest = readYaml(file: args.inputManifestPath) def version = inputManifest.build.version def finalJsonDoc = "" - def failedComponents = extractUniqueComponents(failureMessages, /(?<=\bError building\s)\S+/) - def passedComponents = extractUniqueComponents(passMessages, /(?<=\bSuccessfully built\s)\S+/) + List failedComponents = extractComponents(failureMessages, /(?<=\bError building\s).*/, 0) + List passedComponents = extractComponents(passMessages, /(?<=\bSuccessfully built\s).*/, 0) inputManifest.components.each { component -> if (failedComponents.contains(component.name)) { println("Component ${component.name} failed") @@ -156,10 +156,6 @@ def generateJson(component, componentRepo, componentRef, version, distributionBu return JsonOutput.toJson(json) } -def extractUniqueComponents(messages, regex) { - messages.collect { it.find(regex) }.unique() -} - def generateAndAppendJson(indexName, component, componentRepo, componentRef, version, distributionBuildNumber, distributionBuildUrl, buildStartTime, rc, rcNumber, componentCategory, status) { def jsonData = generateJson( component, componentRepo, componentRef, version, @@ -168,3 +164,13 @@ def generateAndAppendJson(indexName, component, componentRepo, componentRef, ver ) return jsonData } + +def extractComponents(List messages, String regex, int splitIndex) { + List components = [] + for (message in messages) { + java.util.regex.Matcher match = (message =~ regex) + String matched = match[0] + components.add(matched.split(' ')[0].split(',')[splitIndex].trim()) + } + return components.unique() +} diff --git a/vars/publishIntegTestResults.groovy b/vars/publishIntegTestResults.groovy index a8efb3f3..290f95f8 100644 --- a/vars/publishIntegTestResults.groovy +++ b/vars/publishIntegTestResults.groovy @@ -19,6 +19,7 @@ * @param args.architecture - The architecture of the integration test build. * @param args.distribution - The distribution of the integration test build. * @param args.testReportManifestYml - The generated test report YAML file using test report workflow. + * @param args.jobName - The integ test job name, used in `testReportManifestYmlUrl`. */ import groovy.json.JsonOutput @@ -34,11 +35,10 @@ void call(Map args = [:]) { } if (isNullOrEmpty(args.version) || isNullOrEmpty(args.distributionBuildNumber) || isNullOrEmpty(args.distributionBuildUrl) || isNullOrEmpty(args.rcNumber) || isNullOrEmpty(args.rc) || isNullOrEmpty(args.platform) || - isNullOrEmpty(args.architecture) || isNullOrEmpty(args.distribution) || isNullOrEmpty(args.testReportManifestYml)) { + isNullOrEmpty(args.architecture) || isNullOrEmpty(args.distribution) || isNullOrEmpty(args.testReportManifestYml) || isNullOrEmpty(args.jobName)) { return null } - def version = args.version.toString() def integTestBuildNumber = currentBuild.number def integTestBuildUrl = env.RUN_DISPLAY_URL @@ -53,7 +53,8 @@ void call(Map args = [:]) { def architecture = args.architecture def distribution = args.distribution def testReportManifestYml = args.testReportManifestYml - def testReportManifestYmlUrl = "https://ci.opensearch.org/ci/dbc/integ-test/${version}/${distributionBuildNumber}/${platform}/${architecture}/${distribution}/test-results/${integTestBuildNumber}/integ-test/test-report.yml" + def jobName = args.jobName + def testReportManifestYmlUrl = "https://ci.opensearch.org/ci/dbc/${jobName}/${version}/${distributionBuildNumber}/${platform}/${architecture}/${distribution}/test-results/${integTestBuildNumber}/integ-test/test-report.yml" def manifestFile = readFile testReportManifestYml def manifest = readYaml text: manifestFile def indexName = "opensearch-integration-test-results-${formattedDate}"