diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index 6ccc50c..2ea4be9 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -282,12 +282,16 @@ ${indent(rendered.mkString("\n"), 1)}""" case sbtStep: Sbt => import sbtStep.commands - val multi = (sbtStepPreamble ::: commands) match { + // Arguments starting with '-' (-D..., -J..., -v) are options for the sbt launcher, not + // commands; inside the command string sbt would try to run them, so they stay separate. + val (launcherOptions, sbtCommands) = (sbtStepPreamble ::: commands).partition(_.startsWith("-")) + val renderedOptions = launcherOptions.map(o => if (o.indexOf(' ') >= 0) s"'$o'" else o) + val multi = sbtCommands match { case x :: Nil => x case xs => s"'${xs.mkString("; ")}'" } renderRunBody( - commands = List(s"$sbt $multi"), + commands = List((sbt :: renderedOptions ::: List(multi)).mkString(" ")), params = sbtStep.params, renderedShell = renderedShell ) diff --git a/src/test/scala/sbtghactions/GenerativePluginSpec.scala b/src/test/scala/sbtghactions/GenerativePluginSpec.scala index 0bd4dcc..ee232be 100644 --- a/src/test/scala/sbtghactions/GenerativePluginSpec.scala +++ b/src/test/scala/sbtghactions/GenerativePluginSpec.scala @@ -442,6 +442,18 @@ class GenerativePluginSpec extends Specification { sbtStepPreamble = Nil) mustEqual s"- run: $$SBT ci-release" } + "keep sbt launcher options out of the command string" in { + compileStep( + Sbt(List("-Dslick.testkit-config=test-dbs/testkit-github.conf", "test")), + "$SBT") mustEqual s"- run: $$SBT -Dslick.testkit-config=test-dbs/testkit-github.conf '++ $${{ matrix.scala }}; test'" + } + + "quote sbt launcher options containing spaces" in { + compileStep( + Sbt(List("-Dgreeting=hello world", "test")), + "$SBT") mustEqual s"- run: $$SBT '-Dgreeting=hello world' '++ $${{ matrix.scala }}; test'" + } + "compile sbt with parameters" in { compileStep( Sbt(List("compile", "test"), params = Map("abc" -> "def", "cafe" -> "@42")),