Skip to content

Commit

Permalink
Added support for proper escaping in java/scala/os names
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed May 29, 2020
1 parent ebc041d commit 459719c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/scala/sbtghactions/GenerativePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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)}"""
Expand Down
64 changes: 64 additions & 0 deletions src/test/scala/sbtghactions/GenerativePluginSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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: [[email protected]]
runs-on: $${{ matrix.os }}
steps:
- run: echo hello

- name: Checkout current branch (fast)
uses: actions/checkout@v2"""
}
}

"predicate compilation" >> {
Expand Down

0 comments on commit 459719c

Please sign in to comment.