|
| 1 | +name: E2E Label Help |
| 2 | + |
| 3 | +# When a `test:e2e` / `test:e2e-gpu` label is applied, post a PR comment |
| 4 | +# telling the maintainer the next manual step. We don't dispatch the workflow |
| 5 | +# ourselves: a workflow_dispatch-triggered run does not surface in the PR's |
| 6 | +# Checks tab, so we'd lose in-progress visibility. Instead we point the |
| 7 | +# maintainer at either the existing run (re-run from the UI) or the |
| 8 | +# `/ok to test <SHA>` command needed to refresh the mirror. |
| 9 | +# |
| 10 | +# Uses `pull_request_target` so forked PRs get a token capable of posting |
| 11 | +# comments. The job never checks out PR code; it only calls the GitHub API. |
| 12 | + |
| 13 | +on: |
| 14 | + pull_request_target: |
| 15 | + types: [labeled] |
| 16 | + |
| 17 | +permissions: {} |
| 18 | + |
| 19 | +jobs: |
| 20 | + hint: |
| 21 | + name: Post next-step hint for E2E label |
| 22 | + if: github.event.label.name == 'test:e2e' || github.event.label.name == 'test:e2e-gpu' |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + pull-requests: write |
| 26 | + steps: |
| 27 | + - name: Post comment |
| 28 | + env: |
| 29 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + GH_REPO: ${{ github.repository }} |
| 31 | + PR_NUMBER: ${{ github.event.pull_request.number }} |
| 32 | + PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} |
| 33 | + LABEL_NAME: ${{ github.event.label.name }} |
| 34 | + shell: bash |
| 35 | + run: | |
| 36 | + set -euo pipefail |
| 37 | +
|
| 38 | + case "$LABEL_NAME" in |
| 39 | + test:e2e) workflow_file=branch-e2e.yml; workflow_name="Branch E2E Checks" ;; |
| 40 | + test:e2e-gpu) workflow_file=test-gpu.yml; workflow_name="GPU Test" ;; |
| 41 | + *) echo "Unrecognized label $LABEL_NAME"; exit 1 ;; |
| 42 | + esac |
| 43 | +
|
| 44 | + mirror_ref="pull-request/$PR_NUMBER" |
| 45 | + mirror_sha=$(gh api "repos/$GH_REPO/branches/$mirror_ref" --jq '.commit.sha' 2>/dev/null || echo "") |
| 46 | + short_pr=${PR_HEAD_SHA:0:7} |
| 47 | +
|
| 48 | + if [ -z "$mirror_sha" ]; then |
| 49 | + body="Label \`$LABEL_NAME\` applied, but \`$mirror_ref\` does not exist yet. A maintainer needs to comment \`/ok to test $PR_HEAD_SHA\` to mirror this PR. Once the mirror exists, re-apply the label or re-run [$workflow_name](https://github.com/$GH_REPO/actions/workflows/$workflow_file) from the Actions tab." |
| 50 | + elif [ "$mirror_sha" != "$PR_HEAD_SHA" ]; then |
| 51 | + short_mirror=${mirror_sha:0:7} |
| 52 | + body="Label \`$LABEL_NAME\` applied, but \`$mirror_ref\` is at \`$short_mirror\` while the PR head is \`$short_pr\`. A maintainer needs to comment \`/ok to test $PR_HEAD_SHA\` to refresh the mirror. Once the mirror catches up, re-run [$workflow_name](https://github.com/$GH_REPO/actions/workflows/$workflow_file) from the Actions tab." |
| 53 | + else |
| 54 | + run_id=$(gh api "repos/$GH_REPO/actions/workflows/$workflow_file/runs?head_sha=$PR_HEAD_SHA&event=push" \ |
| 55 | + --jq '.workflow_runs | sort_by(.created_at) | reverse | .[0].id // empty') |
| 56 | + if [ -n "$run_id" ]; then |
| 57 | + run_link="[the existing run](https://github.com/$GH_REPO/actions/runs/$run_id)" |
| 58 | + else |
| 59 | + run_link="[$workflow_name](https://github.com/$GH_REPO/actions/workflows/$workflow_file)" |
| 60 | + fi |
| 61 | + body="Label \`$LABEL_NAME\` applied for \`$short_pr\`. Open $run_link and click **Re-run all jobs** to execute with the label set. The \`E2E Gate\` check on this PR will flip green automatically once the run finishes." |
| 62 | + fi |
| 63 | +
|
| 64 | + gh pr comment "$PR_NUMBER" --body "$body" |
0 commit comments