diff --git a/src/main/scala/sbtghactions/GenerativePlugin.scala b/src/main/scala/sbtghactions/GenerativePlugin.scala index 4c9fa78..f1e6aad 100644 --- a/src/main/scala/sbtghactions/GenerativePlugin.scala +++ b/src/main/scala/sbtghactions/GenerativePlugin.scala @@ -80,8 +80,13 @@ object GenerativePlugin extends AutoPlugin { else s"'${str.replace("'", "''")}'" - def compileList(items: List[String]): String = - items.map(wrap).map("- " + _).mkString("\n") + def compileList(items: List[String], level: Int): String = { + val rendered = items.map(wrap) + if (rendered.map(_.length).sum < 40) // just arbitrarily... + rendered.mkString(" [", ", ", "]") + else + "\n" + indent(rendered.map("- " + _).mkString("\n"), level) + } def compilePREventType(tpe: PREventType): String = { import PREventType._ @@ -220,9 +225,9 @@ ${indent(rendered.mkString("\n"), 1)}""" val body = s"""name: ${wrap(job.name)}${renderedNeeds}${renderedCond} strategy: matrix: - os: [${job.oses.mkString(", ")}] - scala: [${job.scalas.mkString(", ")}] - java: [${job.javas.mkString(", ")}]${renderedMatrices} + os:${compileList(job.oses, 3)} + scala:${compileList(job.scalas, 3)} + java:${compileList(job.javas, 3)}${renderedMatrices} runs-on: $${{ matrix.os }}${renderedEnv} steps: ${indent(job.steps.map(compileStep(_, sbt, declareShell = declareShell)).mkString("\n\n"), 1)}""" diff --git a/src/test/scala/sbtghactions/GenerativePluginSpec.scala b/src/test/scala/sbtghactions/GenerativePluginSpec.scala index f13894d..b935918 100644 --- a/src/test/scala/sbtghactions/GenerativePluginSpec.scala +++ b/src/test/scala/sbtghactions/GenerativePluginSpec.scala @@ -370,6 +370,70 @@ class GenerativePluginSpec extends Specification { - name: Checkout current branch (fast) uses: actions/checkout@v2""" } + + "compile a job with illegal characters in the JVM" in { + val results = compileJob( + WorkflowJob( + "bippy", + "Bippity Bop Around the Clock", + List( + WorkflowStep.Run(List("echo hello")), + WorkflowStep.Checkout), + javas = List("this:is>#illegal")), + "") + + results mustEqual s"""bippy: + name: Bippity Bop Around the Clock + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.13.1] + java: ['this:is>#illegal'] + runs-on: $${{ matrix.os }} + steps: + - run: echo hello + + - name: Checkout current branch (fast) + uses: actions/checkout@v2""" + } + + "compile a job with a long list of scala versions" in { + val results = compileJob( + WorkflowJob( + "bippy", + "Bippity Bop Around the Clock", + List( + WorkflowStep.Run(List("echo hello")), + WorkflowStep.Checkout), + scalas = List("this", "is", "a", "lot", "of", "versions", "meant", "to", "overflow", "the", "bounds", "checking")), + "") + + results mustEqual s"""bippy: + name: Bippity Bop Around the Clock + strategy: + matrix: + os: [ubuntu-latest] + scala: + - this + - is + - a + - lot + - of + - versions + - meant + - to + - overflow + - the + - bounds + - checking + java: [adopt@1.8] + runs-on: $${{ matrix.os }} + steps: + - run: echo hello + + - name: Checkout current branch (fast) + uses: actions/checkout@v2""" + } } "predicate compilation" >> {