Skip to content

Commit

Permalink
Merge pull request #700 from armanbilge/feature/run-working-directory
Browse files Browse the repository at this point in the history
Support `working-directory` in `WorkflowStep.Run`
  • Loading branch information
armanbilge authored Apr 20, 2024
2 parents 39b474c + b5a4bd1 commit 9371b95
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ jobs:
shell: bash
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- shell: bash
working-directory: project
run: pwd

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
shell: bash
Expand Down
5 changes: 5 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ ThisBuild / githubWorkflowBuildMatrixExclusions ++= {
ThisBuild / githubWorkflowPublishTimeoutMinutes := Some(45)
ThisBuild / githubWorkflowPublishNeeds += "validate-steward"

ThisBuild / githubWorkflowBuild += WorkflowStep.Run(
List("pwd"),
workingDirectory = Some("project")
)

ThisBuild / mergifyStewardConfig ~= {
_.map(_.withMergeMinors(true).withAuthor("typelevel-steward[bot]"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ ${indent(rendered.mkString("\n"), 1)}"""

val body = step match {
case run: Run =>
renderRunBody(run.commands, run.params, renderedShell)
val renderedWorkingDirectory =
run.workingDirectory.map(wrap).map("working-directory: " + _ + "\n").getOrElse("")
renderRunBody(run.commands, run.params, renderedShell, renderedWorkingDirectory)

case sbtStep: Sbt =>
import sbtStep.commands
Expand All @@ -309,7 +311,8 @@ ${indent(rendered.mkString("\n"), 1)}"""
renderRunBody(
commands = List(s"$sbt $safeCommands"),
params = sbtStep.params,
renderedShell = renderedShell
renderedShell = renderedShell,
renderedWorkingDirectory = ""
)

case use: Use =>
Expand Down Expand Up @@ -344,8 +347,10 @@ ${indent(rendered.mkString("\n"), 1)}"""
def renderRunBody(
commands: List[String],
params: Map[String, String],
renderedShell: String) =
renderedShell + "run: " + wrap(commands.mkString("\n")) + renderParams(params)
renderedShell: String,
renderedWorkingDirectory: String) =
renderedShell + renderedWorkingDirectory + "run: " + wrap(
commands.mkString("\n")) + renderParams(params)

def renderParams(params: Map[String, String]): String = {
val renderedParamsPre = compileEnv(params, prefix = "with")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ object WorkflowStep {
sealed abstract class Run extends WorkflowStep {
def commands: List[String]
def params: Map[String, String]
def workingDirectory: Option[String]
}

object Run {
Expand All @@ -127,8 +128,9 @@ object WorkflowStep {
cond: Option[String] = None,
env: Map[String, String] = Map(),
params: Map[String, String] = Map(),
timeoutMinutes: Option[Int] = None): Run =
Impl(commands, id, name, cond, env, params, timeoutMinutes)
timeoutMinutes: Option[Int] = None,
workingDirectory: Option[String] = None): Run =
Impl(commands, id, name, cond, env, params, timeoutMinutes, workingDirectory)

private final case class Impl(
commands: List[String],
Expand All @@ -137,7 +139,8 @@ object WorkflowStep {
cond: Option[String],
env: Map[String, String],
params: Map[String, String],
timeoutMinutes: Option[Int])
timeoutMinutes: Option[Int],
workingDirectory: Option[String])
extends Run {
override def productPrefix = "Run"
def withId(id: Option[String]) = copy(id = id)
Expand Down

0 comments on commit 9371b95

Please sign in to comment.