From 9367595bdd518ecb6d7f049cb822c6190f43c011 Mon Sep 17 00:00:00 2001 From: Andriy Plokhotnyuk Date: Mon, 13 Jan 2025 18:37:11 +0100 Subject: [PATCH] Add MiMa binary compatibility checks --- .github/workflows/ci.yml | 20 ++++++++++++++- build.sbt | 5 +++- project/BuildHelper.scala | 52 ++++++++++++++++++++++++++++++--------- 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d57b98bd..12e1f0b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -106,9 +106,27 @@ jobs: - name: Run tests run: sbt ++${{ matrix.scala }}! test${{ matrix.platform }} + mima_check: + runs-on: ubuntu-20.04 + timeout-minutes: 30 + steps: + - name: Checkout current branch + uses: actions/checkout@v4 + with: + fetch-depth: 300 + - name: Fetch tags + run: git fetch --depth=300 origin +refs/tags/*:refs/tags/* + - name: Setup Java (temurin@21) + uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 21 + cache: sbt + - run: sbt +mimaReportBinaryIssues + ci: runs-on: ubuntu-20.04 - needs: [lint, mdoc, benchmarks, test] + needs: [lint, mdoc, benchmarks, test, mima_check] steps: - name: Aggregate of lint, and all tests run: echo "ci passed" diff --git a/build.sbt b/build.sbt index 5b5bb35c..4f8d68d6 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,5 @@ import BuildHelper.* +import com.typesafe.tools.mima.plugin.MimaKeys.mimaPreviousArtifacts import explicitdeps.ExplicitDepsPlugin.autoImport.moduleFilterRemoveValue import sbtcrossproject.CrossPlugin.autoImport.crossProject @@ -60,7 +61,8 @@ val zioVersion = "2.1.14" lazy val zioJsonRoot = project .in(file(".")) .settings( - publish / skip := true, + publish / skip := true, + mimaPreviousArtifacts := Set(), unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library") ) .aggregate( @@ -400,6 +402,7 @@ lazy val docs = project zioJsonInteropScalaz7x.jvm, zioJsonGolden ), + mimaPreviousArtifacts := Set(), readmeAcknowledgement := """|- Uses [JsonTestSuite](https://github.com/nst/JSONTestSuite) to test parsing. (c) 2016 Nicolas Seriot) | diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index bd5f1b29..946d1f73 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -1,3 +1,7 @@ +import com.typesafe.tools.mima.core.Problem +import com.typesafe.tools.mima.core.ProblemFilters.exclude +import com.typesafe.tools.mima.plugin.MimaKeys.{ mimaBinaryIssueFilters, mimaFailOnProblem, mimaPreviousArtifacts } +import com.typesafe.tools.mima.plugin.MimaPlugin.autoImport.mimaCheckDirection import explicitdeps.ExplicitDepsPlugin.autoImport.* import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport.* import sbt.* @@ -5,6 +9,7 @@ import sbt.Keys.* import sbtbuildinfo.* import sbtbuildinfo.BuildInfoKeys.* import sbtcrossproject.CrossPlugin.autoImport.* +import sbtdynver.DynVerPlugin.autoImport.previousStableVersion import scala.scalanative.sbtplugin.ScalaNativePlugin.autoImport.* @@ -237,7 +242,28 @@ object BuildHelper { Test / parallelExecution := true, incOptions ~= (_.withLogRecompileOnMacro(false)), autoAPIMappings := true, - unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library") + unusedCompileDependenciesFilter -= moduleFilter("org.scala-js", "scalajs-library"), + mimaPreviousArtifacts := previousStableVersion.value.map(organization.value %% name.value % _).toSet, + mimaCheckDirection := { + def isPatch: Boolean = { + val Array(newMajor, newMinor, _) = version.value.split('.') + val Array(oldMajor, oldMinor, _) = previousStableVersion.value.getOrElse(version.value).split('.') + newMajor == oldMajor && newMinor == oldMinor + } + + if (isPatch) "both" + else "backward" + }, + mimaBinaryIssueFilters ++= Seq( + exclude[Problem]("zio.json.macros#package."), + exclude[Problem]("zio.JsonPackagePlatformSpecific.*"), + exclude[Problem]("zio.json.JsonDecoderPlatformSpecific.*"), + exclude[Problem]("zio.json.JsonEncoderPlatformSpecific.*"), + exclude[Problem]("zio.json.internal.*"), + exclude[Problem]("zio.json.package.*"), + exclude[Problem]("zio.json.yaml.internal.*") + ), + mimaFailOnProblem := true ) def macroExpansionSettings = Seq( @@ -258,14 +284,14 @@ object BuildHelper { def macroDefinitionSettings = Seq( scalacOptions += "-language:experimental.macros", - libraryDependencies ++= { - if (scalaVersion.value == ScalaDotty) Seq() - else + libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, _)) => Seq( "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided", "org.scala-lang" % "scala-compiler" % scalaVersion.value % "provided" ) - } + case _ => Seq() + }) ) val scalaJavaTimeVersion = "2.6.0" @@ -290,12 +316,16 @@ object BuildHelper { ) val scalaReflectTestSettings: List[Setting[_]] = List( - libraryDependencies ++= { - if (scalaVersion.value == ScalaDotty) - Seq("org.scala-lang" % "scala-reflect" % Scala213 % Test) - else - Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value % Test) - } + libraryDependencies ++= (CrossVersion.partialVersion(scalaVersion.value) match { + case Some((2, _)) => + Seq( + "org.scala-lang" % "scala-reflect" % scalaVersion.value % Test + ) + case _ => + Seq( + "org.scala-lang" % "scala-reflect" % Scala213 % Test + ) + }) ) def welcomeMessage = onLoadMessage := {