From 8a1e5853cf4cfeee36bd2ad1e243b1df4b221c79 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 7 May 2026 19:07:26 +0000 Subject: [PATCH] Fix Detect Breaking Changes version selection logic for previous released version (#21529) * Fix Detect Breaking Changes version selection logic for previous released version Signed-off-by: Craig Perkins Signed-off-by: Craig Perkins (cherry picked from commit 90be262691242226834483dc36670bf2f7be9ff7) Signed-off-by: github-actions[bot] --- server/build.gradle | 58 +++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/server/build.gradle b/server/build.gradle index 32ae6a14813e5..db4161b029885 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -178,18 +178,21 @@ tasks.named('forbiddenApisInternalClusterTest').configure { forbidSleep() } // Set to current version by default def japicmpCompareTarget = System.getProperty("japicmp.compare.version") -if (japicmpCompareTarget == null) { /* use latest released version */ - // Read the list from maven central. - // Fetch the metadata and parse the xml into Version instances, pick the latest one +if (japicmpCompareTarget == null) { + // Fetch released versions from maven central, pick the latest on the same major line before current. + def currentVersion = org.opensearch.gradle.Version.fromString(org.opensearch.gradle.VersionProperties.getOpenSearch()) japicmpCompareTarget = new URL('https://repo1.maven.org/maven2/org/opensearch/opensearch/maven-metadata.xml').openStream().withStream { s -> - new XmlParser().parse(s) - .versioning.versions.version - .collect { it.text() }.findAll { it ==~ /\d+\.\d+\.\d+/ } - .collect { org.opensearch.gradle.Version.fromString(it) } - .toSorted() - .last() - .toString() - } + new XmlParser().parse(s).versioning.versions.version + .collect { it.text() } + .findAll { it ==~ /\d+\.\d+\.\d+/ } + .collect { org.opensearch.gradle.Version.fromString(it) } + .findAll { it.getMajor() == currentVersion.getMajor() && it.before(currentVersion) } + .toSorted() + .with { it.empty ? null : it.last().toString() } + } + if (japicmpCompareTarget == null) { + logger.lifecycle("No prior released version found on the same major line. Skipping japicmp.") + } } def generateModulesList = tasks.register("generateModulesList") { @@ -496,22 +499,25 @@ tasks.named("sourcesJar").configure { } } -/** Compares the current build against a laltest released version or the version supplied through 'japicmp.compare.version' system property */ +/** Compares the current build against a latest released version or the version supplied through 'japicmp.compare.version' system property */ tasks.register("japicmp", me.champeau.gradle.japicmp.JapicmpTask) { - logger.info("Comparing public APIs from ${version} to ${japicmpCompareTarget}") - // See please https://github.com/siom79/japicmp/issues/201 - compatibilityChangeExcludes = [ "METHOD_ABSTRACT_NOW_DEFAULT", "METHOD_ADDED_TO_INTERFACE" ] - oldClasspath.from(files("${buildDir}/japicmp-target/opensearch-${japicmpCompareTarget}.jar")) - newClasspath.from(tasks.named('jar')) - onlyModified = true - failOnModification = true - ignoreMissingClasses = true - failOnSourceIncompatibility = true - annotationIncludes = ['@org.opensearch.common.annotation.PublicApi', '@org.opensearch.common.annotation.DeprecatedApi'] - annotationExcludes = ['@org.opensearch.common.annotation.InternalApi', '@org.opensearch.common.annotation.ExperimentalApi'] - txtOutputFile = layout.buildDirectory.file("reports/java-compatibility/report.txt") - htmlOutputFile = layout.buildDirectory.file("reports/java-compatibility/report.html") - dependsOn downloadJapicmpCompareTarget + enabled = japicmpCompareTarget != null + if (japicmpCompareTarget != null) { + logger.lifecycle("Comparing public APIs from ${version} to ${japicmpCompareTarget}") + // See please https://github.com/siom79/japicmp/issues/201 + compatibilityChangeExcludes = [ "METHOD_ABSTRACT_NOW_DEFAULT", "METHOD_ADDED_TO_INTERFACE" ] + oldClasspath.from(files("${buildDir}/japicmp-target/opensearch-${japicmpCompareTarget}.jar")) + newClasspath.from(tasks.named('jar')) + onlyModified = true + failOnModification = true + ignoreMissingClasses = true + failOnSourceIncompatibility = true + annotationIncludes = ['@org.opensearch.common.annotation.PublicApi', '@org.opensearch.common.annotation.DeprecatedApi'] + annotationExcludes = ['@org.opensearch.common.annotation.InternalApi', '@org.opensearch.common.annotation.ExperimentalApi'] + txtOutputFile = layout.buildDirectory.file("reports/java-compatibility/report.txt") + htmlOutputFile = layout.buildDirectory.file("reports/java-compatibility/report.html") + dependsOn downloadJapicmpCompareTarget + } } /** If the Java API Comparison task failed, print a hint if the change should be merged from its target branch */