Skip to content

Commit 85a5884

Browse files
authored
[pkl.impl.ghactions] Add helper to not skip dependent jobs with skipped ancestors (#36)
1 parent 95a4168 commit 85a5884

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/pkl.impl.ghactions/PklCI.pkl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import "@gha/Context.pkl"
2020
import "@gha/Workflow.pkl"
2121

2222
import "actions/PublishUnitTestResult.pkl"
23+
import "helpers.pkl"
2324
import "util.pkl"
2425

2526
/// The workflow that runs during pull requests.
@@ -396,6 +397,7 @@ local withPublishTestResultsForMultipleJobs: Mixin<Workflow.Jobs> = (it) -> (it)
396397
}
397398
["publish-test-results"] {
398399
needs = it.keys.filter((key) -> testReports.includes(key)).toListing()
400+
`if` = helpers.ifNoUpstreamFailures
399401
`runs-on` = "ubuntu-latest"
400402
permissions {
401403
checks = "write"
@@ -465,6 +467,8 @@ local function withTriggerWorkflows(triggerType: String): Mixin<Workflow.Jobs> =
465467
}
466468
`runs-on` = "ubuntu-latest"
467469
`if` = "github.repository_owner == 'apple'"
470+
// NOTE: not using helpers.ifNoUpstreamFailures here because nothing should be skipped
471+
// for release, releaseBranch, or main workflows
468472
steps {
469473
new {
470474
name = "Create app token"

packages/pkl.impl.ghactions/helpers.pkl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,19 @@ const withMavenPublishSecrets: Mixin<Workflow.Step> = new {
2727
["ORG_GRADLE_PROJECT_sonatypeUsername"] = Context.secrets("ORG_GRADLE_PROJECT_SONATYPEUSERNAME")
2828
}
2929
}
30+
31+
/// Use this for an `if` condition on jobs that "fan in" from multiple ancestors when one or more of
32+
/// those ancestors runs conditionally.
33+
///
34+
/// The four job states in GHA are:
35+
/// * success - completed successfully, checked by `success()`.
36+
/// * failure - ran unsuccessfully, checked by `failure()`.
37+
/// * cancelled - explicit user cancellation, checked by `cancelled()`.
38+
/// * skipped - skipped due to `if` condition, no check function.
39+
///
40+
/// Per [the docs](https://docs.github.com/en/actions/reference/workflows-and-actions/expressions#status-check-functions):
41+
/// > A default status check of success() is applied unless you include one of these functions.
42+
///
43+
/// This condition overrides the default behavior to proceed if all ancestor jobs have result
44+
/// `success` or `skipped`.
45+
const ifNoUpstreamFailures: String = "!failure() && !cancelled()"

0 commit comments

Comments
 (0)