Skip to content

Commit e69a146

Browse files
authored
πŸ› fix: checkout PR head SHA for issue_comment triggered workflows (llm-d#832)
* πŸ› fix: checkout PR head SHA for issue_comment triggered workflows When /trigger-e2e-full is used on a PR, the workflow is triggered via issue_comment event. For this event type, github.sha points to the default branch (main), not the PR head. This caused e2e-tests and lint-and-test jobs to build/test main instead of the PR changes. Fix: - Export pr_head_sha from check-code-changes job (already computed) - e2e-tests: use pr_head_sha output in checkout (already depends on check-code-changes) - lint-and-test: add PR info step to resolve head SHA for issue_comment events - When ref is empty string, actions/checkout falls back to default behavior (correct for pull_request events) Signed-off-by: Andrew Anderson <andy@clubanderson.com> * chore: re-trigger CI checks Signed-off-by: Andrew Anderson <andy@clubanderson.com> * πŸ› fix: address copilot review - security gates for issue_comment events - Skip lint-and-test for issue_comment events (already runs on pull_request) - Remove duplicated PR head SHA resolution from lint-and-test - Tighten e2e-tests gate: issue_comment only runs when check-full-tests validates an approved trigger from a trusted collaborator - Explicitly handle workflow_dispatch and pull_request event types Signed-off-by: Andrew Anderson <andy@clubanderson.com> * πŸ› fix: address round 2 copilot review - Restore workflow_dispatch smoke-test path (run_full OR has_code_changes) - Require check-code-changes success for issue_comment e2e runs - Add explicit validation step to fail fast if pr_head_sha is empty Signed-off-by: Andrew Anderson <andy@clubanderson.com> --------- Signed-off-by: Andrew Anderson <andy@clubanderson.com>
1 parent affba38 commit e69a146

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

β€Ž.github/workflows/ci-pr-checks.yamlβ€Ž

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
pull-requests: read # For reading PR details when triggered via issue_comment
5353
outputs:
5454
has_code_changes: ${{ steps.set-output.outputs.has_code_changes }}
55+
pr_head_sha: ${{ steps.pr-info.outputs.pr_head_sha }}
5556
steps:
5657
- name: Get PR number for issue_comment events
5758
id: pr-info
@@ -108,7 +109,10 @@ jobs:
108109
echo "has_code_changes=true" >> $GITHUB_OUTPUT
109110
fi
110111
112+
# lint-and-test already runs on pull_request events; skip for issue_comment
113+
# to avoid untrusted commenters triggering execution of PR code
111114
lint-and-test:
115+
if: github.event_name != 'issue_comment'
112116
runs-on: ubuntu-latest
113117
steps:
114118
- name: Checkout source
@@ -250,13 +254,32 @@ jobs:
250254
e2e-tests:
251255
runs-on: ubuntu-latest
252256
needs: [lint-and-test, check-code-changes, check-full-tests]
253-
if: always() && (needs.check-full-tests.outputs.run_full == 'true' || (needs.check-code-changes.result == 'success' && needs.check-code-changes.outputs.has_code_changes == 'true'))
257+
if: >-
258+
always() && (
259+
(github.event_name == 'issue_comment' && needs.check-full-tests.outputs.run_full == 'true' && needs.check-code-changes.result == 'success') ||
260+
(github.event_name == 'workflow_dispatch' && (
261+
needs.check-full-tests.outputs.run_full == 'true' ||
262+
(needs.check-code-changes.result == 'success' && needs.check-code-changes.outputs.has_code_changes == 'true')
263+
)) ||
264+
(github.event_name == 'pull_request' && needs.check-code-changes.result == 'success' && needs.check-code-changes.outputs.has_code_changes == 'true')
265+
)
254266
timeout-minutes: 60
255267
permissions:
256268
contents: read
257269
steps:
270+
- name: Validate PR head SHA for issue_comment events
271+
if: github.event_name == 'issue_comment'
272+
run: |
273+
if [ -z "${{ needs.check-code-changes.outputs.pr_head_sha }}" ]; then
274+
echo "::error::pr_head_sha is empty β€” refusing to fall back to main"
275+
exit 1
276+
fi
277+
echo "Checkout will use PR head SHA: ${{ needs.check-code-changes.outputs.pr_head_sha }}"
278+
258279
- name: Checkout source
259280
uses: actions/checkout@v4
281+
with:
282+
ref: ${{ needs.check-code-changes.outputs.pr_head_sha || '' }}
260283

261284
- name: Extract Go version from go.mod
262285
run: sed -En 's/^go (.*)$/GO_VERSION=\1/p' go.mod >> $GITHUB_ENV

0 commit comments

Comments
Β (0)