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

Add more with*, update*, and add* for Workflow step and jobs. #732

Merged
merged 7 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 14 additions & 20 deletions github-actions/mima.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
import com.typesafe.tools.mima.core._
mimaBinaryIssueFilters ++= Seq(
"org.typelevel.sbt.gha.WorkflowJob.withId",
"org.typelevel.sbt.gha.WorkflowJob.withName",
"org.typelevel.sbt.gha.WorkflowJob.withSteps",
"org.typelevel.sbt.gha.WorkflowJob.withSbtStepPreamble",
"org.typelevel.sbt.gha.WorkflowJob.withCond",
"org.typelevel.sbt.gha.WorkflowJob.withPermissions",
"org.typelevel.sbt.gha.WorkflowJob.withEnv",
"org.typelevel.sbt.gha.WorkflowJob.withOses",
"org.typelevel.sbt.gha.WorkflowJob.withScalas",
"org.typelevel.sbt.gha.WorkflowJob.withJavas",
"org.typelevel.sbt.gha.WorkflowJob.withNeeds",
"org.typelevel.sbt.gha.WorkflowJob.withMatrixFailFast",
"org.typelevel.sbt.gha.WorkflowJob.withMatrixAdds",
"org.typelevel.sbt.gha.WorkflowJob.withMatrixIncs",
"org.typelevel.sbt.gha.WorkflowJob.withMatrixExcs",
"org.typelevel.sbt.gha.WorkflowJob.withRunsOnExtraLabels",
"org.typelevel.sbt.gha.WorkflowJob.withContainer",
"org.typelevel.sbt.gha.WorkflowJob.withEnvironment",
"org.typelevel.sbt.gha.WorkflowJob.withConcurrency",
"org.typelevel.sbt.gha.WorkflowJob.withTimeoutMinutes"
"org.typelevel.sbt.gha.WorkflowJob.with*",
"org.typelevel.sbt.gha.WorkflowJob.append*",
"org.typelevel.sbt.gha.WorkflowJob.update*",
"org.typelevel.sbt.gha.WorkflowStep.update*",
"org.typelevel.sbt.gha.WorkflowStep.add*",
"org.typelevel.sbt.gha.WorkflowStep#Sbt.with*",
"org.typelevel.sbt.gha.WorkflowStep#Sbt.add*",
"org.typelevel.sbt.gha.WorkflowStep#Sbt.update*",
"org.typelevel.sbt.gha.WorkflowStep#Run.with*",
"org.typelevel.sbt.gha.WorkflowStep#Run.add*",
"org.typelevel.sbt.gha.WorkflowStep#Run.update*",
"org.typelevel.sbt.gha.WorkflowStep#Use.with*",
"org.typelevel.sbt.gha.WorkflowStep#Use.add*",
"org.typelevel.sbt.gha.WorkflowStep#Use.update*"
zarthross marked this conversation as resolved.
Show resolved Hide resolved
).map(ProblemFilters.exclude[ReversedMissingMethodProblem](_))
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ sealed abstract class WorkflowJob {
def withEnvironment(environment: Option[JobEnvironment]): WorkflowJob
def withConcurrency(concurrency: Option[Concurrency]): WorkflowJob
def withTimeoutMinutes(timeoutMinutes: Option[Int]): WorkflowJob

def updateEnv(name: String, value: String): WorkflowJob
def appendSteps(steps: List[WorkflowStep]): WorkflowJob
}

object WorkflowJob {
Expand Down Expand Up @@ -149,6 +152,9 @@ object WorkflowJob {
override def withEnvironment(environment: Option[JobEnvironment]): WorkflowJob = copy(environment = environment)
override def withConcurrency(concurrency: Option[Concurrency]): WorkflowJob = copy(concurrency = concurrency)
override def withTimeoutMinutes(timeoutMinutes: Option[Int]): WorkflowJob = copy(timeoutMinutes = timeoutMinutes)

def updateEnv(name: String, value: String): WorkflowJob = withEnv(env.updated(name, value))
def appendSteps(steps: List[WorkflowStep]): WorkflowJob = withSteps(this.steps ++ steps)
Copy link
Member

@armanbilge armanbilge Aug 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method name append is inconsistent (in both name and signature) with appended. https://www.scala-lang.org/api/current/scala/collection/immutable/List.html#appended-957

(Although it looks like the 2.12 standard library doesn't have named aliases for these methods.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed append to appended and made it take a single step. Added concatStep with a TraversableOnce for added flexibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also changed add* to concat* for consistency.

// scalafmt: { maxColumn = 96 }

override def productPrefix = "WorkflowJob"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ sealed abstract class WorkflowStep extends Product with Serializable {
def withCond(cond: Option[String]): WorkflowStep
def withEnv(env: Map[String, String]): WorkflowStep
def withTimeoutMinutes(minutes: Option[Int]): WorkflowStep

def updateEnv(name: String, value: String): WorkflowStep
def addEnv(env: Map[String, String]): WorkflowStep
}

object WorkflowStep {
Expand Down Expand Up @@ -118,6 +121,15 @@ object WorkflowStep {
def commands: List[String]
def params: Map[String, String]
def workingDirectory: Option[String]

def withCommands(commands: List[String]): Run
def withParams(params: Map[String, String]): Run
def withWorkingDirectory(workingDirectory: Option[String]): Run

def updateEnv(name: String, value: String): Run
def addEnv(env: Map[String, String]): Run
def updateParams(name: String, value: String): Run
def addParams(params: Map[String, String]): Run
}

object Run {
Expand All @@ -143,18 +155,38 @@ object WorkflowStep {
workingDirectory: Option[String])
extends Run {
override def productPrefix = "Run"
// scalafmt: { maxColumn = 200 }
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)

def withCommands(commands: List[String]) = copy(commands = commands)
def withParams(params: Map[String, String]) = copy(params = params)
def withWorkingDirectory(workingDirectory: Option[String]) = copy(workingDirectory = workingDirectory)

def updateEnv(name: String, value: String) = copy(env = this.env.updated(name, value))
def addEnv(env: Map[String, String]) = copy(env = this.env ++ env)
def updateParams(name: String, value: String) = copy(params = this.params.updated(name, value))
def addParams(params: Map[String, String]) = copy(params = this.params ++ params)
// scalafmt: { maxColumn = 96 }
}
}

sealed abstract class Sbt extends WorkflowStep {
def commands: List[String]
def params: Map[String, String]
def preamble: Boolean

def withCommands(commands: List[String]): Sbt
def withParams(params: Map[String, String]): Sbt
def withPreamble(preamble: Boolean): Sbt

def updateEnv(name: String, value: String): Sbt
def addEnv(env: Map[String, String]): Sbt
def updateParams(name: String, value: String): Sbt
def addParams(params: Map[String, String]): Sbt
}

object Sbt {
Expand All @@ -180,17 +212,36 @@ object WorkflowStep {
preamble: Boolean)
extends Sbt {
override def productPrefix = "Sbt"
// scalafmt: { maxColumn = 200 }
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)

def withCommands(commands: List[String]) = copy(commands = commands)
def withParams(params: Map[String, String]) = copy(params = params)
def withPreamble(preamble: Boolean) = copy(preamble = preamble)

def updateEnv(name: String, value: String) = copy(env = this.env.updated(name, value))
def addEnv(env: Map[String, String]) = copy(env = this.env ++ env)
def updateParams(name: String, value: String) = copy(params = params.updated(name, value))
def addParams(params: Map[String, String]) = copy(params = this.params ++ params)
// scalafmt: { maxColumn = 96 }
}
}

sealed abstract class Use extends WorkflowStep {
def ref: UseRef
def params: Map[String, String]

def withRef(ref: UseRef): Use
def withParams(params: Map[String, String]): Use

def updateEnv(name: String, value: String): Use
def addEnv(env: Map[String, String]): Use
def updateParams(name: String, value: String): Use
def addParams(params: Map[String, String]): Use
}

object Use {
Expand All @@ -215,11 +266,21 @@ object WorkflowStep {
timeoutMinutes: Option[Int])
extends Use {
override def productPrefix = "Use"
// scalafmt: { maxColumn = 200 }
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)

def withRef(ref: UseRef) = copy(ref = ref)
def withParams(params: Map[String, String]) = copy(params = params)

def updateEnv(name: String, value: String) = copy(env = this.env.updated(name, value))
def addEnv(env: Map[String, String]) = copy(env = this.env ++ env)
def updateParams(name: String, value: String) = copy(params = params.updated(name, value))
def addParams(params: Map[String, String]) = copy(params = this.params ++ params)
// scalafmt: { maxColumn = 96 }
}
}
}
Loading