|
10 | 10 | permissions: {} |
11 | 11 |
|
12 | 12 | jobs: |
| 13 | + # On PR events, actually evaluate the gate — these runs post their check |
| 14 | + # result to the PR's head SHA, which is what branch protection sees. |
13 | 15 | e2e: |
14 | 16 | name: E2E |
15 | | - # Run on every PR event; on workflow_run, only when the upstream was the |
16 | | - # matching gated workflow. |
17 | | - if: >- |
18 | | - github.event_name == 'pull_request' || |
19 | | - github.event.workflow_run.name == 'Branch E2E Checks' |
| 17 | + if: github.event_name == 'pull_request' |
20 | 18 | permissions: |
21 | 19 | contents: read |
22 | 20 | pull-requests: read |
|
28 | 26 |
|
29 | 27 | gpu: |
30 | 28 | name: GPU E2E |
31 | | - if: >- |
32 | | - github.event_name == 'pull_request' || |
33 | | - github.event.workflow_run.name == 'GPU Test' |
| 29 | + if: github.event_name == 'pull_request' |
34 | 30 | permissions: |
35 | 31 | contents: read |
36 | 32 | pull-requests: read |
|
39 | 35 | with: |
40 | 36 | required_label: test:e2e-gpu |
41 | 37 | workflow_file: test-gpu.yml |
| 38 | + |
| 39 | + # When the guarded workflow finishes, GitHub fires `workflow_run` in the |
| 40 | + # default-branch context — any check posted from here would land on `main`, |
| 41 | + # not on the PR. Instead, find the latest `pull_request`-triggered gate run |
| 42 | + # for the same head SHA and ask the API to re-run it. The re-run replays the |
| 43 | + # original event (labels, head SHA) so the check posts to the PR again, and |
| 44 | + # this time the gate sees the successful upstream run. |
| 45 | + rerun-on-completion: |
| 46 | + name: Re-run gate in PR context |
| 47 | + if: github.event_name == 'workflow_run' |
| 48 | + runs-on: ubuntu-latest |
| 49 | + permissions: |
| 50 | + actions: write |
| 51 | + steps: |
| 52 | + - name: Rerun latest PR-context gate for this SHA |
| 53 | + env: |
| 54 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + GH_REPO: ${{ github.repository }} |
| 56 | + HEAD_SHA: ${{ github.event.workflow_run.head_sha }} |
| 57 | + shell: bash |
| 58 | + run: | |
| 59 | + set -euo pipefail |
| 60 | + run_id=$(gh api "repos/$GH_REPO/actions/workflows/e2e-gate.yml/runs?event=pull_request&head_sha=$HEAD_SHA" \ |
| 61 | + --jq '.workflow_runs | sort_by(.created_at) | reverse | .[0].id // empty') |
| 62 | + if [ -z "$run_id" ]; then |
| 63 | + echo "No pull_request-triggered E2E Gate run found for $HEAD_SHA — nothing to re-run." |
| 64 | + exit 0 |
| 65 | + fi |
| 66 | + echo "Re-running E2E Gate run $run_id so it re-evaluates and posts a fresh check on the PR." |
| 67 | + gh api --method POST "repos/$GH_REPO/actions/runs/$run_id/rerun" |
0 commit comments