Skip to content

Commit

Permalink
Added id to WorkflowStep
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Apr 10, 2020
1 parent ee20ff9 commit 49e46f9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
9 changes: 5 additions & 4 deletions src/main/scala/sbtghactions/GenerativePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ ${indent(rendered.mkString("\n"), 1)}"""
import WorkflowStep._

val renderedName = step.name.map(wrap).map("name: " + _ + "\n").getOrElse("")
val renderedId = step.id.map(wrap).map("id: " + _ + "\n").getOrElse("")
val renderedCond = step.cond.map(wrap).map("if: " + _ + "\n").getOrElse("")
val renderedShell = if (declareShell) "shell: bash\n" else ""

Expand All @@ -154,18 +155,18 @@ ${indent(rendered.mkString("\n"), 1)}"""
else
renderedEnvPre + "\n"

val preamblePre = renderedName + renderedCond + renderedEnv
val preamblePre = renderedName + renderedId + renderedCond + renderedEnv

val preamble = if (preamblePre.isEmpty)
""
else
preamblePre

val body = step match {
case Run(commands, _, _, _) =>
case Run(commands, _, _, _, _) =>
renderedShell + "run: " + wrap(commands.mkString("\n"))

case Sbt(commands, _, _, _) =>
case Sbt(commands, _, _, _, _) =>
val safeCommands = commands map { c =>
if (c.indexOf(' ') >= 0)
s"'$c'"
Expand All @@ -175,7 +176,7 @@ ${indent(rendered.mkString("\n"), 1)}"""

renderedShell + "run: " + wrap(s"$sbt ++$${{ matrix.scala }} ${safeCommands.mkString(" ")}")

case Use(owner, repo, version, params, _, _, _) =>
case Use(owner, repo, version, params, _, _, _, _) =>
val renderedParamsPre = compileEnv(params, prefix = "with")
val renderedParams = if (renderedParamsPre.isEmpty)
""
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/sbtghactions/WorkflowStep.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package sbtghactions

sealed trait WorkflowStep extends Product with Serializable {
def id: Option[String]
def name: Option[String]
def cond: Option[String]
def env: Map[String, String]
Expand All @@ -34,7 +35,7 @@ object WorkflowStep {
def ComputeVar(name: String, cmd: String): WorkflowStep =
Run(List(s"echo ::set-env name=$name::$$($cmd)"), name = Some(s"Export $name"))

final case class Run(commands: List[String], name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map()) extends WorkflowStep
final case class Sbt(commands: List[String], name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map()) extends WorkflowStep
final case class Use(owner: String, repo: String, version: Int, params: Map[String, String] = Map(), name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map()) extends WorkflowStep
final case class Run(commands: List[String], id: Option[String] = None, name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map()) extends WorkflowStep
final case class Sbt(commands: List[String], id: Option[String] = None, name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map()) extends WorkflowStep
final case class Use(owner: String, repo: String, version: Int, params: Map[String, String] = Map(), id: Option[String] = None, name: Option[String] = None, cond: Option[String] = None, env: Map[String, String] = Map()) extends WorkflowStep
}
4 changes: 4 additions & 0 deletions src/test/scala/sbtghactions/GenerativePluginSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ class GenerativePluginSpec extends Specification {
compileStep(Run(List("echo hi")), "") mustEqual "- run: echo hi"
}

"compile a simple run with an id" in {
compileStep(Run(List("echo hi"), id = Some("bippy")), "") mustEqual "- id: bippy\n run: echo hi"
}

"compile a simple run with a name" in {
compileStep(
Run(
Expand Down

0 comments on commit 49e46f9

Please sign in to comment.