Skip to content

Commit 9ee0b11

Browse files
committed
Fix shell quoting in coverage-comment workflow
The "Resolve PR number" step embedded the event JSON via `<<<'${{ toJson(github.event) }}'`. Actions performs the `${{...}}` interpolation *before* bash parses the script, so the single-quoted heredoc string contained the entire raw event payload inline. As soon as the payload contained a single quote — e.g. an apostrophe in a commit message, branch name, or any string field — bash's '...' quoting closed early and the rest of the step's body became malformed, producing the GitHub-Actions error: syntax error near unexpected token `else` (reported against the assembled temp script's line number, not the workflow file's). The first PR opened after the coverage workflow landed happened to have such a quote. Pass the JSON via an environment variable instead. The shell sees only `"$EVENT_JSON"`, which is safe regardless of what characters the payload contains. Add a comment recording the failure mode so no future maintainer reintroduces the inline-interpolation pattern.
1 parent 25ce1e4 commit 9ee0b11

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/coverage-comment.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,25 @@ jobs:
119119
120120
- name: Resolve PR number
121121
id: pr
122+
env:
123+
# Pass the event JSON via the environment rather than
124+
# interpolating it directly into the shell script. The
125+
# `${{ toJson(...) }}` expansion happens *before* bash
126+
# parses the script, so any single quote inside the JSON
127+
# (e.g. an apostrophe in a commit message or branch
128+
# name) would terminate the surrounding `'...'` quoting
129+
# and corrupt the rest of the step — manifesting as a
130+
# bewildering syntax error like
131+
# "syntax error near unexpected token `else`" several
132+
# commands later.
133+
EVENT_JSON: ${{ toJson(github.event) }}
122134
run: |
123135
set -euo pipefail
124136
# workflow_run.pull_requests[] is empty for fork PRs and
125137
# for default-branch schedule/push runs. Empty == no PR
126138
# to comment on; fall through to the tracking-issue path.
127139
pr=$(jq -r '.workflow_run.pull_requests[0].number // empty' \
128-
<<<'${{ toJson(github.event) }}')
140+
<<<"$EVENT_JSON")
129141
echo "pr=$pr" >> "$GITHUB_OUTPUT"
130142
if [ -n "$pr" ]; then
131143
echo "Will comment on PR #$pr"

0 commit comments

Comments
 (0)