Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ lazy val site = project
.settings(
name := "sbt-typelevel-site"
)
.dependsOn(kernel, github, githubActions, versioning, noPublish)
.dependsOn(kernel, github, githubActions, noPublish)

lazy val unidoc = project
.in(file("unidoc"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package org.typelevel.sbt

import sbt._
import sbt.*
import sbt.plugins.JvmPlugin

import Keys._
import Keys.*
import org.typelevel.sbt.kernel.{GitHelper, V}

object TypelevelKernelPlugin extends AutoPlugin {

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

private[sbt] lazy val currentReleaseImpl = 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 = previousReleasesImpl.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 currentPreReleaseImpl = Def.setting {
previousReleasesImpl.value.headOption.map(_.toString)
}

private[sbt] lazy val previousReleasesImpl = 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
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import LaikaPlugin.autoImport._
import gha.GenerativePlugin
import GenerativePlugin.autoImport._
import TypelevelKernelPlugin.autoImport._
import TypelevelVersioningPlugin.autoImport._

object TypelevelSitePlugin extends AutoPlugin {

Expand Down Expand Up @@ -110,8 +109,8 @@ object TypelevelSitePlugin extends AutoPlugin {
mdocVariables := {
mdocVariables.value ++
Map(
"VERSION" -> currentRelease.value.getOrElse(version.value),
"PRERELEASE_VERSION" -> currentPreRelease.value.getOrElse(version.value),
"VERSION" -> currentReleaseImpl.value.getOrElse(version.value),
"PRERELEASE_VERSION" -> currentPreReleaseImpl.value.getOrElse(version.value),
"SNAPSHOT_VERSION" -> version.value
) ++
tlSiteApiUrl.value.map("API_URL" -> _.toString).toMap
Expand All @@ -129,7 +128,7 @@ object TypelevelSitePlugin extends AutoPlugin {
scalaVersion.value,
scalaBinaryVersion.value
)
version <- currentRelease.value
version <- currentReleaseImpl.value
} yield {
val o = moduleId.organization
val n = cross(moduleId.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import sbt._

import scala.util.Try
import Keys._
import org.typelevel.sbt.TypelevelKernelPlugin.autoImport._

object TypelevelVersioningPlugin extends AutoPlugin {

Expand All @@ -37,36 +38,11 @@ object TypelevelVersioningPlugin extends AutoPlugin {
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 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)
}
lazy val currentRelease = currentReleaseImpl

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

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) <= _)
}
}
lazy val currentPreRelease = currentPreReleaseImpl
Copy link
Member

Choose a reason for hiding this comment

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

We should define these as proper settingKeys with descriptions, that are populated below based on the implementations.

Copy link
Member

Choose a reason for hiding this comment

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

Also, we should be mindful about naming. tl-prefixed to avoid collisions with other plugins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍


lazy val previousReleases = previousReleasesImpl
}

import autoImport._
Expand Down