Skip to content

Commit b991295

Browse files
authored
ci: guard fromJSON in detect-changes against empty pr-info output (#1940)
The detect-changes job's `Detect changed paths` step gates on `startsWith(github.ref_name, 'pull-request/')`, but GitHub Actions evaluates step-level `env:` expressions eagerly — the `if:` gate does not short-circuit them. On push to main, tag, or schedule events the preceding `Resolve PR base branch` step is skipped and its outputs are empty strings, so `fromJSON(steps.pr-info.outputs.pr-info)` raises a template error and fails the step even though its `if:` would otherwise skip it. That failure cascades into the final "Check job status" aggregation, turning every push-to-main CI run red (see run 24566662170). Guard the `fromJSON` call with a short-circuit so the expression resolves to an empty string when pr-info did not run. On PR events the expression still evaluates to the PR's actual base ref.
1 parent 56b53ca commit b991295

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,15 @@ jobs:
121121
id: filter
122122
if: ${{ startsWith(github.ref_name, 'pull-request/') }}
123123
env:
124-
BASE_REF: ${{ fromJSON(steps.pr-info.outputs.pr-info).base.ref }}
124+
# GitHub Actions evaluates step-level `env:` expressions eagerly —
125+
# the step's `if:` gate does NOT short-circuit them. On non-PR
126+
# events (push/tag/schedule), `pr-info` is skipped and its outputs
127+
# are empty strings, so `fromJSON('')` would raise a template error
128+
# and fail the step despite `if:` being false. Guard the
129+
# `fromJSON` call with a short-circuit so the expression resolves
130+
# to an empty string on non-PR events; the step is still gated
131+
# off by `if:`, so `BASE_REF` is never consumed there.
132+
BASE_REF: ${{ steps.pr-info.outputs.pr-info && fromJSON(steps.pr-info.outputs.pr-info).base.ref || '' }}
125133
run: |
126134
# Diff against the merge base with the PR's actual target branch.
127135
# Uses merge-base so diverged branches only show files changed on

0 commit comments

Comments
 (0)