Skip to content

Commit

Permalink
Simplify release process with scalacenter/sbt-version-policy#186
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrf committed Nov 29, 2023
1 parent 1564b89 commit d114399
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 47 deletions.
67 changes: 21 additions & 46 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ReleaseTransformations.*
import sbtversionpolicy.SbtVersionPolicyPlugin.aggregatedAssessedCompatibilityWithLatestRelease

ThisBuild / scalaVersion := "2.13.12"
ThisBuild / crossScalaVersions := Seq(
Expand Down Expand Up @@ -54,57 +55,31 @@ lazy val `etag-caching-root` = (project in file("."))
).settings(baseSettings).settings(
publish / skip := true,
releaseCrossBuild := true, // true if you cross-build the project for multiple Scala versions
releaseVersion := Def.taskDyn {
releaseVersion := {
import sbtrelease.{ Version, versionFormatError }

val log = streams.value.log
val subprojectRefs = thisProject.value.aggregate
val compatibility = aggregatedAssessedCompatibilityWithLatestRelease.value

Def.taskDyn {
val compatibilityTask =
subprojectRefs.foldLeft(Def.task[Compatibility] {
Compatibility.BinaryAndSourceCompatible
}) { (previousCompatibilityTask, subproject) =>
Def.task {
val previousCompatibility = previousCompatibilityTask.value
val subprojectCompatibilities = (subproject / versionPolicyAssessCompatibility).value
subprojectCompatibilities.headOption match {
case Some((_, compatibility)) =>
log.debug(s"Compatibility of project ${subproject.project} is ${compatibility}")
(previousCompatibility, compatibility) match {
case (Compatibility.None, _) => Compatibility.None
case (_, Compatibility.None) => Compatibility.None
case (Compatibility.BinaryCompatible, _) => Compatibility.BinaryCompatible
case (_, Compatibility.BinaryCompatible) => Compatibility.BinaryCompatible
case _ => Compatibility.BinaryAndSourceCompatible
}
case None => previousCompatibility
}
}
}
Def.task {
val compatibility = compatibilityTask.value
log.info(s"Overall compatibility is ${compatibility}")
val maybeBump =
compatibility match {
case Compatibility.None => Some(Version.Bump.Major)
case Compatibility.BinaryCompatible => Some(Version.Bump.Minor)
case Compatibility.BinaryAndSourceCompatible => None // No need to bump the patch version, because it has already been bumped when sbt-release set the next release version
}
log.debug(s"releaseVersion function will apply ${maybeBump}")
({ (currentVersion: String) =>
val versionWithoutQualifier =
Version(currentVersion)
.getOrElse(versionFormatError(currentVersion))
.withoutQualifier
(maybeBump match {
case Some(bump) => versionWithoutQualifier.bump(bump)
case None => versionWithoutQualifier
}).string
})
log.info(s"Overall compatibility is ${compatibility}")
val maybeBump =
compatibility match {
case Compatibility.None => Some(Version.Bump.Major)
case Compatibility.BinaryCompatible => Some(Version.Bump.Minor)
case Compatibility.BinaryAndSourceCompatible => None // No need to bump the patch version, because it has already been bumped when sbt-release set the next release version
}
}
}.value,
log.debug(s"releaseVersion function will apply ${maybeBump}")
({ (currentVersion: String) =>
val versionWithoutQualifier =
Version(currentVersion)
.getOrElse(versionFormatError(currentVersion))
.withoutQualifier
(maybeBump match {
case Some(bump) => versionWithoutQualifier.bump(bump)
case None => versionWithoutQualifier
}).string
})
},
releaseProcess := Seq[ReleaseStep](
checkSnapshotDependencies,
inquireVersions,
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.21")

addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "2.1.3+14-700cfa17-SNAPSHOT")
addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "2.1.3+16-9c3dded3+20231129-1538-SNAPSHOT")

0 comments on commit d114399

Please sign in to comment.