Skip to content

Commit 243e78e

Browse files
authored
benchmarks.yml: Fix PR branch checkout when triggered by comment (#1998)
This commit resolves an issue in our GitHub Actions workflow where the correct PR branch was not being checked out when the workflow was triggered by an 'issue_comment' event. Previously, the workflow was set up to handle the 'pull_request_target' event correctly, but it did not account for the different context provided by 'issue_comment'. The fix involves adding conditional steps in the workflow to handle the 'issue_comment' event. When the workflow is triggered by an 'issue_comment', it now uses the GitHub API to extract the PR number from the comment context. This information is then used to retrieve the PR details, including the head branch and the repository name. With these details, the workflow can now correctly check out the PR branch associated with the issue comment. This ensures that our benchmarks and other PR-related checks run against the appropriate branch, regardless of the triggering event.
1 parent 3e73e9b commit 243e78e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

.github/workflows/benchmarks.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,36 @@ jobs:
5050
path: benchmarks/timings_1.pickle
5151
- name: Checkout PR branch
5252
uses: actions/checkout@v4
53+
if: github.event_name == 'pull_request_target'
5354
with:
5455
ref: ${{ github.event.pull_request.head.ref }}
5556
repository: ${{ github.event.pull_request.head.repo.full_name }}
5657
fetch-depth: 0
5758
persist-credentials: false
5859
clean: false
60+
- name: Checkout PR branch from issue comment
61+
if: github.event_name == 'issue_comment'
62+
uses: actions/github-script@v5
63+
with:
64+
script: |
65+
const issue_number = context.issue.number;
66+
const repository = context.repo.repo;
67+
const owner = context.repo.owner;
68+
const pr = await github.rest.pulls.get({ owner, repo: repository, pull_number: issue_number });
69+
const ref = pr.data.head.ref;
70+
const repoFullName = pr.data.head.repo.full_name;
71+
console.log(`::set-output name=ref::${ref}`);
72+
console.log(`::set-output name=repo::${repoFullName}`);
73+
result-encoding: string
74+
- name: Actual Checkout for Issue Comment
75+
if: github.event_name == 'issue_comment'
76+
uses: actions/checkout@v4
77+
with:
78+
repository: ${{ steps.checkout-pr-branch-from-issue-comment.outputs.repo }}
79+
ref: ${{ steps.checkout-pr-branch-from-issue-comment.outputs.ref }}
80+
fetch-depth: 0
81+
persist-credentials: false
82+
clean: false
5983
- name: Download benchmark results
6084
uses: actions/download-artifact@v4
6185
with:

0 commit comments

Comments
 (0)