Commit 6e0989c
authored
Resolve PR by head SHA in coverage-comment workflow (#847)
Two issues with the previous "Resolve PR number" step:
1. Inline `${{ toJson(github.event) }}` interpolation inside `'...'`
shell quoting could be broken by any single quote in the payload
(e.g. an apostrophe in a commit message), producing the
notorious `syntax error near unexpected token "else"`.
2. `workflow_run.pull_requests[]` is *always empty* for PRs whose
head ref lives in a fork. By GitHub design, the default-branch
`workflow_run` handler (which holds the write token) does not
receive cross-repo PR linkage. The first PR through the new
coverage workflow happened to come from a fork, so the comment
was posted to the tracking issue instead of the PR.
Replace the bash step with a github-script step:
- reads `github.event` via an environment variable, immune to
payload-quoting issues;
- first tries `workflow_run.pull_requests[0]` for the same-repo
branch case;
- falls back to
`GET /repos/{owner}/{repo}/commits/{sha}/pulls` (the
"pull requests associated with commit" API), which is the only
way to recover a PR number from a fork `workflow_run` payload;
- prefers an open PR but tolerates a closed one if there's a
squash-merge race between the build and this comment job;
- falls through to the tracking-issue path only when neither
source produces a PR.
The downstream "Comment on PR" step is unchanged — it consumes the
same `steps.pr.outputs.pr` it always did.1 parent 34c9d32 commit 6e0989c
1 file changed
Lines changed: 45 additions & 23 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
| 122 | + | |
122 | 123 | | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
133 | 131 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
147 | 169 | | |
148 | 170 | | |
149 | 171 | | |
| |||
0 commit comments