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

Fix - actionable actions not suggest update to previous version #1813

Merged
merged 1 commit into from
Jan 27, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,63 @@ class ActionableDiagnosticTests extends munit.FunSuite {
expect(testLibDiagnostic.newVersion == "1.0.7")
}
}

test("actionable actions should not suggest update to previous version") {
val testInputs = TestInputs(
os.rel / "Foo.scala" ->
s"""//> using lib "test-org::test-name-1:2.0.0-M1"
|
|object Hello extends App {
| println("Hello")
|}
|""".stripMargin
)
// create fake repository which contains hardcoded versions [1.0.0] of test-name-1 library
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>2.0.0-M</latest>
| <release>2.0.0-M1</release>
| <versions>
| <version>1.0.0</version>
| <version>2.0.0-M1</version>
| </versions>
| </versioning>
|</metadata>
|""".stripMargin,
createFolders = true
)
os.write(
repoTmpDir / "test-org" / "test-name-1_3" / "2.0.0-M1" / "test-name-1_3-2.0.0-M1.pom",
"""<?xml version='1.0' encoding='UTF-8'?>
|<project>
| <groupId>test-org</groupId>
| <artifactId>test-name-1_3</artifactId>
| <version>2.0.0-M1</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
}
println(testLibDiagnosticOpt)
expect(testLibDiagnosticOpt.isEmpty)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package scala.build.actionable

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

Expand Down Expand Up @@ -29,7 +30,7 @@ case object ActionableDependencyHandler
val currentVersion = dependency.version
val latestVersion = value(findLatestVersion(buildOptions, dependency))

if (latestVersion != currentVersion)
if (Version(latestVersion) > Version(currentVersion))
if (dependency.userParams.contains("toolkit"))
Some(ActionableDependencyUpdateDiagnostic(
setting.positions,
Expand Down