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

Suggest to update only to stable version #1634

Merged
merged 1 commit into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -105,4 +105,66 @@ class ActionableDiagnosticTests extends munit.FunSuite {
}
}

test("actionable actions suggest update only to stable version") {
val testInputs = TestInputs(
os.rel / "Foo.scala" ->
s"""//> using lib "test-org::test-name-1:1.0.6"
|
|object Hello extends App {
| println("Hello")
|}
|""".stripMargin
)
// create fake repository which contains hardcoded versions [1.0.6, 1.0.7, 1.0.7-M1] of test-name-1 library
// scala-cli should skip non-stable version 1.0.7-M1 and suggest update 1.0.7
val repoTmpDir = os.temp.dir(prefix = "scala-cli-tests-actionable-diagnostic-repo")
os.write(
repoTmpDir / "test-org" / "test-name-1_3" / "maven-metadata.xml",
"""<?xml version="1.0" encoding="UTF-8"?>
|<metadata>
| <groupId>test-org</groupId>
| <artifactId>test-name-1_3</artifactId>
| <versioning>
| <latest>1.0.7-M1</latest>
| <release>1.0.7-M1</release>
| <versions>
| <version>1.0.6</version>
| <version>1.0.7</version>
| <version>1.0.7-M1</version>
| </versions>
| </versioning>
|</metadata>
|""".stripMargin,
createFolders = true
)
os.write(
repoTmpDir / "test-org" / "test-name-1_3" / "1.0.6" / "test-name-1_3-1.0.6.pom",
"""<?xml version='1.0' encoding='UTF-8'?>
|<project>
| <groupId>test-org</groupId>
| <artifactId>test-name-1_3</artifactId>
| <version>1.0.6</version>
|</project>""".stripMargin,
createFolders = true
)
val withRepoBuildOptions = baseOptions.copy(
classPathOptions =
baseOptions.classPathOptions.copy(extraRepositories = Seq(s"file:${repoTmpDir.toString}"))
)
testInputs.withBuild(withRepoBuildOptions, buildThreads, None, actionableDiagnostics = true) {
(_, _, maybeBuild) =>
val build = maybeBuild.orThrow

val updateDiagnostics =
ActionablePreprocessor.generateActionableDiagnostics(build.options).orThrow

val testLibDiagnosticOpt = updateDiagnostics.collectFirst {
case diagnostic: ActionableDependencyUpdateDiagnostic => diagnostic
}
expect(testLibDiagnosticOpt.nonEmpty)
val testLibDiagnostic = testLibDiagnosticOpt.get

expect(testLibDiagnostic.newVersion == "1.0.7")
}
}
}
@@ -1,13 +1,14 @@
package scala.build.actionable

import coursier.Versions
import coursier.parse.RepositoryParser
import dependency._

import scala.build.EitherCps.{either, value}
import scala.build.Positioned
import scala.build.actionable.ActionableDiagnostic._
import scala.build.actionable.errors.ActionableHandlerError
import scala.build.errors.BuildException
import scala.build.errors.{BuildException, RepositoryFormatError}
import scala.build.internal.Util._
import scala.build.options.BuildOptions
import scala.build.options.ScalaVersionUtil.versionsWithTtl0
Expand Down Expand Up @@ -40,12 +41,15 @@ case object ActionableDependencyHandler
buildOptions: BuildOptions,
dependency: AnyDependency
): Either[BuildException, String] = either {
val scalaParams = value(buildOptions.scalaParams)
val cache = buildOptions.finalCache
val csModule = value(dependency.toCs(scalaParams)).module
val scalaParams = value(buildOptions.scalaParams)
val cache = buildOptions.finalCache
val csModule = value(dependency.toCs(scalaParams)).module
val repositories = value(buildOptions.finalRepositories)

value {
cache.versionsWithTtl0(csModule).versions.latest(coursier.core.Latest.Release).toRight {
cache.versionsWithTtl0(csModule, repositories).versions.latest(
coursier.core.Latest.Stable
).toRight {
new ActionableHandlerError(s"No latest version found for ${dependency.render}")
}
}
Expand Down
Expand Up @@ -46,12 +46,9 @@ object ScalaVersionUtil {
repositories: Seq[Repository] = Seq.empty
): Versions.Result =
cache.withTtl(0.seconds).logger.use {
val versionsWithModule = Versions(cache)
Versions(cache)
.withModule(module)
val versionsWithRepositories =
if repositories.nonEmpty then versionsWithModule.withRepositories(repositories)
else versionsWithModule
versionsWithRepositories
.addRepositories(repositories: _*)
.result()
.unsafeRun()(cache.ec)
}
Expand Down