Skip to content

Commit ab3f3e0

Browse files
authored
fix(ci): post E2E Gate check to the PR when workflow_run fires (#938)
1 parent 3b7d309 commit ab3f3e0

1 file changed

Lines changed: 34 additions & 8 deletions

File tree

.github/workflows/e2e-gate.yml

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ on:
1010
permissions: {}
1111

1212
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.
1315
e2e:
1416
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'
2018
permissions:
2119
contents: read
2220
pull-requests: read
@@ -28,9 +26,7 @@ jobs:
2826

2927
gpu:
3028
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'
3430
permissions:
3531
contents: read
3632
pull-requests: read
@@ -39,3 +35,33 @@ jobs:
3935
with:
4036
required_label: test:e2e-gpu
4137
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

Comments
 (0)