Skip to content

Commit

Permalink
Publish Bug
Browse files Browse the repository at this point in the history
Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Jul 24, 2024
1 parent cd984fa commit d01a714
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 9 deletions.
39 changes: 39 additions & 0 deletions tests/jenkins/TestPublishDistributionBuildResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,43 @@ class TestPublishDistributionBuildResults extends BuildPipelineTest {
])
assert result == expectedJson
}

@Test
void testExtractComponentsForFailureMessages() {
List<String> failureMessages = [
"Error building componentA, caused by ...",
"Error building componentB due to ...",
"Error building componentA because ..."
]
List<String> expectedComponents = ["componentA", "componentB"]
def script = loadScript('vars/publishDistributionBuildResults.groovy')
List<String> result = script.extractComponents(failureMessages, /(?<=\bError building\s).*/, 0)
assert result == expectedComponents
}

@Test
void testExtractComponentsForPassMessages() {
List<String> passMessages = [
"Successfully built componentA",
"Successfully built componentB",
"Successfully built componentC"
]
List<String> expectedComponents = ["componentA", "componentB", "componentC"]
def script = loadScript('vars/publishDistributionBuildResults.groovy')
List<String> result = script.extractComponents(passMessages, /(?<=\bSuccessfully built\s).*/, 0)
assert result == expectedComponents
}

@Test
void testExtractComponentsWithDuplicates() {
List<String> messages = [
"Successfully built componentA",
"Successfully built componentA",
"Successfully built componentB"
]
List<String> expectedComponents = ["componentA", "componentB"]
def script = loadScript('vars/publishDistributionBuildResults.groovy')
List<String> result = script.extractComponents(messages, /(?<=\bSuccessfully built\s).*/, 0)
assert result == expectedComponents
}
}
42 changes: 42 additions & 0 deletions tests/jenkins/TestPublishIntegTestResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
18 changes: 12 additions & 6 deletions vars/publishDistributionBuildResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> failedComponents = extractComponents(failureMessages, /(?<=\bError building\s).*/, 0)
List<String> passedComponents = extractComponents(passMessages, /(?<=\bSuccessfully built\s).*/, 0)
inputManifest.components.each { component ->
if (failedComponents.contains(component.name)) {
println("Component ${component.name} failed")
Expand Down Expand Up @@ -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,
Expand All @@ -168,3 +164,13 @@ def generateAndAppendJson(indexName, component, componentRepo, componentRef, ver
)
return jsonData
}

def extractComponents(List<String> messages, String regex, int splitIndex) {
List<String> 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()
}
7 changes: 4 additions & 3 deletions vars/publishIntegTestResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @param args.architecture <required> - The architecture of the integration test build.
* @param args.distribution <required> - The distribution of the integration test build.
* @param args.testReportManifestYml <required> - The generated test report YAML file using test report workflow.
* @param args.jobName <required> - The integ test job name, used in `testReportManifestYmlUrl`.
*/

import groovy.json.JsonOutput
Expand All @@ -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
Expand All @@ -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}"
Expand Down

0 comments on commit d01a714

Please sign in to comment.