Skip to content

Add continueOnError option to WorkflowStep #811

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name := "sbt-typelevel"

import org.typelevel.sbt.gha.{PermissionScope, PermissionValue, Permissions}
import com.typesafe.tools.mima.core._

ThisBuild / tlBaseVersion := "0.7"
ThisBuild / crossScalaVersions := Seq("2.12.20")
Expand Down Expand Up @@ -121,7 +122,11 @@ lazy val githubActions = project
.in(file("github-actions"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-typelevel-github-actions"
name := "sbt-typelevel-github-actions",
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("org.typelevel.sbt.gha.*#*#Impl.*"),
ProblemFilters.exclude[MissingTypesProblem]("org.typelevel.sbt.gha.*$*$Impl$")
)
)

lazy val mergify = project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ ${indent(rendered.mkString("\n"), 1)}"""
val renderedId = step.id.map(wrap).map("id: " + _ + "\n").getOrElse("")
val renderedCond = step.cond.map(wrap).map("if: " + _ + "\n").getOrElse("")
val renderedShell = if (declareShell) "shell: bash\n" else ""
val renderedContinueOnError = if (step.continueOnError) "continue-on-error: true\n" else ""

val renderedEnvPre = compileEnv(step.env)
val renderedEnv =
Expand All @@ -288,7 +289,12 @@ ${indent(rendered.mkString("\n"), 1)}"""
case run: Run =>
val renderedWorkingDirectory =
run.workingDirectory.map(wrap).map("working-directory: " + _ + "\n").getOrElse("")
renderRunBody(run.commands, run.params, renderedShell, renderedWorkingDirectory)
renderRunBody(
run.commands,
run.params,
renderedShell,
renderedWorkingDirectory,
renderedContinueOnError)

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

case use: Use =>
Expand All @@ -338,18 +345,27 @@ ${indent(rendered.mkString("\n"), 1)}"""
s"uses: docker://$image:$tag"
}

decl + renderParams(params)
decl + renderedContinueOnError + renderParams(params)
}

indent(preamble + body, 1).updated(0, '-')
}

@deprecated("Use the apply method with renderedContinueOnError", since = "0.7.8")
def renderRunBody(
commands: List[String],
params: Map[String, String],
renderedShell: String,
renderedWorkingDirectory: String): String =
renderRunBody(commands, params, renderedShell, renderedWorkingDirectory, "")

def renderRunBody(
commands: List[String],
params: Map[String, String],
renderedShell: String,
renderedWorkingDirectory: String) =
renderedShell + renderedWorkingDirectory + "run: " + wrap(
renderedWorkingDirectory: String,
renderedContinueOnError: String): String =
renderedShell + renderedWorkingDirectory + renderedContinueOnError + "run: " + wrap(
commands.mkString("\n")) + renderParams(params)

def renderParams(params: Map[String, String]): String = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ sealed abstract class WorkflowStep extends Product with Serializable {
def cond: Option[String]
def env: Map[String, String]
def timeoutMinutes: Option[Int]
def continueOnError: Boolean

def withId(id: Option[String]): WorkflowStep
def withName(name: Option[String]): WorkflowStep
def withCond(cond: Option[String]): WorkflowStep
def withEnv(env: Map[String, String]): WorkflowStep
def withTimeoutMinutes(minutes: Option[Int]): WorkflowStep
def withContinueOnError(continueOnError: Boolean): WorkflowStep

def updatedEnv(name: String, value: String): WorkflowStep
def concatEnv(env: TraversableOnce[(String, String)]): WorkflowStep
Expand Down Expand Up @@ -136,6 +138,28 @@ object WorkflowStep {
}

object Run {
@deprecated("Use the apply method with continueOnError", since = "0.7.8")
def apply(
commands: List[String],
id: Option[String],
name: Option[String],
cond: Option[String],
env: Map[String, String],
params: Map[String, String],
timeoutMinutes: Option[Int],
workingDirectory: Option[String]
): Run = apply(
commands,
id,
name,
cond,
env,
params,
timeoutMinutes,
workingDirectory,
continueOnError = false
)

def apply(
commands: List[String],
id: Option[String] = None,
Expand All @@ -144,8 +168,18 @@ object WorkflowStep {
env: Map[String, String] = Map(),
params: Map[String, String] = Map(),
timeoutMinutes: Option[Int] = None,
workingDirectory: Option[String] = None): Run =
Impl(commands, id, name, cond, env, params, timeoutMinutes, workingDirectory)
workingDirectory: Option[String] = None,
continueOnError: Boolean = false): Run =
Comment on lines 170 to +172
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here: unfortunately, adding a default parameter (= false) will not fix bincompat. However, adding a deprecated overload with the old signature, that passes continueOnError = false to the new overload will work.

Impl(
commands,
id,
name,
cond,
env,
params,
timeoutMinutes,
workingDirectory,
continueOnError)

private final case class Impl(
commands: List[String],
Expand All @@ -155,7 +189,8 @@ object WorkflowStep {
env: Map[String, String],
params: Map[String, String],
timeoutMinutes: Option[Int],
workingDirectory: Option[String])
workingDirectory: Option[String],
continueOnError: Boolean)
extends Run {
override def productPrefix = "Run"
// scalafmt: { maxColumn = 200 }
Expand All @@ -164,6 +199,7 @@ object WorkflowStep {
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 withContinueOnError(continueOnError: Boolean) = copy(continueOnError = continueOnError)

def withCommands(commands: List[String]) = copy(commands = commands)
def withParams(params: Map[String, String]) = copy(params = params)
Expand Down Expand Up @@ -193,6 +229,19 @@ object WorkflowStep {
}

object Sbt {

@deprecated("Use the apply method with continueOnError", since = "0.7.8")
def apply(
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): Sbt =
apply(commands, id, name, cond, env, params, timeoutMinutes, preamble, false)

def apply(
commands: List[String],
id: Option[String] = None,
Expand All @@ -201,8 +250,9 @@ object WorkflowStep {
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)
preamble: Boolean = true,
continueOnError: Boolean = false): Sbt =
Impl(commands, id, name, cond, env, params, timeoutMinutes, preamble, continueOnError)

private final case class Impl(
commands: List[String],
Expand All @@ -212,7 +262,8 @@ object WorkflowStep {
env: Map[String, String],
params: Map[String, String],
timeoutMinutes: Option[Int],
preamble: Boolean)
preamble: Boolean,
continueOnError: Boolean)
extends Sbt {
override def productPrefix = "Sbt"
// scalafmt: { maxColumn = 200 }
Expand All @@ -221,6 +272,7 @@ object WorkflowStep {
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 withContinueOnError(continueOnError: Boolean): WorkflowStep = copy(continueOnError = continueOnError)

def withCommands(commands: List[String]) = copy(commands = commands)
def withParams(params: Map[String, String]) = copy(params = params)
Expand Down Expand Up @@ -249,15 +301,37 @@ object WorkflowStep {

object Use {

@deprecated("Use the apply method with continueOnError", since = "0.7.8")
def apply(
ref: UseRef,
params: Map[String, String],
id: Option[String],
name: Option[String],
cond: Option[String],
env: Map[String, String],
timeoutMinutes: Option[Int]
): Use =
apply(
ref,
params,
id,
name,
cond,
env,
timeoutMinutes,
continueOnError = false
)

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)
timeoutMinutes: Option[Int] = None,
continueOnError: Boolean = false): Use =
Impl(ref, params, id, name, cond, env, timeoutMinutes, continueOnError)

private final case class Impl(
ref: UseRef,
Expand All @@ -266,7 +340,8 @@ object WorkflowStep {
name: Option[String],
cond: Option[String],
env: Map[String, String],
timeoutMinutes: Option[Int])
timeoutMinutes: Option[Int],
continueOnError: Boolean)
extends Use {
override def productPrefix = "Use"
// scalafmt: { maxColumn = 200 }
Expand All @@ -275,6 +350,7 @@ object WorkflowStep {
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 withContinueOnError(continueOnError: Boolean) = copy(continueOnError = continueOnError)

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