-
-
Notifications
You must be signed in to change notification settings - Fork 805
fix(ci): post the archive link on pull requests from forks #857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ jobs: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| RUN_ID: ${{ github.event.workflow_run.id }} | ||
| EVENT_PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} | ||
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | ||
|
|
||
| steps: | ||
| # This trusted workflow reads artifact metadata only. Never download or | ||
|
|
@@ -28,6 +29,20 @@ jobs: | |
| run: | | ||
| set -euo pipefail | ||
|
|
||
| # workflow_run.pull_requests is populated only for same-repository pull | ||
| # requests and is empty for pull requests from forks, so fork builds never | ||
| # got past the check below. Match the head SHA from the trusted event | ||
| # payload against the open pull requests instead. The artifact name also | ||
| # encodes the number, but it is produced by the untrusted pull_request | ||
| # workflow, so it is not trusted to select the comment target here. | ||
| if [[ ! "$EVENT_PR_NUMBER" =~ ^[0-9]+$ ]]; then | ||
| EVENT_PR_NUMBER=$( | ||
| gh api "repos/$GITHUB_REPOSITORY/pulls?state=open&per_page=100" --paginate \ | ||
| --jq '.[] | select(.head.sha == env.HEAD_SHA) | .number' \ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a fork run has no event PR number, Prompt To Fix With AIThis is a comment left during a code review.
Path: .github/workflows/pr-archive-comment.yml
Line: 41
Comment:
**Environment lookup returns no match**
When a fork run has no event PR number, `gh api --jq` does not expose the shell's `HEAD_SHA` through `env.HEAD_SHA`, so the filter returns no PR number and the guard exits without posting the archive link.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the upstream Prompt To Fix With AIThis is a comment left during a code review.
Path: .github/workflows/pr-archive-comment.yml
Line: 41
Comment:
**Merge SHA cannot match head**
For the upstream `pull_request` workflow, `workflow_run.head_sha` identifies the synthetic merge commit while `.head.sha` identifies the PR's actual head commit, so the fallback finds no PR and fork contributors still receive no archive link.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||
| | sed -n '1p' | ||
| ) | ||
| fi | ||
|
|
||
| if [[ ! "$EVENT_PR_NUMBER" =~ ^[0-9]+$ ]]; then | ||
| echo "The completed workflow run is not associated with a pull request." >&2 | ||
| exit 1 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a fork PR is merged or closed before its archive run completes,
workflow_run.pull_requestsis still empty but this query can no longer find the PR, so the following guard exits without posting the archive link. This is plausible because the archive job inpr-archive.ymlmay run for up to 45 minutes and closing a PR does not cancel its existing run; the fallback should also resolve matching closed/merged PRs while avoiding ambiguous SHA matches.Useful? React with 👍 / 👎.