Skip to content

Commit d7d764f

Browse files
committed
Cleanup render of types and steps
1 parent a7b98af commit d7d764f

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativePlugin.scala

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,9 @@ object GenerativePlugin extends AutoPlugin {
115115
def renderBranches(branches: List[String]) =
116116
if (branches.size == 0) ""
117117
else s"branches: [${branches.map(wrap).mkString(", ")}]"
118-
def renderTypesPre(prEventTypes: List[PREventType]) =
119-
prEventTypes.map(compilePREventType).mkString("[", ", ", "]")
120118
def renderTypes(prEventTypes: List[PREventType]) =
121119
if (prEventTypes.sortBy(_.toString) == PREventType.Defaults) ""
122-
else "\n" + indent("types: " + renderTypesPre(prEventTypes), 2)
120+
else "\ntypes: " + prEventTypes.map(compilePREventType).mkString("[", ", ", "]")
123121

124122
def renderTags(tags: List[String]) = {
125123
if (tags.isEmpty) ""
@@ -619,14 +617,20 @@ object GenerativePlugin extends AutoPlugin {
619617

620618
val renderedFailFast = job.matrixFailFast.fold("")("\n fail-fast: " + _)
621619

620+
val renderedSteps = indent(
621+
job
622+
.steps
623+
.map(compileStep(_, sbt, job.sbtStepPreamble, declareShell = declareShell))
624+
.mkString("\n\n"),
625+
1)
622626
// format: off
623627
val body = s"""name: ${wrap(job.name)}${renderedNeeds}${renderedCond}
624628
|strategy:${renderedFailFast}
625629
| matrix:
626630
|${buildMatrix(2, "os" -> job.oses, "scala" -> job.scalas, "java" -> job.javas.map(_.render))}${renderedMatrices}
627631
|runs-on: ${runsOn}${renderedEnvironment}${renderedContainer}${renderedPerm}${renderedEnv}${renderedOutputs}${renderedConcurrency}${renderedTimeoutMinutes}
628632
|steps:
629-
|${indent(job.steps.map(compileStep(_, sbt, job.sbtStepPreamble, declareShell = declareShell)).mkString("\n\n"), 1)}""".stripMargin
633+
|${renderedSteps}""".stripMargin
630634
// format: on
631635

632636
s"${job.id}:\n${indent(body, 1)}"
@@ -695,21 +699,21 @@ object GenerativePlugin extends AutoPlugin {
695699

696700
val renderedOn = compileOn(on)
697701

698-
s"""# This file was automatically generated by sbt-github-actions using the
699-
# githubWorkflowGenerate task. You should add and commit this file to
700-
# your git repository. It goes without saying that you shouldn't edit
701-
# this file by hand! Instead, if you wish to make changes, you should
702-
# change your sbt build configuration to revise the workflow description
703-
# to meet your needs, then regenerate this file.
704-
705-
${renderedName}
706-
707-
${renderedOn}
708-
709-
${renderedPerm}${renderedEnv}${renderedConcurrency}jobs:
710-
${indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)}
711-
"""
702+
val renderedJobs = "jobs:\n" + indent(jobs.map(compileJob(_, sbt)).mkString("\n\n"), 1)
712703

704+
s"""# This file was automatically generated by sbt-github-actions using the
705+
|# githubWorkflowGenerate task. You should add and commit this file to
706+
|# your git repository. It goes without saying that you shouldn't edit
707+
|# this file by hand! Instead, if you wish to make changes, you should
708+
|# change your sbt build configuration to revise the workflow description
709+
|# to meet your needs, then regenerate this file.
710+
|
711+
|${renderedName}
712+
|
713+
|${renderedOn}
714+
|
715+
|${renderedPerm}${renderedEnv}${renderedConcurrency}${renderedJobs}
716+
|""".stripMargin
713717
}
714718

715719
val settingDefaults = Seq(

0 commit comments

Comments
 (0)