Skip to content

Commit

Permalink
Add Function To Check All Relevant MiMa Versions (#2265)
Browse files Browse the repository at this point in the history
* Add Function To Check All Relevant MiMa Versions

* Fix Incorrectly Assumed Patch Equivalence, Add Safety Nets

* Fix Returned List Rather than Set
  • Loading branch information
ChristopherDavenport authored and kailuowang committed May 30, 2018
1 parent d4bc349 commit f4722ac
Showing 1 changed file with 41 additions and 4 deletions.
45 changes: 41 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,48 @@ lazy val docSettings = Seq(
includeFilter in Jekyll := (includeFilter in makeSite).value
)

lazy val binaryCompatibleVersions = Set("1.0.0", "1.1.0")
def mimaSettings(moduleName: String) = {
import sbtrelease.Version

def semverBinCompatVersions(major: Int, minor: Int, patch: Int): Set[(Int, Int, Int)] = {
val majorVersions: List[Int] = List(major)
val minorVersions : List[Int] =
if (major >= 1) Range(0, minor).inclusive.toList
else List(minor)
def patchVersions(currentMinVersion: Int): List[Int] =
if (minor == 0 && patch == 0) List.empty[Int]
else if (currentMinVersion != minor) List(0)
else Range(0, patch - 1).inclusive.toList

val versions = for {
maj <- majorVersions
min <- minorVersions
pat <- patchVersions(min)
} yield (maj, min, pat)
versions.toSet
}

def mimaSettings(moduleName: String) = Seq(
mimaPreviousArtifacts := binaryCompatibleVersions.map(v => "org.typelevel" %% moduleName % v)
)
def mimaVersions(version: String): Set[String] = {
Version(version) match {
case Some(Version(major, Seq(minor, patch), _)) =>
semverBinCompatVersions(major.toInt, minor.toInt, patch.toInt)
.map{case (maj, min, pat) => s"${maj}.${min}.${pat}"}
case _ =>
Set.empty[String]
}
}
// Safety Net For Exclusions
lazy val excludedVersions: Set[String] = Set()

// Safety Net for Inclusions
lazy val extraVersions: Set[String] = Set()

Seq(
mimaPreviousArtifacts := (mimaVersions(version.value) ++ extraVersions)
.filterNot(excludedVersions.contains(_))
.map(v => "org.typelevel" %% moduleName % v)
)
}

lazy val docs = project
.enablePlugins(MicrositesPlugin)
Expand Down

0 comments on commit f4722ac

Please sign in to comment.