From 7ad0b5b5c54a2c821c2cc475fd31d85378c6f6d7 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 18 Apr 2024 15:53:20 +0000 Subject: [PATCH] De-case-classify `WorkflowStep` --- .../org/typelevel/sbt/CrossRootProject.scala | 4 +- .../org/typelevel/sbt/gha/WorkflowStep.scala | 142 ++++++++++++------ 2 files changed, 101 insertions(+), 45 deletions(-) diff --git a/ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala b/ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala index b4bae862..2a5d4eb2 100644 --- a/ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala +++ b/ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala @@ -194,7 +194,7 @@ object TypelevelCiJSPlugin extends AutoPlugin with RootProjectId { }, githubWorkflowBuild := { githubWorkflowBuild.value.flatMap { - case testStep @ WorkflowStep.Sbt(List("test"), _, _, _, _, _, _, _) => + case testStep: WorkflowStep.Sbt if testStep.commands == List("test") => val fastOptStep = WorkflowStep.Sbt( List("Test/scalaJSLinkerResult"), name = Some("scalaJSLink"), @@ -226,7 +226,7 @@ object TypelevelCiNativePlugin extends AutoPlugin with RootProjectId { }, githubWorkflowBuild := { githubWorkflowBuild.value.flatMap { - case testStep @ WorkflowStep.Sbt(List("test"), _, _, _, _, _, _, _) => + case testStep: WorkflowStep.Sbt if testStep.commands == List("test") => val nativeLinkStep = WorkflowStep.Sbt( List("Test/nativeLink"), name = Some("nativeLink"), diff --git a/github-actions/src/main/scala/org/typelevel/sbt/gha/WorkflowStep.scala b/github-actions/src/main/scala/org/typelevel/sbt/gha/WorkflowStep.scala index d884de67..35f82e69 100644 --- a/github-actions/src/main/scala/org/typelevel/sbt/gha/WorkflowStep.scala +++ b/github-actions/src/main/scala/org/typelevel/sbt/gha/WorkflowStep.scala @@ -114,52 +114,108 @@ object WorkflowStep { List("echo \"$(" + cmd + ")\" >> $GITHUB_PATH"), name = Some(s"Prepend $$PATH using $cmd")) - final case class Run( - commands: List[String], - id: Option[String] = None, - name: Option[String] = None, - cond: Option[String] = None, - env: Map[String, String] = Map(), - params: Map[String, String] = Map(), - timeoutMinutes: Option[Int] = None) - extends WorkflowStep { - def withId(id: Option[String]) = copy(id = id) - def withName(name: Option[String]) = copy(name = name) - def withCond(cond: Option[String]) = copy(cond = cond) - def withEnv(env: Map[String, String]) = copy(env = env) - def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes) + sealed abstract class Run extends WorkflowStep { + def commands: List[String] + def params: Map[String, String] } - final case class Sbt( - commands: List[String], - id: Option[String] = None, - name: Option[String] = None, - cond: Option[String] = None, - env: Map[String, String] = Map(), - params: Map[String, String] = Map(), - timeoutMinutes: Option[Int] = None, - preamble: Boolean = true) - extends WorkflowStep { - def withId(id: Option[String]) = copy(id = id) - def withName(name: Option[String]) = copy(name = name) - def withCond(cond: Option[String]) = copy(cond = cond) - def withEnv(env: Map[String, String]) = copy(env = env) - def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes) + object Run { + def apply( + commands: List[String], + id: Option[String] = None, + name: Option[String] = None, + 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) + + private final case class Impl( + commands: List[String], + id: Option[String], + name: Option[String], + cond: Option[String], + env: Map[String, String], + params: Map[String, String], + timeoutMinutes: Option[Int]) + extends Run { + def withId(id: Option[String]) = copy(id = id) + def withName(name: Option[String]) = copy(name = name) + def withCond(cond: Option[String]) = copy(cond = cond) + def withEnv(env: Map[String, String]) = copy(env = env) + def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes) + } + } + + sealed abstract class Sbt extends WorkflowStep { + def commands: List[String] + def params: Map[String, String] + def preamble: Boolean } - final case class Use( - ref: UseRef, - params: Map[String, String] = Map(), - id: Option[String] = None, - name: Option[String] = None, - cond: Option[String] = None, - env: Map[String, String] = Map(), - timeoutMinutes: Option[Int] = None) - extends WorkflowStep { - def withId(id: Option[String]) = copy(id = id) - def withName(name: Option[String]) = copy(name = name) - def withCond(cond: Option[String]) = copy(cond = cond) - def withEnv(env: Map[String, String]) = copy(env = env) - def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes) + object Sbt { + def apply( + commands: List[String], + id: Option[String] = None, + name: Option[String] = None, + cond: Option[String] = None, + env: Map[String, String] = Map(), + params: Map[String, String] = Map(), + timeoutMinutes: Option[Int] = None, + preamble: Boolean = true): Sbt = + Impl(commands, id, name, cond, env, params, timeoutMinutes, preamble) + + private final case class Impl( + commands: List[String], + id: Option[String], + name: Option[String], + cond: Option[String], + env: Map[String, String], + params: Map[String, String], + timeoutMinutes: Option[Int], + preamble: Boolean) + extends Sbt { + override def productPrefix = "Sbt" + def withId(id: Option[String]) = copy(id = id) + def withName(name: Option[String]) = copy(name = name) + def withCond(cond: Option[String]) = copy(cond = cond) + def withEnv(env: Map[String, String]) = copy(env = env) + def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes) + } + } + + sealed abstract class Use extends WorkflowStep { + def ref: UseRef + def params: Map[String, String] + } + + object Use { + + def apply( + ref: UseRef, + params: Map[String, String] = Map(), + id: Option[String] = None, + name: Option[String] = None, + cond: Option[String] = None, + env: Map[String, String] = Map(), + timeoutMinutes: Option[Int] = None): Use = + Impl(ref, params, id, name, cond, env, timeoutMinutes) + + private final case class Impl( + ref: UseRef, + params: Map[String, String], + id: Option[String], + name: Option[String], + cond: Option[String], + env: Map[String, String], + timeoutMinutes: Option[Int]) + extends Use { + override def productPrefix = "Use" + def withId(id: Option[String]) = copy(id = id) + def withName(name: Option[String]) = copy(name = name) + def withCond(cond: Option[String]) = copy(cond = cond) + def withEnv(env: Map[String, String]) = copy(env = env) + def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes) + } } }