From e5798c4d7452de963868573ad94c851739deacf2 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 | 28 +++++++++++++++++++++++++++- 3 files changed, 50 insertions(+), 3 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..9d5c3f91 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(