Resolve PR by head SHA in coverage-comment workflow#847
Merged
mjp41 merged 1 commit intomicrosoft:mainfrom May 8, 2026
Merged
Conversation
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.
Coverage report (cross-platform merged)Lines covered ( Merged line coverage is the per-line union across all platforms. Region coverage is reported per-platform only; no cross-platform region total is computed. Per-directory breakdown
Per-platform contributions (advisory)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
workflow_run.pull_requests[]is always empty for PRs whose head ref lives in a fork. By GitHub design, the default-branchworkflow_runhandler (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:
github.eventvia an environment variable, immune to payload-quoting issues;workflow_run.pull_requests[0]for the same-repo branch case;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 forkworkflow_runpayload;The downstream "Comment on PR" step is unchanged — it consumes the same
steps.pr.outputs.prit always did.