From 4f0b26d7a7b84598167369bac4a863c49031737a Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 15 May 2017 15:32:52 +0200 Subject: [PATCH] Add released versions to binary compatiblity versions --- project/Mima.scala | 13 +++++++++++-- project/Release.scala | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/project/Mima.scala b/project/Mima.scala index 4e5249491..8bf084a89 100644 --- a/project/Mima.scala +++ b/project/Mima.scala @@ -6,12 +6,21 @@ import com.typesafe.tools.mima.plugin.MimaKeys._ object Mima { - def binaryCompatibilityVersion = "1.0.0-RC1" + // Important: the line with the "binary compatibility versions" comment below is matched during releases + def binaryCompatibilityVersions = Set( + "1.0.0-RC1", + "1.0.0-RC2", + "1.0.0-RC3", + "" // binary compatibility versions + ) lazy val previousArtifacts = Seq( mimaPreviousArtifacts := { - Set(organization.value %% moduleName.value % binaryCompatibilityVersion) + binaryCompatibilityVersions.collect { + case ver if ver.nonEmpty => + organization.value %% moduleName.value % ver + } } ) diff --git a/project/Release.scala b/project/Release.scala index beb6cd1d0..2c914b6b6 100644 --- a/project/Release.scala +++ b/project/Release.scala @@ -231,6 +231,42 @@ object Release { state } + val mimaVersionsPattern = s"(?m)^(\\s+)${Pattern.quote("\"\" // binary compatibility versions")}$$".r + + val updateMimaVersions = ReleaseStep { state => + + val vcs = state.vcs + + val (releaseVer, _) = state.get(ReleaseKeys.versions).getOrElse { + sys.error(s"${ReleaseKeys.versions.label} key not set") + } + + val baseDir = Project.extract(state).get(baseDirectory.in(ThisBuild)) + val mimaScalaFile = baseDir / "project" / "Mima.scala" + + val content = Source.fromFile(mimaScalaFile)(Codec.UTF8).mkString + + mimaVersionsPattern.findAllIn(content).toVector match { + case Seq() => sys.error(s"Found no matches in $mimaScalaFile") + case Seq(_) => + case _ => sys.error(s"Found too many matches in $mimaScalaFile") + } + + val newContent = mimaVersionsPattern.replaceAllIn( + content, + m => { + val indent = m.group(1) + indent + "\"" + releaseVer + "\",\n" + + indent + "\"\" // binary compatibility versions" + } + ) + + Files.write(mimaScalaFile.toPath, newContent.getBytes(StandardCharsets.UTF_8)) + vcs.add(mimaScalaFile.getAbsolutePath).!!(state.log) + + state + } + val commitUpdates = ReleaseStep( action = { state => @@ -312,11 +348,13 @@ object Release { releaseStepCommand("tut"), stageReadme, updatePluginsSbt, + updateMimaVersions, commitUpdates, reallyTagRelease, setNextVersion, commitNextVersion, ReleaseStep(_.reload), + releaseStepCommand("mimaReportBinaryIssues"), pushChanges ), releasePublishArtifactsAction := PgpKeys.publishSigned.value