mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
ci: run required checks on merge-queue groups (#11297)
* ci: run required checks on merge-queue groups Add the merge_group trigger to CI and PR title validation so every required check reports on the queued group's exact head. Group runs use exact-head concurrency groups that pushes cannot cancel, classify the group's combined diff from its base (a non-ancestor base fails planning), and keep the CI required gate running when a group is cancelled so it fails instead of reporting a skipped check. Title validation checks every squash commit subject between the group base and head. * ci: read the merge-group comparison from a file
This commit is contained in:
1 parent
28e95f34d0
commit
5efaedda88
9 files changed
+328
-34
No files matched your search
@@ -5,6 +5,9 @@ on:
|
||||
branches: [main]
|
||||
pull_request:
|
||||
branches: [main, "release/*"]
|
||||
# The merge queue tests each group's exact head before it lands on main.
|
||||
merge_group:
|
||||
types: [checks_requested]
|
||||
schedule:
|
||||
- cron: "23 0-2,4-23 * * *"
|
||||
- cron: "23 3 * * *"
|
||||
@@ -33,7 +36,8 @@ concurrency:
|
||||
# Main feedback also finishes, coalescing newer pushes to one pending run.
|
||||
# Scheduled/manual main runs coalesce to one active and the latest pending;
|
||||
# release and label-triggered qualification use exact-revision groups.
|
||||
group: ci-${{ (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || inputs.source_sha != '' || contains(github.event.pull_request.labels.*.name, 'ci:full')) && 'qualification' || 'feedback' }}-${{ inputs.source_sha || github.event.pull_request.number || github.ref }}
|
||||
# Merge-queue groups use their exact head and are never cancelled by pushes.
|
||||
group: ci-${{ github.event_name == 'merge_group' && 'merge-queue' || (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || inputs.source_sha != '' || contains(github.event.pull_request.labels.*.name, 'ci:full')) && 'qualification' || 'feedback' }}-${{ github.event.merge_group.head_sha || inputs.source_sha || github.event.pull_request.number || github.ref }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' && inputs.source_sha == '' && !contains(github.event.pull_request.labels.*.name, 'ci:full') }}
|
||||
|
||||
env:
|
||||
@@ -102,6 +106,14 @@ jobs:
|
||||
run: |
|
||||
test "${SOURCE_SHA}" = "${GITHUB_SHA}"
|
||||
test "${SOURCE_SHA}" = "$(git rev-parse HEAD)"
|
||||
- name: Bind classification to the queued merge-group head
|
||||
if: github.event_name == 'merge_group'
|
||||
env:
|
||||
MERGE_GROUP_HEAD_SHA: ${{ github.event.merge_group.head_sha }}
|
||||
run: |
|
||||
test -n "${MERGE_GROUP_HEAD_SHA}"
|
||||
test "${MERGE_GROUP_HEAD_SHA}" = "${GITHUB_SHA}"
|
||||
test "${MERGE_GROUP_HEAD_SHA}" = "$(git rev-parse HEAD)"
|
||||
- name: Find a verified ancestor for push selection
|
||||
id: baseline
|
||||
if: github.event_name == 'push' && inputs.source_sha == ''
|
||||
@@ -125,9 +137,9 @@ jobs:
|
||||
- name: Select verification lanes
|
||||
id: plan
|
||||
env:
|
||||
BASE_SHA: ${{ steps.baseline.outputs.base || github.event.pull_request.base.sha }}
|
||||
BASE_SHA: ${{ steps.baseline.outputs.base || github.event.pull_request.base.sha || github.event.merge_group.base_sha }}
|
||||
BASELINE_REASON: ${{ steps.baseline.outputs.reason }}
|
||||
HEAD_SHA: ${{ inputs.source_sha || github.event.pull_request.head.sha || github.sha }}
|
||||
HEAD_SHA: ${{ inputs.source_sha || github.event.pull_request.head.sha || github.event.merge_group.head_sha || github.sha }}
|
||||
CI_FULL: ${{ inputs.source_sha != '' || contains(github.event.pull_request.labels.*.name, 'ci:full') }}
|
||||
CI_SKIP_FULL: ${{ steps.qualification.outputs.run_full == 'false' }}
|
||||
run: node scripts/ci/plan.mjs
|
||||
@@ -328,7 +340,7 @@ jobs:
|
||||
strategy:
|
||||
# Failed PRs release the remaining matrix slots; qualification retains
|
||||
# every shard's diagnostics and coverage. Passing PRs run the full suite.
|
||||
fail-fast: ${{ github.event_name == 'pull_request' && needs.changes.outputs.tier == 'fast' }}
|
||||
fail-fast: ${{ (github.event_name == 'pull_request' || github.event_name == 'merge_group') && needs.changes.outputs.tier == 'fast' }}
|
||||
matrix:
|
||||
# Fast feedback uses one source group and twelve built groups. Shards
|
||||
# are balanced by recorded duration, but hosted runner speed varies,
|
||||
@@ -1215,7 +1227,9 @@ jobs:
|
||||
required:
|
||||
name: CI required
|
||||
# Report failed dependencies, but release superseded PR concurrency slots.
|
||||
if: ${{ !cancelled() }}
|
||||
# A merge-queue run always reports: a skipped required check counts as
|
||||
# passing, so a cancelled group must fail this gate instead.
|
||||
if: ${{ github.event_name == 'merge_group' || !cancelled() }}
|
||||
needs:
|
||||
[
|
||||
changes,
|
||||
|
||||
@@ -4,26 +4,74 @@ on:
|
||||
pull_request:
|
||||
branches: [main, "release/*"]
|
||||
types: [opened, synchronize, reopened, edited]
|
||||
# A queued group lands its squash commits on main. Their subjects are the
|
||||
# queued PR titles, so the queue revalidates exactly what Release Please reads.
|
||||
merge_group:
|
||||
types: [checks_requested]
|
||||
|
||||
permissions: {}
|
||||
|
||||
concurrency:
|
||||
group: pr-title-${{ github.event.pull_request.number }}
|
||||
cancel-in-progress: true
|
||||
group: pr-title-${{ github.event.pull_request.number || github.event.merge_group.head_sha }}
|
||||
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
jobs:
|
||||
pr-title:
|
||||
name: Conventional PR title
|
||||
runs-on: ubuntu-24.04
|
||||
timeout-minutes: 2
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Validate title for Release Please
|
||||
env:
|
||||
PR_TITLE: ${{ github.event.pull_request.title }}
|
||||
run: >-
|
||||
node -e 'const title = process.env.PR_TITLE ?? "";
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
MERGE_GROUP_BASE_SHA: ${{ github.event.merge_group.base_sha }}
|
||||
MERGE_GROUP_HEAD_SHA: ${{ github.event.merge_group.head_sha }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
# The comparison includes file patches and can exceed the size of one
|
||||
# environment string or argument, so it travels through a file.
|
||||
comparison_file=""
|
||||
if [ "${GITHUB_EVENT_NAME}" = "merge_group" ]; then
|
||||
comparison_file="$(mktemp)"
|
||||
trap 'rm -f "${comparison_file}"' EXIT
|
||||
gh api "repos/${GITHUB_REPOSITORY}/compare/${MERGE_GROUP_BASE_SHA}...${MERGE_GROUP_HEAD_SHA}" > "${comparison_file}"
|
||||
fi
|
||||
MERGE_GROUP_COMPARISON_FILE="${comparison_file}" node --input-type=module <<'EOF'
|
||||
import { readFileSync } from "node:fs";
|
||||
const conventional = /^(?:feat|fix|docs|refactor|perf|test|build|ci|chore|revert)(?:\([a-z0-9._/-]+\))?!?: .+/u;
|
||||
if (!conventional.test(title)) {
|
||||
console.error("PR title must use Conventional Commits, for example: feat: add historical source import");
|
||||
const event = process.env.GITHUB_EVENT_NAME;
|
||||
let titles;
|
||||
if (event === "pull_request") {
|
||||
titles = [process.env.PR_TITLE ?? ""];
|
||||
} else if (event === "merge_group") {
|
||||
// Every queued squash commit between the group base and head lands on
|
||||
// main. An incomplete or unexpected comparison fails closed.
|
||||
const comparison = JSON.parse(
|
||||
readFileSync(process.env.MERGE_GROUP_COMPARISON_FILE ?? "", "utf8") || "null",
|
||||
);
|
||||
const commits = Array.isArray(comparison?.commits) ? comparison.commits : [];
|
||||
if (
|
||||
comparison?.status !== "ahead" ||
|
||||
comparison.behind_by !== 0 ||
|
||||
commits.length === 0 ||
|
||||
comparison.total_commits !== commits.length ||
|
||||
commits.at(-1)?.sha !== process.env.MERGE_GROUP_HEAD_SHA
|
||||
) {
|
||||
console.error("Merge group commits between its base and head could not be identified");
|
||||
process.exit(1);
|
||||
}
|
||||
titles = commits.map((entry) => String(entry?.commit?.message ?? "").split("\n")[0]);
|
||||
} else {
|
||||
console.error(`Unsupported title validation event: ${event}`);
|
||||
process.exit(1);
|
||||
}'
|
||||
}
|
||||
const invalid = titles.filter((title) => !conventional.test(title));
|
||||
if (invalid.length) {
|
||||
console.error("PR title must use Conventional Commits, for example: feat: add historical source import");
|
||||
if (event === "merge_group") for (const title of invalid) console.error(`Queued commit subject: ${title}`);
|
||||
process.exit(1);
|
||||
}
|
||||
EOF
|
||||
Reference in new issue
Block a user