Skip to content

🐛 fix: checkout PR head SHA for issue_comment triggered workflows#832

Merged
mamy-CS merged 4 commits intomainfrom
fix/issue-comment-checkout-ref
Mar 4, 2026
Merged

🐛 fix: checkout PR head SHA for issue_comment triggered workflows#832
mamy-CS merged 4 commits intomainfrom
fix/issue-comment-checkout-ref

Conversation

@clubanderson
Copy link
Copy Markdown
Contributor

@clubanderson clubanderson commented Mar 3, 2026

Problem

Fixes #831

When /trigger-e2e-full is used on a PR, the workflow triggers via issue_comment event. For this event type, github.sha points to main (the default branch), not the PR head. This caused the e2e-tests job to build and test code from main instead of the PR changes.

Root Cause

The check-code-changes job already correctly resolves the PR head SHA and checks it out, but e2e-tests did a bare actions/checkout@v4 with no ref:, defaulting to github.sha (main for issue_comment events).

Fix

  • check-code-changes: Export pr_head_sha as a job output (already computed but not exposed)
  • e2e-tests: Use needs.check-code-changes.outputs.pr_head_sha in checkout ref, with a validation step that fails fast if the SHA is empty (prevents silent fallback to main)
  • lint-and-test: Skip entirely for issue_comment events — it already runs on pull_request triggers, so re-running on comments is unnecessary and would allow untrusted commenters to execute PR code
  • e2e-tests gate: Tightened so issue_comment events only run when check-full-tests validates an approved trigger from a trusted collaborator AND check-code-changes succeeds
  • workflow_dispatch: Preserved smoke-test path — runs when run_full_tests=true OR when code changes are detected (matching existing behavior)

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>
Copilot AI review requested due to automatic review settings March 3, 2026 17:20
@clubanderson
Copy link
Copy Markdown
Contributor Author

/trigger-e2e-full

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

🚀 Full E2E tests triggered by /trigger-e2e-full

View the Kind E2E workflow run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

GPU Pre-flight Check ✅

GPUs are available for e2e-openshift tests. Proceeding with deployment.

Resource Total Allocated Available
GPUs 50 12 38
Cluster Value
Nodes 16 (7 with GPUs)
Total CPU 993 cores
Total Memory 10383 Gi
GPUs required 4 (min) / 6 (recommended)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes CI correctness for issue_comment-triggered runs by ensuring jobs checkout the PR head commit (instead of main, which github.sha points to for issue_comment events).

Changes:

  • Export pr_head_sha from check-code-changes as a job output.
  • Update e2e-tests to checkout needs.check-code-changes.outputs.pr_head_sha.
  • Update lint-and-test to resolve the PR head SHA on issue_comment events and checkout that ref.

Comment thread .github/workflows/ci-pr-checks.yaml Outdated
Comment thread .github/workflows/ci-pr-checks.yaml Outdated
Comment on lines 279 to +282
- name: Checkout source
uses: actions/checkout@v4
with:
ref: ${{ needs.check-code-changes.outputs.pr_head_sha || '' }}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e2e-tests now checks out needs.check-code-changes.outputs.pr_head_sha (PR code) even on issue_comment runs, but the job-level if: condition still allows the job to run when has_code_changes == 'true' (which can be true for ordinary comments). This enables untrusted commenters to trigger execution of PR code (and expensive Kind E2E runs). Tighten the e2e-tests if: logic so that issue_comment runs only proceed when check-full-tests has validated an approved trigger comment from a trusted collaborator.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot mentioned this pull request Mar 3, 2026
Signed-off-by: Andrew Anderson <andy@clubanderson.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

GPU Pre-flight Check ✅

GPUs are available for e2e-openshift tests. Proceeding with deployment.

Resource Total Allocated Available
GPUs 50 12 38
Cluster Value
Nodes 16 (7 with GPUs)
Total CPU 993 cores
Total Memory 10383 Gi
GPUs required 4 (min) / 6 (recommended)

- 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>
Copilot AI review requested due to automatic review settings March 3, 2026 17:53
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

GPU Pre-flight Check ✅

GPUs are available for e2e-openshift tests. Proceeding with deployment.

Resource Total Allocated Available
GPUs 50 12 38
Cluster Value
Nodes 16 (7 with GPUs)
Total CPU 993 cores
Total Memory 10383 Gi
GPUs required 4 (min) / 6 (recommended)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread .github/workflows/ci-pr-checks.yaml Outdated
if: >-
always() && (
(github.event_name == 'issue_comment' && needs.check-full-tests.outputs.run_full == 'true') ||
(github.event_name == 'workflow_dispatch' && needs.check-full-tests.outputs.run_full == 'true') ||
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated if: condition removes the previous fallback that allowed smoke tests to run on workflow_dispatch when run_full_tests is false. With this change, a manual dispatch with default inputs will run no e2e tests, which contradicts the workflow_dispatch input description (“default: smoke tests only”) and the comment above e2e-tests (“smoke tests run automatically”). Consider restoring the smoke-test path for workflow_dispatch (e.g., reuse the has_code_changes/default-true behavior) or update the input/inline documentation to match the new behavior.

Suggested change
(github.event_name == 'workflow_dispatch' && needs.check-full-tests.outputs.run_full == 'true') ||
(github.event_name == 'workflow_dispatch' && (
needs.check-full-tests.outputs.run_full == 'true' ||
(needs.check-code-changes.result == 'success' && needs.check-code-changes.outputs.has_code_changes == 'true')
)) ||

Copilot uses AI. Check for mistakes.
Comment on lines +257 to +270
if: >-
always() && (
(github.event_name == 'issue_comment' && needs.check-full-tests.outputs.run_full == 'true') ||
(github.event_name == 'workflow_dispatch' && needs.check-full-tests.outputs.run_full == 'true') ||
(github.event_name == 'pull_request' && needs.check-code-changes.result == 'success' && needs.check-code-changes.outputs.has_code_changes == 'true')
)
timeout-minutes: 60
permissions:
contents: read
steps:
- name: Checkout source
uses: actions/checkout@v4
with:
ref: ${{ needs.check-code-changes.outputs.pr_head_sha || '' }}
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For issue_comment triggers, e2e-tests can still run even if check-code-changes fails (because of always() and no needs.check-code-changes.result == 'success' guard). In that failure mode needs.check-code-changes.outputs.pr_head_sha will be empty, so the checkout falls back to the event default SHA (which is main for issue_comment) and reintroduces the original problem. Tighten the if: for the issue_comment branch to require check-code-changes success (and/or a non-empty pr_head_sha), or explicitly fail early when pr_head_sha is empty.

Copilot uses AI. Check for mistakes.
Comment on lines +112 to 116
# lint-and-test already runs on pull_request events; skip for issue_comment
# to avoid untrusted commenters triggering execution of PR code
lint-and-test:
if: github.event_name != 'issue_comment'
runs-on: ubuntu-latest
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes lint-and-test skip entirely for issue_comment events, but the PR description says the fix is to resolve PR info and check out the PR head SHA in lint-and-test. Please reconcile the implementation with the PR description (either implement the described checkout/ref behavior for trusted comment triggers, or update the PR description to reflect that lint is intentionally not run for issue_comment).

Copilot uses AI. Check for mistakes.
- 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>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

GPU Pre-flight Check ✅

GPUs are available for e2e-openshift tests. Proceeding with deployment.

Resource Total Allocated Available
GPUs 50 16 34
Cluster Value
Nodes 16 (7 with GPUs)
Total CPU 993 cores
Total Memory 10383 Gi
GPUs required 4 (min) / 6 (recommended)

@mamy-CS
Copy link
Copy Markdown
Collaborator

mamy-CS commented Mar 3, 2026

@clubanderson can we also make the full tests required before pr merge? Thanks.

@clubanderson
Copy link
Copy Markdown
Contributor Author

Is there an example of another test or action you would like to follow in wva?

@mamy-CS
Copy link
Copy Markdown
Collaborator

mamy-CS commented Mar 3, 2026

For example the CI openshift tests and the smoke tests are required right? Same
The smoke tests currently are labeled CI - PR Checks / e2e-tests (pull_request). We can label that SMOKE EMULATED and have another one for FULL Emulated?

@clubanderson
Copy link
Copy Markdown
Contributor Author

@mamy-CS Making full e2e tests a required check is separate scope from this PR (which fixes the checkout ref bug for issue_comment triggers). Could you approve this one and open a new issue to track adding a required full e2e check? Happy to help with that next. Thanks!

Copy link
Copy Markdown
Collaborator

@mamy-CS mamy-CS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@mamy-CS mamy-CS merged commit e69a146 into main Mar 4, 2026
18 checks passed
@mamy-CS mamy-CS deleted the fix/issue-comment-checkout-ref branch March 4, 2026 15:00
zdtsw added a commit to zdtsw-forking/workload-variant-autoscaler that referenced this pull request Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI: /trigger-e2e-full runs full e2e against latest main instead of PR head

3 participants