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
Copy link
Contributor

Choose a reason for hiding this comment

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

MillAlgTest needs fix:

==> X org.scalasteward.core.buildtool.mill.MillAlgTest.getDependencies, version < 0.11  0.04s munit.ComparisonFailException: modules/core/src/test/scala/org/scalasteward/core/buildtool/mill/MillAlgTest.scala:32
31:    )
32:    assertEquals(state, expected)
33:  }
values are not the same
=> Diff (- expected, + obtained)
         "read",
-        "/tmp/scala-steward/workspace/lihaoyi/fastparse/.mill-version"
+        "/tmp/scala-steward/workspace/lihaoyi/fastparse/build.mill"
       )
         "read",
-        "/tmp/scala-steward/workspace/lihaoyi/fastparse/.config/mill-version"
+        "/tmp/scala-steward/workspace/lihaoyi/fastparse/build.mill.scala"
       )
       cmd = List(
+        "read",
+        "/tmp/scala-steward/workspace/lihaoyi/fastparse/build.sc"
+      )
+    ),
+    Cmd(
+      cmd = List(
         "write",
    at munit.FunSuite.assertEquals(FunSuite.scala:13)
    at org.scalasteward.core.buildtool.mill.MillAlgTest.$anonfun$new$1(MillAlgTest.scala:32)
==> X org.scalasteward.core.buildtool.mill.MillAlgTest.getDependencies, 0.11 <= version < 0.12  0.004s org.scalasteward.core.buildtool.mill.parser$CirceParseError: Failed to decode Modules
    at org.scalasteward.core.buildtool.mill.parser$.$anonfun$parseModules$1(parser.scala:43)
    at cats.syntax.EitherOps$.leftMap$extension(either.scala:193)
    at org.scalasteward.core.buildtool.mill.parser$.parseModules(parser.scala:43)
    at org.scalasteward.core.buildtool.mill.MillAlg.$anonfun$getProjectDependencies$1(MillAlg.scala:85)
    at cats.data.Kleisli.$anonfun$flatMap$4(Kleisli.scala:75)
    at set @ org.scalasteward.core.io.MockProcessAlg$.$anonfun$create$6(MockProcessAlg.scala:22)
    at blocking @ org.scalasteward.core.io.FileAlg$$anon$1.readResource(FileAlg.scala:111)
    at get @ org.scalasteward.core.io.MockProcessAlg$.$anonfun$create$2(MockProcessAlg.scala:15)
    at flatMap @ org.scalasteward.core.mock.package$.getFlatMapSet(package.scala:32)
    at flatMap @ org.scalasteward.core.mock.package$.getFlatMapSet(package.scala:32)
    at set @ org.scalasteward.core.io.MockProcessAlg$.$anonfun$create$6(MockProcessAlg.scala:22)
    at map @ org.scalasteward.core.io.MockProcessAlg$.$anonfun$create$14(MockProcessAlg.scala:37)
    at map @ org.scalasteward.core.io.MockProcessAlg$.$anonfun$create$7(MockProcessAlg.scala:23)
    at flatMap @ org.scalasteward.core.io.MockProcessAlg$.$anonfun$create$7(MockProcessAlg.scala:23)
    at set @ org.scalasteward.core.io.MockProcessAlg$.$anonfun$create$6(MockProcessAlg.scala:22)
Caused by: ParsingFailure: exhausted input

Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,18 @@ final class MillAlg[F[_]](defaultResolvers: List[Resolver])(implicit
override protected val scalafixIssue: Option[String] =
Some("https://github.com/scala-steward-org/scala-steward/issues/2838")

private def getMillVersion(buildRootDir: File): F[Option[Version]] =
List(
buildRootDir / s".$millVersionName",
buildRootDir / ".config" / millVersionName
).collectFirstSomeM(fileAlg.readFile).map(_.flatMap(parser.parseMillVersion))
private def getMillVersion(buildRootDir: File): F[Option[Version]] = {
val fromConfigFile =
List(
buildRootDir / s".$millVersionName",
buildRootDir / ".config" / millVersionName
).collectFirstSomeM(fileAlg.readFile).map(_.flatMap(parser.parseMillVersion))
val fromBuildFile = List(buildRootDir / "build.mill", buildRootDir / "build.mill.scala")
Copy link
Member

Choose a reason for hiding this comment

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

build.sc is missing here. Also build.mill.yaml.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

build.sc is not here since it doesn't have a yaml header to parse.
I'm going to add build.mill.yaml. But, is it already supported? Maybe can be added in a follow up PR?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I wasn't aware build.sc does not support a YAML header. I think that's nowhere documented. build.mill.yaml is supported in Mill main and snapshot releases, but has a slightly different format (pure YAML without the comment-prefix), so no need to add it right now. I was just mentioning it for completeness.

Copy link
Member

Choose a reason for hiding this comment

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

I checked, Mill does read YAML-headers from build.sc files. We should also add support for them.

.collectFirstSomeM(fileAlg.readFile)
.map(_.flatMap(parser.parseBuildFileMillVersion))

fromBuildFile.orElse(fromConfigFile)
}

private def getMillPluginDeps(
millVersion: Version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ object parser {
def parseMillVersion(s: String): Option[Version] =
Option(s.trim).filter(_.nonEmpty).map(Version.apply)

private val millVersionRegex = """\s*\/\/\|\s*mill-version:\s*['"]?(.+?)['"]?\s*""".r
def parseBuildFileMillVersion(s: String): Option[Version] = {
s.linesIterator.collectFirst {
case millVersionRegex(version) => Version(version)
}
}

/** Used to correctly format the Mill plugin artifacts will when included look like:
* - import $ivy.`com.goyeau::mill-scalafix::0.2.10`
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,31 @@ class MillVersionParserTest extends FunSuite {
val parsed = parser.parseMillVersion(versionFileContent).map(_.value)
assertEquals(parsed, expected)
}

test(s"parse version from build.mill file") {
val buildMillFileContent = """
|//|
|//| mill-version: 1.0.5
|""".stripMargin
val parsed = parser.parseBuildFileMillVersion(buildMillFileContent).map(_.value)
assertEquals(parsed, Some("1.0.5"))
}

test(s"parse quoted version from build.mill file") {
val buildMillFileContent = """
|//|
|//| mill-version: "1.0.5"
|""".stripMargin
val parsed = parser.parseBuildFileMillVersion(buildMillFileContent).map(_.value)
assertEquals(parsed, Some("1.0.5"))
}

test(s"parse single quoted version from build.mill file") {
val buildMillFileContent = """
|//|
|//| mill-version: '1.0.5'
|""".stripMargin
val parsed = parser.parseBuildFileMillVersion(buildMillFileContent).map(_.value)
assertEquals(parsed, Some("1.0.5"))
}
}
2 changes: 1 addition & 1 deletion project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ object Dependencies {
val scalacheck = "org.scalacheck" %% "scalacheck" % "1.19.0"
val scalaStewardMillPluginArtifactName = "scala-steward-mill-plugin"
val scalaStewardMillPlugin =
"org.scala-steward" % s"${scalaStewardMillPluginArtifactName}_mill0.11_2.13" % "0.18.2"
"org.scala-steward" % s"${scalaStewardMillPluginArtifactName}_mill1_3" % "0.18.2-9-0ad5e5"
val tomlj = "org.tomlj" % "tomlj" % "1.1.1"
}