Skip to content

Commit

Permalink
Handle Scala LTS and Next version update
Browse files Browse the repository at this point in the history
Scala Steward now distinguishes between Scala Next and Scala LTS.

When the current Scala 3 versions is below 3.4.0 no updates to a newer Scala Next version will be created. But updates to newer Scala 3.3.x version will be created.

If the current version is already a Scala Next version (3.4.x), updates to newer Scala Next versions will be created.

In the future the `versionLine` property can be used to identify LTS and Next version. (scala/scala3#19986)
  • Loading branch information
mzuehlke committed Mar 31, 2024
1 parent e8dd833 commit 7a2ca27
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 7 deletions.
8 changes: 4 additions & 4 deletions modules/core/src/main/resources/default.scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ postUpdateHooks = [
updates.ignore = [
// Artifacts below are ignored because they are not yet announced.

// No upgrades to non LTS versions
{ groupId = "org.scala-lang", artifactId = "scala3-compiler", version = { prefix = "3.4." } },
{ groupId = "org.scala-lang", artifactId = "scala3-library", version = { prefix = "3.4." } },
{ groupId = "org.scala-lang", artifactId = "scala3-library_sjs1", version = { prefix = "3.4." } },
// Ignore the next Scala 3 Next version until it is announced.
{ groupId = "org.scala-lang", artifactId = "scala3-compiler", version = { exact = "3.4.2" } },
{ groupId = "org.scala-lang", artifactId = "scala3-library", version = { exact = "3.4.2" } },
{ groupId = "org.scala-lang", artifactId = "scala3-library_sjs1", version = { exact = "3.4.2" } },

// Ignore the next Scala 3 LTS version until it is announced.
{ groupId = "org.scala-lang", artifactId = "scala3-compiler", version = { exact = "3.3.4" } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,23 @@ package org.scalasteward.core
package object data {
val scalaLangGroupId: GroupId = GroupId("org.scala-lang")

val scalaLangModules: List[(GroupId, ArtifactId)] =
val scala2LangModules: List[(GroupId, ArtifactId)] =
List(
(scalaLangGroupId, ArtifactId("scala-compiler")),
(scalaLangGroupId, ArtifactId("scala-library")),
(scalaLangGroupId, ArtifactId("scala-reflect")),
(scalaLangGroupId, ArtifactId("scalap")),
(scalaLangGroupId, ArtifactId("scalap"))
)

val scala3LangModules: List[(GroupId, ArtifactId)] =
List(
(scalaLangGroupId, ArtifactId("scala3-compiler")),
(scalaLangGroupId, ArtifactId("scala3-library")),
(scalaLangGroupId, ArtifactId("scala3-library_sjs1"))
)

val scalaLangModules: List[(GroupId, ArtifactId)] =
scala2LangModules ++ scala3LangModules

val scalaNextMinVersion: Version = Version("3.4.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ object FilterAlg {
case NotAllowedByConfig(_) => "not allowed by config"
case NoSuitableNextVersion(_) => "no suitable next version"
case VersionOrderingConflict(_) => "version ordering conflict"
case IgnoreScalaNext(_) => "not upgrading from Scala LTS to Next version"

Check warning on line 57 in modules/core/src/main/scala/org/scalasteward/core/update/FilterAlg.scala

View check run for this annotation

Codecov / codecov/patch

modules/core/src/main/scala/org/scalasteward/core/update/FilterAlg.scala#L57

Added line #L57 was not covered by tests
}
}

Expand All @@ -62,9 +63,30 @@ object FilterAlg {
final case class NotAllowedByConfig(update: Update.ForArtifactId) extends RejectionReason
final case class NoSuitableNextVersion(update: Update.ForArtifactId) extends RejectionReason
final case class VersionOrderingConflict(update: Update.ForArtifactId) extends RejectionReason
final case class IgnoreScalaNext(update: Update.ForArtifactId) extends RejectionReason

def localFilter(update: Update.ForArtifactId, repoConfig: RepoConfig): FilterResult =
repoConfig.updates.keep(update).flatMap(globalFilter(_, repoConfig))
repoConfig.updates.keep(update).flatMap(scalaLTSFilter).flatMap(globalFilter(_, repoConfig))

def scalaLTSFilter(update: Update.ForArtifactId): FilterResult =
if (!isScala3Lang(update))
Right(update)
else {
if (update.currentVersion >= scalaNextMinVersion) {
// already on Scala Next
Right(update)
} else {
val filteredVersions = update.newerVersions.filterNot(_ >= scalaNextMinVersion)
if (filteredVersions.nonEmpty)
Right(update.copy(newerVersions = Nel.fromListUnsafe(filteredVersions)))

Check warning on line 81 in modules/core/src/main/scala/org/scalasteward/core/update/FilterAlg.scala

View check run for this annotation

Codecov / codecov/patch

modules/core/src/main/scala/org/scalasteward/core/update/FilterAlg.scala#L81

Added line #L81 was not covered by tests
else Left(IgnoreScalaNext(update))
}
}

def isScala3Lang(update: Update.ForArtifactId): Boolean =
scala3LangModules.exists { case (g, a) =>
update.groupId == g && update.artifactIds.exists(_ == a)
}

private def globalFilter(update: Update.ForArtifactId, repoConfig: RepoConfig): FilterResult =
selectSuitableNextVersion(update, repoConfig).flatMap(checkVersionOrdering)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,24 @@ class FilterAlgTest extends FunSuite {
val dependency = "org.typelevel".g % ("cats-effect", "cats-effect_2.12").a % "1.0.0"
assert(isDependencyConfigurationIgnored(dependency.copy(configurations = Some("scalafmt"))))
}

test("scalaLTSFilter: LTS") {
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.3.3" %> Nel.of("3.4.0")).single
assertEquals(scalaLTSFilter(update), Left(IgnoreScalaNext(update)))
}

test("scalaLTSFilter: Next") {
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.4.0" %> Nel.of("3.4.1")).single
assertEquals(scalaLTSFilter(update), Right(update))
}

test("isScala3Lang: true") {
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.3.3" %> Nel.of("3.4.0")).single
assert(isScala3Lang(update))
}

test("isScala3Lang: false") {
val update = ("org.scala-lang".g % "scala-compiler".a % "2.13.11" %> Nel.of("2.13.12")).single
assert(!isScala3Lang(update))
}
}

0 comments on commit 7a2ca27

Please sign in to comment.