Skip to content

Commit 284c207

Browse files
committed
Handle Scala LTS and Next version update
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)
1 parent ddfdff8 commit 284c207

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

modules/core/src/main/resources/default.scala-steward.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ postUpdateHooks = [
3030
updates.ignore = [
3131
// Artifacts below are ignored because they are not yet announced.
3232

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

3838
// Ignore the next Scala 3 LTS version until it is announced.
3939
{ groupId = "org.scala-lang", artifactId = "scala3-compiler", version = { exact = "3.3.4" } },

modules/core/src/main/scala/org/scalasteward/core/data/package.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ package org.scalasteward.core
1919
package object data {
2020
val scalaLangGroupId: GroupId = GroupId("org.scala-lang")
2121

22-
val scalaLangModules: List[(GroupId, ArtifactId)] =
22+
val scala2LangModules: List[(GroupId, ArtifactId)] =
2323
List(
2424
(scalaLangGroupId, ArtifactId("scala-compiler")),
2525
(scalaLangGroupId, ArtifactId("scala-library")),
2626
(scalaLangGroupId, ArtifactId("scala-reflect")),
27-
(scalaLangGroupId, ArtifactId("scalap")),
27+
(scalaLangGroupId, ArtifactId("scalap"))
28+
)
29+
30+
val scala3LangModules: List[(GroupId, ArtifactId)] =
31+
List(
2832
(scalaLangGroupId, ArtifactId("scala3-compiler")),
2933
(scalaLangGroupId, ArtifactId("scala3-library")),
3034
(scalaLangGroupId, ArtifactId("scala3-library_sjs1"))
3135
)
36+
37+
val scalaLangModules: List[(GroupId, ArtifactId)] =
38+
scala2LangModules ++ scala3LangModules
39+
40+
val scalaNextMinVersion: Version = Version("3.4.0")
3241
}

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ object FilterAlg {
5454
case NotAllowedByConfig(_) => "not allowed by config"
5555
case NoSuitableNextVersion(_) => "no suitable next version"
5656
case VersionOrderingConflict(_) => "version ordering conflict"
57+
case IgnoreScalaNext(_) => "not upgrading from Scala LTS to Next version"
5758
}
5859
}
5960

@@ -62,9 +63,30 @@ object FilterAlg {
6263
final case class NotAllowedByConfig(update: Update.ForArtifactId) extends RejectionReason
6364
final case class NoSuitableNextVersion(update: Update.ForArtifactId) extends RejectionReason
6465
final case class VersionOrderingConflict(update: Update.ForArtifactId) extends RejectionReason
66+
final case class IgnoreScalaNext(update: Update.ForArtifactId) extends RejectionReason
6567

6668
def localFilter(update: Update.ForArtifactId, repoConfig: RepoConfig): FilterResult =
67-
repoConfig.updates.keep(update).flatMap(globalFilter(_, repoConfig))
69+
repoConfig.updates.keep(update).flatMap(scalaLTSFilter).flatMap(globalFilter(_, repoConfig))
70+
71+
def scalaLTSFilter(update: Update.ForArtifactId): FilterResult =
72+
if (!isScala3Lang(update))
73+
Right(update)
74+
else {
75+
if (update.currentVersion >= scalaNextMinVersion) {
76+
// already on Scala Next
77+
Right(update)
78+
} else {
79+
val filteredVersions = update.newerVersions.filterNot(_ >= scalaNextMinVersion)
80+
if (filteredVersions.nonEmpty)
81+
Right(update.copy(newerVersions = Nel.fromListUnsafe(filteredVersions)))
82+
else Left(IgnoreScalaNext(update))
83+
}
84+
}
85+
86+
def isScala3Lang(update: Update.ForArtifactId): Boolean =
87+
scala3LangModules.exists { case (g, a) =>
88+
update.groupId == g && update.artifactIds.exists(_ == a)
89+
}
6890

6991
private def globalFilter(update: Update.ForArtifactId, repoConfig: RepoConfig): FilterResult =
7092
selectSuitableNextVersion(update, repoConfig).flatMap(checkVersionOrdering)

modules/core/src/test/scala/org/scalasteward/core/update/FilterAlgTest.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,4 +246,24 @@ class FilterAlgTest extends FunSuite {
246246
val dependency = "org.typelevel".g % ("cats-effect", "cats-effect_2.12").a % "1.0.0"
247247
assert(isDependencyConfigurationIgnored(dependency.copy(configurations = Some("scalafmt"))))
248248
}
249+
250+
test("scalaLTSFilter: LTS") {
251+
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.3.3" %> Nel.of("3.4.0")).single
252+
assertEquals(scalaLTSFilter(update), Left(IgnoreScalaNext(update)))
253+
}
254+
255+
test("scalaLTSFilter: Next") {
256+
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.4.0" %> Nel.of("3.4.1")).single
257+
assertEquals(scalaLTSFilter(update), Right(update))
258+
}
259+
260+
test("isScala3Lang: true") {
261+
val update = ("org.scala-lang".g % "scala3-compiler".a % "3.3.3" %> Nel.of("3.4.0")).single
262+
assert(isScala3Lang(update))
263+
}
264+
265+
test("isScala3Lang: false") {
266+
val update = ("org.scala-lang".g % "scala-compiler".a % "2.13.11" %> Nel.of("2.13.12")).single
267+
assert(!isScala3Lang(update))
268+
}
249269
}

0 commit comments

Comments
 (0)