From e7dc3e0d551c5b6e20ef13069ab7db6ff1753a2f Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Tue, 1 Aug 2023 20:19:34 +0000 Subject: [PATCH] Detect breaking changes Adds a gradle task and github action to check for breaking changes made to the APIs in server by running comparison against most resent snapshot build on sonotype maven repository. Uses japicmp to perform the comparison against the jar files, learn more https://siom79.github.io/japicmp/ - Related #8982 Signed-off-by: Peter Nied --- .github/workflows/detect-breaking-change.yml | 20 +++++++++++ server/build.gradle | 36 ++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .github/workflows/detect-breaking-change.yml diff --git a/.github/workflows/detect-breaking-change.yml b/.github/workflows/detect-breaking-change.yml new file mode 100644 index 0000000000000..d4369dd8ff26e --- /dev/null +++ b/.github/workflows/detect-breaking-change.yml @@ -0,0 +1,20 @@ +name: "Detect Breaking Changes" +on: [push, pull_request] +jobs: + detect-breaking-change: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-java@v2 + with: + distribution: temurin # Temurin is a distribution of adoptium + java-version: 17 + + - uses: actions/checkout@v2 + + - uses: gradle/gradle-build-action@v2 + with: + arguments: japicmp + build-root-directory: server + + - if: failure() + run: cat server/build/reports/japi.txt \ No newline at end of file diff --git a/server/build.gradle b/server/build.gradle index 3fde1b745c546..3a458c2e22152 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -36,6 +36,7 @@ plugins { id('opensearch.publish') id('opensearch.internal-cluster-test') id('opensearch.optional-dependencies') + id('me.champeau.gradle.japicmp') version '0.4.2' } publishing { @@ -408,3 +409,38 @@ tasks.named("sourcesJar").configure { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } } + +/** Compares the current build against a snapshot build */ +tasks.register("japicmp", me.champeau.gradle.japicmp.JapicmpTask) { + oldClasspath.from(files("${buildDir}/snapshot/opensearch-${version}.jar")) + newClasspath.from(tasks.named('jar')) + onlyModified = true + failOnModification = true + ignoreMissingClasses = true + txtOutputFile = layout.buildDirectory.file("reports/japi.txt") + dependsOn downloadSnapshot +} + +/** Downloads latest snapshot from maven repository */ +tasks.register("downloadSnapshot", Copy) { + def mavenSnapshotRepoUrl = "https://aws.oss.sonatype.org/content/repositories/snapshots/" + def groupId = "org.opensearch" + def artifactId = "opensearch" + + repositories { + maven { + url mavenSnapshotRepoUrl + } + } + + configurations { + snapshotArtifact + } + + dependencies { + snapshotArtifact("${groupId}:${artifactId}:${version}:") + } + + from configurations.snapshotArtifact + into "$buildDir/snapshot" +} \ No newline at end of file