mill icon indicating copy to clipboard operation
mill copied to clipboard

`init <Giter8 template>` does not work (version 0.12.8) without `-i` flag

Open carlosrogue opened this issue 10 months ago • 6 comments

When checking https://github.com/com-lihaoyi/mill-scala-hello.g8 I realize this does not work anymore: mill init com-lihaoyi/mill-scala-hello.g8 but like this MILL_VERSION=0.11.11 mill init com-lihaoyi/mill-scala-hello.g8. With my local mill version 0.12.8 I have to run it as interactive and it works: mill -i init com-lihaoyi/mill-scala-hello.g8. Should the -i flag be added to the init module docs: Run mill -i init <Giter8 template> or should we modify (implicity) the run mode when is giter8 template? Something similar mentioned here: https://github.com/com-lihaoyi/mill/pull/1874#issuecomment-1133599462

carlosrogue avatar Feb 20 '25 07:02 carlosrogue

Do you have an error message we can see?

lihaoyi avatar Feb 20 '25 07:02 lihaoyi

$ mill init com-lihaoyi/mill-scala-hello.g8
No mill version specified.
You should provide a version via '.mill-version' file or --mill-version option.
Using mill version 0.12.8
[build.mill-61/65] compile
[build.mill-61] [info] compiling 1 Scala source to /home/carlosrogue/Projects/2025/g8/out/mill-build/compile.dest/classes ...
[build.mill-61] [info] done compiling
[1/1] init
[1] Creating a new project...
[1] A minimal Scala project built with Mill 
[1] 
[1] name [Scala Hello World]: [1] 
[1] Interrupting...
[1] 
[1/1] ================ init com-lihaoyi/mill-scala-hello.g8 =============== 19s
1 tasks failed
init java.lang.Exception: 1 tasks failed
mill.scalalib.giter8.Giter8Module.init os.SubprocessException: Result of /home/carlosrogue/.cache/coursier/jvm/[email protected]/bin/java…: 1

    os.proc.call(ProcessOps.scala:230)
    mill.util.Jvm$.callProcess(Jvm.scala:95)
    mill.scalalib.giter8.Giter8Module.$anonfun$init$1(Giter8Module.scala:36)
    mill.define.Task$TraverseCtx.evaluate(Task.scala:225)
    mill.main.MainModule.$anonfun$init$1(MainModule.scala:603)
    mill.define.Task$TraverseCtx.evaluate(Task.scala:225)

carlosrogue avatar Feb 20 '25 22:02 carlosrogue

@lihaoyi something like this should succeed in MillInitTests:

    test("Mill init works for g8 templates without explicit interactive") - integrationTest { tester =>
      import tester._
      // pass "example" to eval from stdin
      eval(("init", "com-lihaoyi/mill-scala-hello.g8"), stdin = "--name=example").isSuccess ==> true
      val projFile = workspacePath / "example/build.sc"
      assert(os.exists(projFile))
    }

Why this command does not work: mill 'integration.feature[init].test', I can compile but not run tests.

UPDATE I see this inside eval:

      val serverArgs = Option.when(!clientServerMode)("--no-server")

So this parameter might be missing. Idea to introduce --quiet/-q flag, default: true. When true validates field names, requiring only name field and printing other fields with their default value, skipping generation:

$ mill init <org/repo>.g8 --name=example
Missing fields: --package=com.example --other-prop=value3, skipping project generation

When false, require all fields, still reports missing one but fail the task execution. Some reading (ordered) properties code: https://github.com/foundweekends/giter8/blob/cb4a859b2fac2825d073ec2851cd8bc000f7b87c/library/src/main/scala/g8.scala#L564 And how to get the default properties file: https://github.com/foundweekends/giter8/blob/cb4a859b2fac2825d073ec2851cd8bc000f7b87c/plugin/src/main/scala/Giter8Plugin.scala#L84

carlosrogue avatar Feb 21 '25 06:02 carlosrogue

Seems like the problem is that the .g8 initialization requires user input, which became stricter in 0.12.x, requiring -i/--interactive to work. We probably should update the docs and add a proper error

lihaoyi avatar Mar 13 '25 01:03 lihaoyi

So a new test in MillInitTests like this should pass:

    test("Mill init works for g8 templates only with explicit interactive") - integrationTest { tester =>
      import tester._
      eval(("-i", "init", "com-lihaoyi/mill-scala-hello.g8"), stdin = "--name=example").isSuccess ==> true
      val projFile = workspacePath / "example/build.sc"
      assert(os.exists(projFile))
    }

carlosrogue avatar Apr 05 '25 00:04 carlosrogue

Maybe, we should introduce a interactive flag in Task.Command such that we can detect early and generically, that the user is supposed to run with --interactive. (We could even automatically restart Mill interactively, if that is a wanted feature, but we should put this behind a config setting.)

lefou avatar Apr 06 '25 12:04 lefou