Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support working-directory in WorkflowStep.Run #700

Merged
merged 1 commit into from
Apr 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading