Skip to content

Commit b7b5e2a

Browse files
authored
ci: run required checks for the merge queue (#1061)
1 parent 2d8d8e7 commit b7b5e2a

3 files changed

Lines changed: 38 additions & 11 deletions

File tree

‎.github/workflows/pull-request-metadata.yml‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
name: Pull Request Metadata
22
run-name: >-
33
${{ inputs.request_id && format('{0} [{1}]', github.workflow, inputs.request_id)
4-
|| github.event.pull_request.title || github.event.head_commit.message || github.workflow }}
4+
|| github.event.pull_request.title || github.event.head_commit.message
5+
|| github.event.merge_group.head_commit.message || github.workflow }}
56
67
on:
78
pull_request:
89
types: [opened, edited, synchronize, reopened]
10+
merge_group:
911
workflow_dispatch:
1012
inputs:
1113
pr_number:
@@ -26,8 +28,16 @@ jobs:
2628
name: Pull Request Metadata
2729
runs-on: ubuntu-24.04
2830
steps:
31+
# The queue only admits pull requests whose metadata check already passed, so a merge group
32+
# reports success instead of skipping: a required check must report for the queue to merge.
33+
- name: Accept metadata validated on the pull request
34+
if: github.event_name == 'merge_group'
35+
run: echo "Pull request metadata was validated on the pull request before it was queued."
36+
2937
- uses: actions/checkout@v4
38+
if: github.event_name != 'merge_group'
3039
- name: Resolve pull request metadata
40+
if: github.event_name != 'merge_group'
3141
env:
3242
EVENT_NAME: ${{ github.event_name }}
3343
GH_TOKEN: ${{ github.token }}
@@ -41,6 +51,7 @@ jobs:
4151
fi
4252
4353
- name: Validate branch, title, and description
54+
if: github.event_name != 'merge_group'
4455
env:
4556
PR_METADATA_PATH: ${{ runner.temp }}/pull-request.json
4657
run: python -m scripts.validate_pr_metadata --metadata-file "${PR_METADATA_PATH}"

‎.github/workflows/verify.yml‎

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ name: Verify
22

33
on:
44
pull_request:
5+
merge_group:
56
workflow_dispatch:
67

78
permissions:
89
contents: read
910

11+
# Each merge group has its own gh-readonly-queue ref, so queued groups never cancel each other; the
12+
# queue itself discards a group's run when it rebuilds the group.
1013
concurrency:
11-
group: verify-${{ github.workflow }}-${{ github.ref }}
12-
cancel-in-progress: true
14+
group: verify-${{ github.workflow }}-${{ github.event.merge_group.head_ref || github.ref }}
15+
cancel-in-progress: ${{ github.event_name != 'merge_group' }}
1316

1417
jobs:
1518
changes:
@@ -32,8 +35,8 @@ jobs:
3235
id: scope
3336
env:
3437
EVENT_NAME: ${{ github.event_name }}
35-
BASE_SHA: ${{ github.event.pull_request.base.sha }}
36-
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
38+
BASE_SHA: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
39+
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.event.merge_group.head_sha }}
3740
run: |
3841
write_scope() {
3942
{
@@ -48,7 +51,19 @@ jobs:
4851
} >> "${GITHUB_OUTPUT}"
4952
}
5053
51-
if [[ "${EVENT_NAME}" != "pull_request" ]]; then
54+
if [[ "${EVENT_NAME}" != "pull_request" && "${EVENT_NAME}" != "merge_group" ]]; then
55+
write_scope true true true true true true true true
56+
exit 0
57+
fi
58+
59+
# A merge group's head is its base plus every queued pull request ahead of and including
60+
# this one, so the base..head diff covers the whole group. Anything that prevents an exact
61+
# diff runs everything rather than risk skipping a suite. Three dots compare with the merge
62+
# base, so changes that landed on main after a branch started are not counted as its own.
63+
changed_paths="${RUNNER_TEMP}/changed-paths"
64+
if [[ -z "${BASE_SHA}" || -z "${HEAD_SHA}" ]] || \
65+
! git diff --name-only -z "${BASE_SHA}...${HEAD_SHA}" > "${changed_paths}"; then
66+
echo "Could not diff ${BASE_SHA:-<none>}...${HEAD_SHA:-<none>}; running every suite" >&2
5267
write_scope true true true true true true true true
5368
exit 0
5469
fi
@@ -135,9 +150,7 @@ jobs:
135150
broad=true
136151
;;
137152
esac
138-
# Three dots: compare with the merge base, so changes that landed on main after the branch
139-
# started are not counted as this pull request's changes.
140-
done < <(git diff --name-only -z "${BASE_SHA}...${HEAD_SHA}")
153+
done < "${changed_paths}"
141154
142155
if [[ "${changed}" != "true" ]]; then
143156
write_scope true true true true true true true true
@@ -590,7 +603,7 @@ jobs:
590603
- name: Check out the comparison base
591604
uses: actions/checkout@v4
592605
with:
593-
ref: ${{ github.event.pull_request.base.sha || 'main' }}
606+
ref: ${{ github.event.pull_request.base.sha || github.event.merge_group.base_sha || 'main' }}
594607
path: base
595608
- uses: astral-sh/setup-uv@v5
596609
with:

‎.github/workflows/version-guard.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
name: Version Guard
22
run-name: >-
33
${{ inputs.request_id && format('{0} [{1}]', github.workflow, inputs.request_id)
4-
|| github.event.pull_request.title || github.event.head_commit.message || github.workflow }}
4+
|| github.event.pull_request.title || github.event.head_commit.message
5+
|| github.event.merge_group.head_commit.message || github.workflow }}
56
67
on:
78
pull_request:
@@ -10,6 +11,8 @@ on:
1011
push:
1112
branches:
1213
- main
14+
# Checks out the merge group's head, so the version that would land on main is the one checked.
15+
merge_group:
1316
workflow_dispatch:
1417
inputs:
1518
request_id:

0 commit comments

Comments
 (0)