Skip to content

Commit ad24943

Browse files
authored
Merge pull request #811 from hugo-vrijswijk/continue-on-error
Add `continueOnError` option to `WorkflowStep`
2 parents e6266cc + 4220749 commit ad24943

File tree

4 files changed

+125
-18
lines changed

4 files changed

+125
-18
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ jobs:
223223
working-directory: project
224224
run: pwd
225225

226+
- shell: bash
227+
continue-on-error: true
228+
run: exit 1
229+
226230
- name: Make target directories
227231
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
228232
shell: bash

build.sbt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name := "sbt-typelevel"
22

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

56
ThisBuild / tlBaseVersion := "0.8"
67
ThisBuild / crossScalaVersions := Seq("2.12.20")
@@ -41,9 +42,15 @@ ThisBuild / githubWorkflowBuildMatrixExclusions ++= {
4142
ThisBuild / githubWorkflowPublishTimeoutMinutes := Some(45)
4243
ThisBuild / githubWorkflowPublishNeeds += "validate-steward"
4344

44-
ThisBuild / githubWorkflowBuild += WorkflowStep.Run(
45-
List("pwd"),
46-
workingDirectory = Some("project")
45+
ThisBuild / githubWorkflowBuild ++= Seq(
46+
WorkflowStep.Run(
47+
List("pwd"),
48+
workingDirectory = Some("project")
49+
),
50+
WorkflowStep.Run(
51+
List("exit 1"),
52+
continueOnError = true
53+
)
4754
)
4855

4956
ThisBuild / mergifyStewardConfig ~= {
@@ -121,7 +128,11 @@ lazy val githubActions = project
121128
.in(file("github-actions"))
122129
.enablePlugins(SbtPlugin)
123130
.settings(
124-
name := "sbt-typelevel-github-actions"
131+
name := "sbt-typelevel-github-actions",
132+
mimaBinaryIssueFilters ++= Seq(
133+
ProblemFilters.exclude[DirectMissingMethodProblem]("org.typelevel.sbt.gha.*#*#Impl.*"),
134+
ProblemFilters.exclude[MissingTypesProblem]("org.typelevel.sbt.gha.*$*$Impl$")
135+
)
125136
)
126137

127138
lazy val mergify = project

github-actions/src/main/scala/org/typelevel/sbt/gha/GenerativePlugin.scala

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ ${indent(rendered.mkString("\n"), 1)}"""
264264
val renderedId = step.id.map(wrap).map("id: " + _ + "\n").getOrElse("")
265265
val renderedCond = step.cond.map(wrap).map("if: " + _ + "\n").getOrElse("")
266266
val renderedShell = if (declareShell) "shell: bash\n" else ""
267+
val renderedContinueOnError = if (step.continueOnError) "continue-on-error: true\n" else ""
267268

268269
val renderedEnvPre = compileEnv(step.env)
269270
val renderedEnv =
@@ -288,7 +289,12 @@ ${indent(rendered.mkString("\n"), 1)}"""
288289
case run: Run =>
289290
val renderedWorkingDirectory =
290291
run.workingDirectory.map(wrap).map("working-directory: " + _ + "\n").getOrElse("")
291-
renderRunBody(run.commands, run.params, renderedShell, renderedWorkingDirectory)
292+
renderRunBody(
293+
run.commands,
294+
run.params,
295+
renderedShell,
296+
renderedWorkingDirectory,
297+
renderedContinueOnError)
292298

293299
case sbtStep: Sbt =>
294300
import sbtStep.commands
@@ -312,7 +318,8 @@ ${indent(rendered.mkString("\n"), 1)}"""
312318
commands = List(s"$sbt $safeCommands"),
313319
params = sbtStep.params,
314320
renderedShell = renderedShell,
315-
renderedWorkingDirectory = ""
321+
renderedWorkingDirectory = "",
322+
renderedContinueOnError = renderedContinueOnError
316323
)
317324

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

341-
decl + renderParams(params)
348+
decl + renderedContinueOnError + renderParams(params)
342349
}
343350

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

354+
@deprecated("Use the overload with renderedContinueOnError", since = "0.8.1")
355+
def renderRunBody(
356+
commands: List[String],
357+
params: Map[String, String],
358+
renderedShell: String,
359+
renderedWorkingDirectory: String): String =
360+
renderRunBody(commands, params, renderedShell, renderedWorkingDirectory, "")
361+
347362
def renderRunBody(
348363
commands: List[String],
349364
params: Map[String, String],
350365
renderedShell: String,
351-
renderedWorkingDirectory: String) =
352-
renderedShell + renderedWorkingDirectory + "run: " + wrap(
366+
renderedWorkingDirectory: String,
367+
renderedContinueOnError: String): String =
368+
renderedShell + renderedWorkingDirectory + renderedContinueOnError + "run: " + wrap(
353369
commands.mkString("\n")) + renderParams(params)
354370

355371
def renderParams(params: Map[String, String]): String = {

github-actions/src/main/scala/org/typelevel/sbt/gha/WorkflowStep.scala

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ sealed abstract class WorkflowStep extends Product with Serializable {
2222
def cond: Option[String]
2323
def env: Map[String, String]
2424
def timeoutMinutes: Option[Int]
25+
def continueOnError: Boolean
2526

2627
def withId(id: Option[String]): WorkflowStep
2728
def withName(name: Option[String]): WorkflowStep
2829
def withCond(cond: Option[String]): WorkflowStep
2930
def withEnv(env: Map[String, String]): WorkflowStep
3031
def withTimeoutMinutes(minutes: Option[Int]): WorkflowStep
32+
def withContinueOnError(continueOnError: Boolean): WorkflowStep
3133

3234
def updatedEnv(name: String, value: String): WorkflowStep
3335
def concatEnv(env: TraversableOnce[(String, String)]): WorkflowStep
@@ -136,6 +138,28 @@ object WorkflowStep {
136138
}
137139

138140
object Run {
141+
@deprecated("Use the apply method with continueOnError", since = "0.8.1")
142+
def apply(
143+
commands: List[String],
144+
id: Option[String],
145+
name: Option[String],
146+
cond: Option[String],
147+
env: Map[String, String],
148+
params: Map[String, String],
149+
timeoutMinutes: Option[Int],
150+
workingDirectory: Option[String]
151+
): Run = apply(
152+
commands,
153+
id,
154+
name,
155+
cond,
156+
env,
157+
params,
158+
timeoutMinutes,
159+
workingDirectory,
160+
continueOnError = false
161+
)
162+
139163
def apply(
140164
commands: List[String],
141165
id: Option[String] = None,
@@ -144,8 +168,18 @@ object WorkflowStep {
144168
env: Map[String, String] = Map(),
145169
params: Map[String, String] = Map(),
146170
timeoutMinutes: Option[Int] = None,
147-
workingDirectory: Option[String] = None): Run =
148-
Impl(commands, id, name, cond, env, params, timeoutMinutes, workingDirectory)
171+
workingDirectory: Option[String] = None,
172+
continueOnError: Boolean = false): Run =
173+
Impl(
174+
commands,
175+
id,
176+
name,
177+
cond,
178+
env,
179+
params,
180+
timeoutMinutes,
181+
workingDirectory,
182+
continueOnError)
149183

150184
private final case class Impl(
151185
commands: List[String],
@@ -155,7 +189,8 @@ object WorkflowStep {
155189
env: Map[String, String],
156190
params: Map[String, String],
157191
timeoutMinutes: Option[Int],
158-
workingDirectory: Option[String])
192+
workingDirectory: Option[String],
193+
continueOnError: Boolean)
159194
extends Run {
160195
override def productPrefix = "Run"
161196
// scalafmt: { maxColumn = 200 }
@@ -164,6 +199,7 @@ object WorkflowStep {
164199
def withCond(cond: Option[String]) = copy(cond = cond)
165200
def withEnv(env: Map[String, String]) = copy(env = env)
166201
def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes)
202+
def withContinueOnError(continueOnError: Boolean) = copy(continueOnError = continueOnError)
167203

168204
def withCommands(commands: List[String]) = copy(commands = commands)
169205
def withParams(params: Map[String, String]) = copy(params = params)
@@ -193,6 +229,19 @@ object WorkflowStep {
193229
}
194230

195231
object Sbt {
232+
233+
@deprecated("Use the apply method with continueOnError", since = "0.8.1")
234+
def apply(
235+
commands: List[String],
236+
id: Option[String],
237+
name: Option[String],
238+
cond: Option[String],
239+
env: Map[String, String],
240+
params: Map[String, String],
241+
timeoutMinutes: Option[Int],
242+
preamble: Boolean): Sbt =
243+
apply(commands, id, name, cond, env, params, timeoutMinutes, preamble, false)
244+
196245
def apply(
197246
commands: List[String],
198247
id: Option[String] = None,
@@ -201,8 +250,9 @@ object WorkflowStep {
201250
env: Map[String, String] = Map(),
202251
params: Map[String, String] = Map(),
203252
timeoutMinutes: Option[Int] = None,
204-
preamble: Boolean = true): Sbt =
205-
Impl(commands, id, name, cond, env, params, timeoutMinutes, preamble)
253+
preamble: Boolean = true,
254+
continueOnError: Boolean = false): Sbt =
255+
Impl(commands, id, name, cond, env, params, timeoutMinutes, preamble, continueOnError)
206256

207257
private final case class Impl(
208258
commands: List[String],
@@ -212,7 +262,8 @@ object WorkflowStep {
212262
env: Map[String, String],
213263
params: Map[String, String],
214264
timeoutMinutes: Option[Int],
215-
preamble: Boolean)
265+
preamble: Boolean,
266+
continueOnError: Boolean)
216267
extends Sbt {
217268
override def productPrefix = "Sbt"
218269
// scalafmt: { maxColumn = 200 }
@@ -221,6 +272,7 @@ object WorkflowStep {
221272
def withCond(cond: Option[String]) = copy(cond = cond)
222273
def withEnv(env: Map[String, String]) = copy(env = env)
223274
def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes)
275+
def withContinueOnError(continueOnError: Boolean): WorkflowStep = copy(continueOnError = continueOnError)
224276

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

250302
object Use {
251303

304+
@deprecated("Use the apply method with continueOnError", since = "0.8.1")
305+
def apply(
306+
ref: UseRef,
307+
params: Map[String, String],
308+
id: Option[String],
309+
name: Option[String],
310+
cond: Option[String],
311+
env: Map[String, String],
312+
timeoutMinutes: Option[Int]
313+
): Use =
314+
apply(
315+
ref,
316+
params,
317+
id,
318+
name,
319+
cond,
320+
env,
321+
timeoutMinutes,
322+
continueOnError = false
323+
)
324+
252325
def apply(
253326
ref: UseRef,
254327
params: Map[String, String] = Map(),
255328
id: Option[String] = None,
256329
name: Option[String] = None,
257330
cond: Option[String] = None,
258331
env: Map[String, String] = Map(),
259-
timeoutMinutes: Option[Int] = None): Use =
260-
Impl(ref, params, id, name, cond, env, timeoutMinutes)
332+
timeoutMinutes: Option[Int] = None,
333+
continueOnError: Boolean = false): Use =
334+
Impl(ref, params, id, name, cond, env, timeoutMinutes, continueOnError)
261335

262336
private final case class Impl(
263337
ref: UseRef,
@@ -266,7 +340,8 @@ object WorkflowStep {
266340
name: Option[String],
267341
cond: Option[String],
268342
env: Map[String, String],
269-
timeoutMinutes: Option[Int])
343+
timeoutMinutes: Option[Int],
344+
continueOnError: Boolean)
270345
extends Use {
271346
override def productPrefix = "Use"
272347
// scalafmt: { maxColumn = 200 }
@@ -275,6 +350,7 @@ object WorkflowStep {
275350
def withCond(cond: Option[String]) = copy(cond = cond)
276351
def withEnv(env: Map[String, String]) = copy(env = env)
277352
def withTimeoutMinutes(minutes: Option[Int]) = copy(timeoutMinutes = minutes)
353+
def withContinueOnError(continueOnError: Boolean) = copy(continueOnError = continueOnError)
278354

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

0 commit comments

Comments
 (0)