Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tlLatestVersion, tlLatestPreReleaseVersion to versioning plugin #333

Merged
merged 10 commits into from
Jul 16, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import sbt._
import sbt.plugins.JvmPlugin

import Keys._
bplommer marked this conversation as resolved.
Show resolved Hide resolved
import org.typelevel.sbt.kernel.{GitHelper, V}

object TypelevelKernelPlugin extends AutoPlugin {

Expand All @@ -37,6 +38,36 @@ object TypelevelKernelPlugin extends AutoPlugin {
BasicCommands.addAlias(BasicCommands.removeAlias(s, name), name, contents)
}
})

private[sbt] lazy val currentRelease: Def.Initialize[Option[String]] = Def.setting {
// some tricky logic here ...
// if the latest release is a pre-release (e.g., M or RC)
// and there are no stable releases it is bincompatible with,
// then for all effective purposes it is the current release

val release = previousReleases.value match {
case head :: tail if head.isPrerelease =>
tail
.filterNot(_.isPrerelease)
.find(head.copy(prerelease = None).mustBeBinCompatWith(_))
.orElse(Some(head))
case releases => releases.headOption
}

release.map(_.toString)
}

// latest tagged release, including pre-releases
private[sbt] lazy val currentPreRelease: Def.Initialize[Option[String]] = Def.setting {
previousReleases.value.headOption.map(_.toString)
}

private[sbt] lazy val previousReleases: Def.Initialize[List[V]] = Def.setting {
val currentVersion = V(version.value).map(_.copy(prerelease = None))
GitHelper.previousReleases(fromHead = true, strict = false).filter { v =>
currentVersion.forall(v.copy(prerelease = None) <= _)
}
}
}

import autoImport._
Expand Down
32 changes: 0 additions & 32 deletions site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import laika.helium.config.ImageLink
import laika.sbt.LaikaPlugin
import laika.theme.ThemeProvider
import mdoc.MdocPlugin
import org.typelevel.sbt.kernel.GitHelper
import org.typelevel.sbt.kernel.V
import org.typelevel.sbt.site._
import sbt._

Expand Down Expand Up @@ -250,36 +248,6 @@ object TypelevelSitePlugin extends AutoPlugin {
)
)

private lazy val currentRelease = Def.setting {
// some tricky logic here ...
// if the latest release is a pre-release (e.g., M or RC)
// and there are no stable releases it is bincompatible with,
// then for all effective purposes it is the current release

val release = previousReleases.value match {
case head :: tail if head.isPrerelease =>
tail
.filterNot(_.isPrerelease)
.find(head.copy(prerelease = None).mustBeBinCompatWith(_))
.orElse(Some(head))
case releases => releases.headOption
}

release.map(_.toString)
}

// latest tagged release, including pre-releases
private lazy val currentPreRelease = Def.setting {
previousReleases.value.headOption.map(_.toString)
}

private lazy val previousReleases = Def.setting {
val currentVersion = V(version.value).map(_.copy(prerelease = None))
GitHelper.previousReleases(fromHead = true, strict = false).filter { v =>
currentVersion.forall(v.copy(prerelease = None) <= _)
}
}

private def previewTask = Def
.taskDyn {
// inlined from https://github.com/planet42/Laika/blob/9022f6f37c9017f7612fa59398f246c8e8c42c3e/sbt/src/main/scala/laika/sbt/Tasks.scala#L192
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import sbt._
import scala.util.Try

import Keys._
bplommer marked this conversation as resolved.
Show resolved Hide resolved
import org.typelevel.sbt.TypelevelKernelPlugin.autoImport._

object TypelevelVersioningPlugin extends AutoPlugin {

Expand All @@ -37,6 +38,13 @@ object TypelevelVersioningPlugin extends AutoPlugin {
lazy val tlUntaggedAreSnapshots =
settingKey[Boolean](
"If true, an untagged commit is given a snapshot version, e.g. 0.4-00218f9-SNAPSHOT. If false, it is given a release version, e.g. 0.4-00218f9. (default: true)")

lazy val tlCurrentRelease =
settingKey[Option[String]](
"The latest stable released version of your project, e.g. 0.2.0, 3.5.1. If applicable, this will be the version currently being released.")

lazy val tlCurrentPreRelease = settingKey[Option[String]](
"The latest pre-release (e.g. milestone, release candidate) of your project. If applicable, this will be the version currently being released.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, these are great descriptions! Bikeshed time, is "current release" and "current pre-release" the best terminology for these? Maybe "latest" is more appropriate? And "version" instead of "release"?

I guest that gets us to something like tlLatestStableVersion and tlLatestPreReleaseVersion maybe 🤔 bit of a mouthful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have absolutely no opinion on this but happy to change it if you like 😃

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not even a smidgeon of an opinion? 😂 I hate deciding these things. I can commit whatever I decide before I merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I have a slight preference for tlLatestStableRelease and tlLatestPreRelease - explicit but reasonably concise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the other hand, currentRelease isn't actually guaranteed to be a stable release:

if the latest release is a pre-release (e.g., M or RC)
and there are no stable releases it is bincompatible with,
then for all effective purposes it is the current release

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I leave this with you to commit the final wording and naming? Happy to discuss ideas of course

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I can do that. Thanks for all your help, nice to bounce ideas! Much appreciated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the first one is maybe something like:

The latest stable version of your project in the tlBaseVersion series, with the latest pre-release in this series used as a fallback if there is no stable release yet.

Ah yeah sounds good, I only just saw this now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest stable version of your project in the tlBaseVersion series, with the latest pre-release in this series used as a fallback if there is no stable release yet.

Actually I don't think that's correct? tlBaseVersion isn't used in the calculation, and this won't be the behaviour if (say) tlBaseVersion is 1.4 but there's a stable 1.3.0 release and a 1.4.0-M1 release, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it's still not 100% correct.

tlBaseVersion isn't used in the calculation

It is, albeit indirectly. version is used in the calculation, and tlBaseVersion is used to calculate version.

tlBaseVersion is 1.4 but there's a stable 1.3.0 release and a 1.4.0-M1 release, right?

You are right about this. It uses the binary series and not the x.y series.

}

import autoImport._
Expand Down Expand Up @@ -123,7 +131,9 @@ object TypelevelVersioningPlugin extends AutoPlugin {
if (isSnapshot.value) version += "-SNAPSHOT"

version
}
},
tlCurrentRelease := currentRelease.value,
tlCurrentPreRelease := currentPreRelease.value
)

private val Description = """^.*-(\d+)-[a-zA-Z0-9]+$""".r
Expand Down