5353 outputs :
5454 has_code_changes : ${{ steps.set-output.outputs.has_code_changes }}
5555 pr_head_sha : ${{ steps.pr-info.outputs.pr_head_sha }}
56+ pr_head_repo : ${{ steps.pr-info.outputs.pr_head_repo }}
5657 steps :
5758 - name : Get PR number for issue_comment events
5859 id : pr-info
@@ -70,15 +71,19 @@ jobs:
7071 repo: context.repo.repo,
7172 pull_number: issue.number
7273 });
74+ const baseRepo = `${context.repo.owner}/${context.repo.repo}`;
75+ const headRepo = pr.head.repo ? pr.head.repo.full_name : baseRepo;
7376 core.setOutput('pr_number', issue.number.toString());
7477 core.setOutput('pr_head_sha', pr.head.sha);
78+ core.setOutput('pr_head_repo', headRepo);
7579
7680 - name : Checkout source
7781 uses : actions/checkout@v4
7882 with :
79- # For issue_comment events, checkout the PR head SHA
83+ # For issue_comment on a fork PR: checkout from head repo so the commit exists
84+ repository : ${{ steps.pr-info.outputs.pr_head_repo || github.repository }}
8085 ref : ${{ github.event_name == 'issue_comment' && steps.pr-info.outputs.pr_head_sha || github.event.pull_request.head.sha || github.sha }}
81- # For pull_request events, fetch the PR head
86+ token : ${{ secrets.GITHUB_TOKEN }}
8287 fetch-depth : 0
8388
8489 - name : Check for code changes
@@ -275,11 +280,15 @@ jobs:
275280 exit 1
276281 fi
277282 echo "Checkout will use PR head SHA: ${{ needs.check-code-changes.outputs.pr_head_sha }}"
283+ echo "PR head repo: ${{ needs.check-code-changes.outputs.pr_head_repo || github.repository }}"
278284
279285 - name : Checkout source
280286 uses : actions/checkout@v4
281287 with :
282- ref : ${{ needs.check-code-changes.outputs.pr_head_sha || '' }}
288+ # For issue_comment on a fork PR: checkout from head repo so the commit exists
289+ repository : ${{ needs.check-code-changes.outputs.pr_head_repo || github.repository }}
290+ ref : ${{ needs.check-code-changes.outputs.pr_head_sha || github.sha }}
291+ token : ${{ secrets.GITHUB_TOKEN }}
283292
284293 - name : Extract Go version from go.mod
285294 run : sed -En 's/^go (.*)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV
0 commit comments