Skip to content

Commit

Permalink
Add MIMA checks to ensure binary compatibility (#1214)
Browse files Browse the repository at this point in the history
Add MIMA checks to ensure binary compatibility across different
zio-kafka versions.

Also: use scala 3 syntax in sbt files.

Based on #1018 by @myazinn.

Mima is disabled in this PR because master is currently _not_ binary
compatible with the latest released version.

---------

Co-authored-by: Nikita Miazin <myazin.n@list.ru>
  • Loading branch information
erikvanoosten and myazinn authored Apr 14, 2024
1 parent 8baa167 commit 778d812
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
27 changes: 24 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import sbt.Def
import MimaSettings.mimaSettings

/**
* As of zio-kafka version 2.8.0 releases are binary compatible. This is checked with Mima.
*
* Keep this value set to the oldest minor release (with patch version set to "0") that is still binary compatible.
*
* Set this value to `None` when master is _not_ binary compatible with the latest minor release, the next release shall
* increase the minor version.
*/
lazy val binCompatVersionToCompare = None // Some("2.8.0")

lazy val kafkaVersion = "3.7.0"
lazy val embeddedKafkaVersion = "3.7.0" // Should be the same as kafkaVersion, except for the patch part
Expand Down Expand Up @@ -66,9 +77,10 @@ val excludeInferAny = { options: Seq[String] => options.filterNot(Set("-Xlint:in
lazy val root = project
.in(file("."))
.settings(
name := "zio-kafka",
publish / skip := true,
crossScalaVersions := Nil // https://www.scala-sbt.org/1.x/docs/Cross-Build.html#Cross+building+a+project+statefully
name := "zio-kafka",
publish / skip := true,
crossScalaVersions := Nil, // https://www.scala-sbt.org/1.x/docs/Cross-Build.html#Cross+building+a+project+statefully,
commands += lint
)
.aggregate(
zioKafka,
Expand Down Expand Up @@ -104,6 +116,7 @@ lazy val zioKafka =
.enablePlugins(BuildInfoPlugin)
.settings(stdSettings("zio-kafka"))
.settings(buildInfoSettings("zio.kafka"))
.settings(mimaSettings(binCompatVersionToCompare, failOnProblem = true))
.settings(enableZIO(enableStreaming = true))
.settings(
libraryDependencies ++= Seq(
Expand All @@ -126,6 +139,7 @@ lazy val zioKafkaTestkit =
.dependsOn(zioKafka)
.enablePlugins(BuildInfoPlugin)
.settings(stdSettings("zio-kafka-testkit"))
.settings(mimaSettings(binCompatVersionToCompare, failOnProblem = false))
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % zioVersion.value,
Expand Down Expand Up @@ -187,6 +201,7 @@ lazy val zioKafkaExample =

addCommandAlias("fmt", "all scalafmtSbt scalafmt test:scalafmt")
addCommandAlias("check", "all scalafmtSbtCheck scalafmtCheck test:scalafmtCheck")
addCommandAlias("mimaCheck", "+zioKafka/mimaReportBinaryIssues;+zioKafkaTestkit/mimaReportBinaryIssues")

lazy val docs = project
.in(file("zio-kafka-docs"))
Expand All @@ -206,3 +221,9 @@ lazy val docs = project
)
.enablePlugins(WebsitePlugin)
.dependsOn(zioKafka, zioKafkaTestkit)

// Extend 'lint' with mimaCheck
lazy val lint = {
val defaultLint = zio.sbt.Commands.ComposableCommand.lint
defaultLint.copy(commandStrings = defaultLint.commandStrings :+ "mimaCheck").toCommand
}
24 changes: 24 additions & 0 deletions project/MimaSettings.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import com.typesafe.tools.mima.core.*
import com.typesafe.tools.mima.core.ProblemFilters.*
import com.typesafe.tools.mima.plugin.MimaKeys.*
import sbt.*
import sbt.Keys.{ name, organization }

object MimaSettings {

def mimaSettings(binCompatVersionToCompare: Option[String], failOnProblem: Boolean): Seq[Def.Setting[?]] =
binCompatVersionToCompare match {
case None =>
Seq(mimaPreviousArtifacts := Set.empty)
case Some(binCompatVersion) =>
Seq(
mimaPreviousArtifacts := Set(organization.value %% name.value % binCompatVersion),
mimaBinaryIssueFilters ++= Seq(
exclude[Problem]("zio.kafka.consumer.internal.*")
),
mimaFailOnProblem := failOnProblem
)

}

}
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ addSbtPlugin("dev.zio" % "zio-sbt-ci" % zioSbtVersion)
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.0")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.1")
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.10.0")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3")

resolvers ++= Resolver.sonatypeOssRepos("public")

0 comments on commit 778d812

Please sign in to comment.