Skip to content

Commit

Permalink
Bug fixes in publishDistributionBuildResults and `publishIntegTestR…
Browse files Browse the repository at this point in the history
…esults` (#462)

Signed-off-by: Prudhvi Godithi <[email protected]>
  • Loading branch information
prudhvigodithi committed Jul 24, 2024
1 parent cd984fa commit 0b44ea2
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 12 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jacocoTestReport {
}
}

String version = '6.7.0'
String version = '6.7.1'

task updateVersion {
doLast {
Expand Down
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
20 changes: 12 additions & 8 deletions vars/publishDistributionBuildResults.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,16 @@ 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")
def jsonData = generateAndAppendJson(indexName, component.name, component.repository, component.ref,
version, distributionBuildNumber, distributionBuildUrl,
buildStartTime, rc, rcNumber, componentCategory, "failed"
)
finalJsonDoc += "{\"index\": {\"_index\": \"${indexName}\"}}\n${jsonData}\n"
} else if (passedComponents.contains(component.name)) {
println("Component ${component.name} passed")
def jsonData = generateAndAppendJson(indexName, component.name, component.repository, component.ref,
version, distributionBuildNumber, distributionBuildUrl,
buildStartTime, rc, rcNumber, componentCategory, "passed"
Expand Down Expand Up @@ -156,10 +154,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 +162,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 0b44ea2

Please sign in to comment.