diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 60a9dba..8b00d50 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,6 +4,8 @@ on: push: branches: [main] pull_request: + merge_group: + types: [checks_requested] workflow_dispatch: inputs: full_mutation: @@ -48,7 +50,7 @@ env: # Scheduled/full-manual runs use unique groups: cancel=false alone still replaces pending runs. # Release validation is isolated; the separate publisher retains its publication lock. concurrency: - group: ci-${{ (inputs.ref != '' || inputs.release_tag != '') && format('release-{0}-{1}', inputs.release_tag, inputs.ref) || github.event_name == 'schedule' && format('scheduled-{0}', github.run_id) || github.event_name == 'workflow_dispatch' && inputs.full_mutation == true && format('full-{0}', github.run_id) || format('validation-{0}', github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && format('fork-pr-{0}', github.event.pull_request.number) || github.head_ref != '' && format('refs/heads/{0}', github.head_ref) || github.ref) }} + group: ci-${{ (inputs.ref != '' || inputs.release_tag != '') && format('release-{0}-{1}', inputs.release_tag, inputs.ref) || github.event_name == 'merge_group' && format('queue-{0}', github.sha) || github.event_name == 'schedule' && format('scheduled-{0}', github.run_id) || github.event_name == 'workflow_dispatch' && inputs.full_mutation == true && format('full-{0}', github.run_id) || format('validation-{0}', github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && format('fork-pr-{0}', github.event.pull_request.number) || github.head_ref != '' && format('refs/heads/{0}', github.head_ref) || github.ref) }} cancel-in-progress: ${{ inputs.ref == '' && inputs.release_tag == '' && github.event_name != 'schedule' && !(github.event_name == 'workflow_dispatch' && inputs.full_mutation == true) }} jobs: diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml index 3521195..0ec774f 100644 --- a/.github/workflows/pr-title.yml +++ b/.github/workflows/pr-title.yml @@ -3,6 +3,8 @@ name: PR title on: pull_request_target: types: [opened, edited, reopened, synchronize] + merge_group: + types: [checks_requested] workflow_dispatch: inputs: pr_number: @@ -21,7 +23,7 @@ jobs: steps: # Only inspect PR metadata. Never check out or execute pull-request code here. - uses: amannn/action-semantic-pull-request@48f256284bd46cdaab1048c3721360e808335d50 # v6.1.1 - if: github.event_name != 'workflow_dispatch' + if: github.event_name == 'pull_request_target' env: GITHUB_TOKEN: ${{ github.token }} with: @@ -37,6 +39,60 @@ jobs: ci chore revert + - name: Validate the exact queued candidate using metadata only + if: github.event_name == 'merge_group' + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + run: | + node --input-type=module <<'JS' + import assert from 'node:assert/strict'; + import { execFileSync } from 'node:child_process'; + import { readFileSync } from 'node:fs'; + const repo = process.env.GH_REPO; + assert.match(repo, /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/); + const event = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')); + assert.equal(event.action, 'checks_requested'); + assert.equal(event.repository.full_name, repo); + const group = event.merge_group; + assert.equal(group.base_ref, 'refs/heads/main'); + assert.equal(group.head_sha, process.env.GITHUB_SHA); + assert.match(group.head_sha, /^[0-9a-f]{40}$/); + assert.match(group.base_sha, /^[0-9a-f]{40}$/); + const [owner, name] = repo.split('/'); + const query = `query($owner:String!,$name:String!,$endCursor:String) { + repository(owner:$owner,name:$name) { + pullRequests(states:OPEN,baseRefName:"main",first:100,after:$endCursor) { + pageInfo { hasNextPage endCursor } + nodes { number title state baseRefName headRefOid repository { nameWithOwner } + mergeQueueEntry { headCommit { oid } baseCommit { oid } } + } + } + } + }`; + const pages = JSON.parse(execFileSync('gh', [ + 'api', 'graphql', '--paginate', '--slurp', '-f', `query=${query}`, + '-f', `owner=${owner}`, '-f', `name=${name}`, + ], { encoding: 'utf8' })); + assert.ok(Array.isArray(pages) && pages.length > 0, 'Queue metadata unavailable'); + const prs = pages.flatMap((page) => { + assert.ok(!page.errors, 'Queue metadata query failed'); + const nodes = page.data.repository.pullRequests?.nodes; + assert.ok(Array.isArray(nodes), 'Pull request metadata unavailable'); + return nodes; + }); + const matches = prs.filter((pr) => pr.mergeQueueEntry?.headCommit?.oid === group.head_sha); + assert.equal(matches.length, 1, 'Exactly one current queue candidate is required'); + const pr = matches[0]; + const entry = pr.mergeQueueEntry; + assert.equal(entry.baseCommit?.oid, group.base_sha, 'Queue candidate base changed'); + assert.equal(pr.state, 'OPEN'); + assert.equal(pr.baseRefName, 'main'); + assert.equal(pr.repository.nameWithOwner, repo); + assert.ok(Number.isSafeInteger(pr.number) && pr.number > 0); + assert.match(pr.headRefOid, /^[0-9a-f]{40}$/); + assert.match(pr.title, /^(feat|fix|perf|docs|style|refactor|test|build|ci|chore|revert)(?:\([^\r\n()]+\))?!?: \S[^\r\n]*$/, 'Queued PR title must be a Conventional Commit'); + JS - name: Validate a dispatched release PR using metadata only if: github.event_name == 'workflow_dispatch' env: diff --git a/.github/workflows/release-please.yml b/.github/workflows/release-please.yml index 807d116..dcf5c1d 100644 --- a/.github/workflows/release-please.yml +++ b/.github/workflows/release-please.yml @@ -76,9 +76,10 @@ jobs: } appendFileSync(process.env.GITHUB_STEP_SUMMARY, [ '## Release PR validation', '', ...rows, '', - 'After the intended main-branch changes are complete, review the current release PR head.', - 'A maintainer can close and reopen the PR to trigger native CI and metadata-only title validation; if it is behind main, Update branch also triggers them.', + 'Review the current release PR head. A maintainer can close and reopen the PR once to trigger native CI and metadata-only title validation.', 'Review any Approve workflows to run prompt. Confirm All checks and Conventional Commit PR title pass in the PR checks before merging.', + 'After the reviewed merge queue configuration is activated, add the PR to the native main merge queue. A branch behind main does not need Update branch: GitHub validates the integrated queue candidate.', + 'Queueing uses the maintainer account; GITHUB_TOKEN cannot enqueue it. A real Release Please head change or a failed check needs review and requeueing.', 'workflow_dispatch checks do not satisfy PR rulesets. This summary does not approve workflows, and workflow approval does not merge or publish.', 'Final publication still requires the separate owner approval in the release environment.', '', ].join('\n')); diff --git a/docs/governance.md b/docs/governance.md index 1656a3a..5726c9a 100644 --- a/docs/governance.md +++ b/docs/governance.md @@ -9,6 +9,7 @@ | Squash-only merging, read-only workflow token, SHA-pinned selected actions | Enforced | | `main`: pull request, `All checks` and PR-title checks, up-to-date branch | Enforced by the `main` ruleset; no bypass | | `main`: resolved conversations, linear history, no force push | Enforced by the `main` ruleset; no bypass | +| `main`: native merge queue | Proposed in Terraform; live activation and acceptance pending | | Release tags cannot move or be deleted | Enforced by the `release-tags` ruleset and immutable releases | | One approval from the release approver before publication | Enforced by the `release` environment; administrators cannot bypass it | | Build provenance, release attestations, secret scanning with push protection | On | @@ -170,9 +171,9 @@ Neither administrators nor automation can bypass the rulesets. If a broken requi The `main` ruleset in [`rulesets.tf`](../governance/rulesets.tf): - **No routine approving review.** A pull request is required but needs 0 approvals: this repository has one maintainer, who cannot approve their own pull request. Conversations must be resolved; stale approvals are dismissed. -- **Checks.** `All checks` and `Conventional Commit PR title` must pass, both from the GitHub Actions app (ID 15368), against a branch that is up to date with `main`. +- **Checks.** `All checks` and `Conventional Commit PR title` must pass, both from the GitHub Actions app (ID 15368). Strict required checks remain enabled; after queue activation GitHub validates the integrated queue candidate against `main` without requiring repeated updates to the PR branch. - **History.** Force pushes and deletion are blocked and history must be linear. Squash is the only merge method. -- **No merge queue,** because one maintainer gains nothing from one. +- **Native merge queue, pending activation.** `SQUASH`, `ALLGREEN`, one entry building and one merging at a time, minimum one entry, no batching wait, and a 180-minute check timeout. Later PRs wait behind the candidate instead of making the maintainer repeatedly update its branch. The timeout accommodates the mutation job and its prerequisites. - **No bypass actors.** - GitHub's default "additional approval for unattributed Copilot pull requests" stays on; the provider cannot manage it, and it has no effect while 0 approvals are required. @@ -183,12 +184,15 @@ The `main` ruleset in [`rulesets.tf`](../governance/rulesets.tf): - its name is not unique across workflows, including filtered and manually dispatched workflows, or it is a matrix or reusable-workflow job rather than one direct job; - it can be skipped, through a condition other than `always()` or through `needs` without `always()`; equivalent whitespace around the expression and its optional `${{ }}` delimiters is accepted; - its workflow does not run on `pull_request` or `pull_request_target`; +- its workflow does not also admit `merge_group` with `checks_requested`; - its workflow filters by paths, ignores branches, or has a branch filter other than exactly `[main]`; - its event `types` omit `opened`, `synchronize` or `reopened`; the title check must also include `edited` so a title-only change is revalidated; - the aggregate is not required or not unique, does not run with `always()`, or does not need every other job in its workflow. The contract inspects the aggregate's `if` and `needs`; it is not a general Actions expression evaluator and does not prove step behavior. Its step in `ci.yml` fails on any child result other than success, including cancelled and skipped. Positive and negative fixtures exercise the supported forms and rejection rules. Renaming a check requires updating its variables and tests together or the `Governance` workflow fails on that pull request. The standalone `Governance` check is not separately required by name: governance validation is required through the fail-closed `All checks` aggregate, so its failure blocks merging. +Both required workflows handle `merge_group`. CI tests the event's queue SHA in a separate concurrency group; an ordinary PR or `main` run cannot cancel it. The title job uses live GraphQL queue metadata to require exactly one entry whose `headCommit` and `baseCommit` match the event, then validates that entry's PR title. It has no checkout. Missing or changed bindings fail closed. The post-merge audit still checks admission evidence on the original PR head; GitHub's ruleset enforces checks on the integrated queue candidate. + **Release PRs require eligible native events.** A `workflow_dispatch` run, even green on the exact head, does **not** satisfy PR ruleset checks. Follow the [release PR validation procedure](releasing.md#automated-path) and @@ -197,6 +201,14 @@ events and workflow-execution approval. Those actions do not authorize publicati GitHub documents [token-generated events](https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/trigger-a-workflow#triggering-a-workflow-from-a-workflow) and [required-check event eligibility](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/troubleshooting-required-status-checks#checks-from-some-workflow-jobs-are-not-evaluated). +### Activate and verify the queue + +This change does **not** apply live settings. After its PR merges, separately authorize the operator procedure: plan against the existing state, review the addition to `github_repository_ruleset.main[0]` (live ruleset **25840882**), then explicitly approve that plan before applying it. Import that existing ruleset first if it is absent from local state; do not create a second ruleset. Retain strict checks and their app bindings, zero required PR approvals, stale-review dismissal, resolved conversations, history protections, no bypass, tag protections, and the single owner environment approval. The pinned provider 6.13.0 already supports the queue; no provider or credential change is required. + +After applying, queue two harmless ordinary PRs in FIFO order, with the second arriving while the first candidate validates. Confirm the first merges without a PR-branch update, both required checks identify its queue SHA, and the second follows. Confirm a failed required check prevents merging, and missing/stale queue metadata fails the title regression. Record the live settings and run evidence; do not use a release PR or publish during this acceptance check. Until activation is verified, the existing strict branch-update behavior remains in force. + +This follows GitHub's [native queue model](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue), also used by the pinned Release Please action's own [CI](https://github.com/googleapis/release-please-action/blob/45996ed1f6d02564a971a2fa1b5860e934307cf7/.github/workflows/ci.yaml). A separate stable release branch was considered: Release Please supports it, but it adds another protected branch and backport process and would require changing the publisher's existing `main`-ancestor contract. + ## Release approval Final publication waits for exactly one approval from the release approver, `choskeli` (user ID 98036866). The `release` environment in [`environment.tf`](../governance/environment.tf): diff --git a/docs/releasing.md b/docs/releasing.md index 47e96dd..e768fc7 100644 --- a/docs/releasing.md +++ b/docs/releasing.md @@ -166,8 +166,8 @@ rechecking boundary and composition behavior, not assuming it is unchanged. ## Automated path 1. A merge to `main` runs `release-please.yml`. Its metadata-only job creates or updates the release PR; it does not check out project code. -2. The workflow reports the generated **release PR and current head** in its job summary without launching duplicate checks. GitHub queues `GITHUB_TOKEN`-generated `pull_request` CI for workflow-execution approval, but does not trigger the metadata-only `pull_request_target` title workflow. Moreover, dispatched workflow checks [do not satisfy PR rulesets](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/troubleshooting-required-status-checks#checks-from-some-workflow-jobs-are-not-evaluated), even when green on that head. After the intended main-branch changes are complete, review the finalized release PR; a maintainer can **close and reopen** it to trigger native CI and title validation, or **Update branch** if it is behind `main`. Review any **Approve workflows to run** prompt and confirm **All checks** and **Conventional Commit PR title** pass in the PR checks. Recheck the head after any update; earlier-head or manual-dispatch success is not admission evidence. Workflow execution approval neither merges the PR nor publishes a release. -3. Review and squash merge the release PR. Release Please creates a **draft release** and, with `force-tag-creation`, creates its `vX.Y.Z` tag while it is still a draft. +2. The workflow reports the generated **release PR and current head** without launching duplicate checks. Initial bot-created checks may need a maintainer to **close and reopen** the PR and review an **Approve workflows to run** prompt. Confirm **All checks** and **Conventional Commit PR title** pass on the current PR head; earlier-head or separately dispatched success is not admission evidence. Dispatched workflow checks [do not satisfy PR rulesets](https://docs.github.com/en/pull-requests/how-tos/merge-and-close-pull-requests/troubleshooting-required-status-checks#checks-from-some-workflow-jobs-are-not-evaluated). This workflow-execution decision does not approve publication. +3. After [queue activation](governance.md#activate-and-verify-the-queue), review and **enqueue** the release PR using the maintainer's existing GitHub account; `GITHUB_TOKEN` cannot enqueue it. GitHub tests the integrated queue SHA and squash merges only after both required checks pass. Later PRs wait behind it; ordinary `main` advancement requires no repeated **Update branch** clicks. Release Please continues updating versions and changelogs: a genuine release-PR head change invalidates the candidate and needs fresh checks and requeueing. Release Please then creates a **draft release** and, with `force-tag-creation`, creates its `vX.Y.Z` tag while it is still a draft. 4. The workflow dispatches `publish-release.yml` **at that exact tag**, passing its full commit SHA. Preflight requires a matching draft, a matching tag commit already reachable from `main`, and `GITHUB_SHA` equal to the declared source commit. Dispatching from `main` is rejected. 5. The reusable, read-only CI validates that commit. It checks Node 24 and 26, npm compatibility, formatting, lint, both TypeScript compilers, coverage, tooling, mutation testing, fuzzing, dependency audits, static analysis, secrets, and measured memory/HTTP behavior. The Node 24 release lane packages the existing compiled output and tests the unpacked artifact; the publisher never rebuilds it. 6. Native notes preparation independently verifies the same release range. The candidate job seals the tested runtime and both notes views, with immutable input identities and checksums, into one artifact. Build provenance attests every sealed file. @@ -175,6 +175,17 @@ rechecking boundary and composition behavior, not assuming it is unchanged. The version verifier requires agreement between `package.json`, both lockfile root versions, the release manifest, and the supplied release tag. In CI, the recorded source commit must equal the checked-out Git HEAD. Tag-based invocation also keeps the standard attestation's workflow commit aligned with the actual build source. +The stable publication candidate is the exact tagged merge commit, which may be +an ancestor of a newer `main`; it need not remain the branch tip during validation +or owner approval. The queue handles integration before that point, without a +manual freeze of `main`. CI validates the queue SHA in its own concurrency group; +the metadata-only title check binds live GraphQL `headCommit`/`baseCommit` to the +queue event without checking out code. Changed or missing bindings fail closed. +The queue configuration is proposed, **not applied**: follow the separately +approved activation and nonpublishing acceptance procedure in +[governance](governance.md#activate-and-verify-the-queue). Until then, existing +strict branch-update requirements still apply. + ## Published files | File | Contents | @@ -204,7 +215,7 @@ The runtime archive is deliberately assembled from compiled output; `npm pack` i | Provenance | `id-token: write` and `attestations: write`; downloads tested assets, no project checkout/build | | Publication | `contents: write` and `actions: read`; downloads and uploads tested assets, no rebuilding | -Workflow actions are pinned by commit. Optional CLI update notices and OpenTelemetry are disabled (`GH_NO_UPDATE_NOTIFIER`, `GH_NO_EXTENSION_UPDATE_NOTIFIER`, `DO_NOT_TRACK`, `OTEL_SDK_DISABLED`). Required GitHub API, artifact and attestation service traffic and service-side audit logs remain; these controls do not claim otherwise. Ordinary PR title validation uses `pull_request_target` only to inspect metadata; it never executes PR code. The optional dispatched title check is diagnostic only; it cannot satisfy a PR ruleset. +Workflow actions are pinned by commit. Optional CLI update notices and OpenTelemetry are disabled (`GH_NO_UPDATE_NOTIFIER`, `GH_NO_EXTENSION_UPDATE_NOTIFIER`, `DO_NOT_TRACK`, `OTEL_SDK_DISABLED`). Required GitHub API, artifact and attestation service traffic and service-side audit logs remain; these controls do not claim otherwise. Ordinary PR title validation uses `pull_request_target` and queue title validation uses `merge_group` only to inspect metadata; neither executes PR code. The optional dispatched title check is diagnostic only; it cannot satisfy a PR ruleset. ## Repository settings @@ -212,7 +223,7 @@ Terraform in [`governance/`](../governance/) manages the repository's settings; - Squash merging only, titled by the PR title with a blank body; merged branches are deleted. - The default `GITHUB_TOKEN` is read-only; only GitHub-owned, verified-creator and the two listed third-party actions may run, each pinned to a full commit SHA. -- The `main` ruleset requires a pull request, passing `All checks` and `Conventional Commit PR title` checks on an up-to-date branch, resolved conversations, and linear history; it blocks force pushes and deletion and has no bypass. +- The `main` ruleset requires a pull request with zero mandatory PR approvals, passing `All checks` and `Conventional Commit PR title`, strict checks, resolved conversations, and linear history; it blocks force pushes and deletion and has no bypass. Proposed queue settings add one candidate at a time (`SQUASH`, `ALLGREEN`, build/merge/minimum counts 1, wait 0, timeout 180 minutes); activation is separate. - `v*` tags cannot be moved or deleted, and publication waits for the release approver in the `release` environment. - Workflows from forks wait for approval before running, and never receive write tokens or secrets. @@ -231,6 +242,10 @@ The `main` ruleset enforces the merge policy. `main-policy-audit.yml` remains a It warns when the PR had no approval from someone other than its author. A failed audit means the policy was bypassed after the fact; investigate it and correct `main` through a new PR. Release publication separately revalidates the exact tagged commit, so an unchecked merge cannot publish without passing CI. +The audit deliberately retains the original PR-head admission evidence. Native +queue validation uses a different integrated SHA, enforced by the ruleset; the +audit does not substitute original-head checks for that queue validation. + ## Local verification From a clean checkout with Node 24 and the documented npm 11.19.0. Archive packaging uses **GNU tar on Linux**, matching the GitHub runner: @@ -273,7 +288,8 @@ dependencies, upload an MP3, and stop the server with `SIGTERM`. ## Recover from a failed release -- **Release PR validation failed or required checks are absent:** fix any source defect in an ordinary PR and finish the intended main-branch batch before validating the release PR again. Review its current head, then close and reopen it as a maintainer to trigger both native CI and metadata-only title validation; **Update branch** is another option when it is behind `main`. Review any workflow-execution approval prompt and verify both required checks in the PR, not a separate manual dispatch. A GitHub App installation token can automate eligible events without recurring prompts, but configuring one is optional and requires separate credential/permission approval; it is not required for this maintainer path. Publication still revalidates the exact tag and waits for separate final owner approval. +- **Release PR checks are absent:** review its current head, close and reopen it as a maintainer to trigger native CI and metadata-only title validation, and review any workflow-execution approval prompt. Verify both required checks in the PR, not a separate manual dispatch, then enqueue it after queue activation. This uses the existing account and needs no new credential. +- **Queue validation failed or the release PR changed:** investigate the failed check, fix source defects through an ordinary PR, and let Release Please update the version/changelog when needed. Review the new head and its fresh checks before requeueing. Genuine candidate changes cannot reuse earlier checks; ordinary advancement of `main` alone does not require manually updating the release branch. Publication still validates the exact tag and waits for one final owner approval. - **Publication failed after the draft and tag were created:** a retry runs the workflows and source from the tag, so changes merged to `main` cannot repair it. Retry the draft as shown below for transient failures, such as a runner or network error. If the tagged source or its workflows are defective, leave the draft unpublished, merge the fix, and let Release Please propose the next version. Never move or recreate a release tag. - **A published release is defective:** published releases are immutable. Merge a correction and release a new version. diff --git a/governance/checks.tf b/governance/checks.tf index 282fcb8..d5b1809 100644 --- a/governance/checks.tf +++ b/governance/checks.tf @@ -1,5 +1,5 @@ # Required checks must come from jobs that report under their own name on -# every pull request into main. Requiring a check that never reports blocks +# every pull request and merge group into main. A check that never reports blocks # every merge, and GitHub counts a skipped check as passing. locals { commit_changing_activities = ["opened", "synchronize", "reopened"] @@ -38,6 +38,25 @@ locals { ]) ] + merge_group_filters = { + for name, on in local.triggers : name => [ + for event in try(keys(on), flatten([on])) : coalesce(try(on[event], null), {}) + if event == "merge_group" + ] + } + + # GitHub requires the same check names on the queue's checks_requested SHA. + # Only an unfiltered event or an exact main branch filter is supported. + every_merge_group_workflows = [ + for name, filters in local.merge_group_filters : name + if length(filters) > 0 && alltrue([ + for filter in filters : + length(setsubtract(keys(filter), ["branches", "types"])) == 0 && + (!contains(keys(filter), "branches") || try(toset(filter.branches) == toset(["main"]), false)) && + contains(try(filter.types, ["checks_requested"]), "checks_requested") + ]) + ] + # Check-name collisions matter across workflows, including filtered and # manually dispatched workflows, not only the eligible required-check jobs. workflow_jobs = flatten([ @@ -68,7 +87,7 @@ locals { # A job without a condition still skips when a job it needs fails. always_reporting_checks = [ for job in local.every_pull_request_jobs : job.name - if !job.renamed && ( + if contains(local.every_merge_group_workflows, job.workflow) && !job.renamed && ( job.always || (job.condition == null && length(job.needs) == 0) ) && (job.name != var.title_status_check || alltrue([ @@ -93,7 +112,7 @@ output "required_status_checks" { contains(local.always_reporting_checks, check) && length([for job in local.workflow_jobs : job.name if job.name == check]) == 1 ]) - error_message = "Every required check must have one unique, unskippable job name across workflows and report on every pull request into main. The title check must also report on edited events." + error_message = "Every required check must have one unique, unskippable job name across workflows and report on every pull request and merge_group checks_requested event into main. The title check must also report on edited events." } } diff --git a/governance/rulesets.tf b/governance/rulesets.tf index 1297c1c..483dbf2 100644 --- a/governance/rulesets.tf +++ b/governance/rulesets.tf @@ -32,6 +32,19 @@ resource "github_repository_ruleset" "main" { allowed_merge_methods = ["squash"] } + # Native queue validation owns the changing base. One candidate at a time + # avoids speculative full campaigns and lets later PRs wait behind it. + merge_queue { + merge_method = "SQUASH" + grouping_strategy = "ALLGREEN" + max_entries_to_build = 1 + max_entries_to_merge = 1 + min_entries_to_merge = 1 + min_entries_to_merge_wait_minutes = 0 + # The mutation job alone permits 100 minutes, in addition to its needs. + check_response_timeout_minutes = 180 + } + required_status_checks { strict_required_status_checks_policy = true do_not_enforce_on_create = false diff --git a/governance/tests/fixtures/aggregate-duplicated/ci.yml b/governance/tests/fixtures/aggregate-duplicated/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/aggregate-duplicated/ci.yml +++ b/governance/tests/fixtures/aggregate-duplicated/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/aggregate-duplicated/pr-title.yml b/governance/tests/fixtures/aggregate-duplicated/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/aggregate-duplicated/pr-title.yml +++ b/governance/tests/fixtures/aggregate-duplicated/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/aggregate-duplicated/second.yml b/governance/tests/fixtures/aggregate-duplicated/second.yml index f687cb6..20848f5 100644 --- a/governance/tests/fixtures/aggregate-duplicated/second.yml +++ b/governance/tests/fixtures/aggregate-duplicated/second.yml @@ -1,5 +1,5 @@ name: Second -on: pull_request +on: [pull_request, merge_group] jobs: lint: runs-on: ubuntu-latest diff --git a/governance/tests/fixtures/aggregate-misses-job/ci.yml b/governance/tests/fixtures/aggregate-misses-job/ci.yml index 91c911f..d7eaa31 100644 --- a/governance/tests/fixtures/aggregate-misses-job/ci.yml +++ b/governance/tests/fixtures/aggregate-misses-job/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/aggregate-misses-job/pr-title.yml b/governance/tests/fixtures/aggregate-misses-job/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/aggregate-misses-job/pr-title.yml +++ b/governance/tests/fixtures/aggregate-misses-job/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/aggregate-skippable/ci.yml b/governance/tests/fixtures/aggregate-skippable/ci.yml index e1d4581..ea4ee51 100644 --- a/governance/tests/fixtures/aggregate-skippable/ci.yml +++ b/governance/tests/fixtures/aggregate-skippable/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/aggregate-skippable/pr-title.yml b/governance/tests/fixtures/aggregate-skippable/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/aggregate-skippable/pr-title.yml +++ b/governance/tests/fixtures/aggregate-skippable/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/aggregate-without-if/ci.yml b/governance/tests/fixtures/aggregate-without-if/ci.yml index 87dc3cc..8d7682e 100644 --- a/governance/tests/fixtures/aggregate-without-if/ci.yml +++ b/governance/tests/fixtures/aggregate-without-if/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/aggregate-without-if/pr-title.yml b/governance/tests/fixtures/aggregate-without-if/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/aggregate-without-if/pr-title.yml +++ b/governance/tests/fixtures/aggregate-without-if/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/always-compact/ci.yml b/governance/tests/fixtures/always-compact/ci.yml index f5ba728..5090588 100644 --- a/governance/tests/fixtures/always-compact/ci.yml +++ b/governance/tests/fixtures/always-compact/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/always-compact/pr-title.yml b/governance/tests/fixtures/always-compact/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/always-compact/pr-title.yml +++ b/governance/tests/fixtures/always-compact/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/always-spaced/ci.yml b/governance/tests/fixtures/always-spaced/ci.yml index 914e0b4..fd6c5a9 100644 --- a/governance/tests/fixtures/always-spaced/ci.yml +++ b/governance/tests/fixtures/always-spaced/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/always-spaced/pr-title.yml b/governance/tests/fixtures/always-spaced/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/always-spaced/pr-title.yml +++ b/governance/tests/fixtures/always-spaced/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/check-conditional/ci.yml b/governance/tests/fixtures/check-conditional/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/check-conditional/ci.yml +++ b/governance/tests/fixtures/check-conditional/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/check-conditional/pr-title.yml b/governance/tests/fixtures/check-conditional/pr-title.yml index 165205f..8fe582a 100644 --- a/governance/tests/fixtures/check-conditional/pr-title.yml +++ b/governance/tests/fixtures/check-conditional/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/check-filtered-by-paths/ci.yml b/governance/tests/fixtures/check-filtered-by-paths/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/check-filtered-by-paths/ci.yml +++ b/governance/tests/fixtures/check-filtered-by-paths/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/check-filtered-by-paths/pr-title.yml b/governance/tests/fixtures/check-filtered-by-paths/pr-title.yml index 00157e6..9d7e575 100644 --- a/governance/tests/fixtures/check-filtered-by-paths/pr-title.yml +++ b/governance/tests/fixtures/check-filtered-by-paths/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: paths: [src/**] types: [opened, edited, reopened, synchronize] diff --git a/governance/tests/fixtures/check-from-matrix/ci.yml b/governance/tests/fixtures/check-from-matrix/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/check-from-matrix/ci.yml +++ b/governance/tests/fixtures/check-from-matrix/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/check-from-matrix/matrix.yml b/governance/tests/fixtures/check-from-matrix/matrix.yml index 6a015b9..0dffa4c 100644 --- a/governance/tests/fixtures/check-from-matrix/matrix.yml +++ b/governance/tests/fixtures/check-from-matrix/matrix.yml @@ -1,5 +1,5 @@ name: Matrix -on: pull_request +on: [pull_request, merge_group] jobs: test: name: Matrix check diff --git a/governance/tests/fixtures/check-from-matrix/pr-title.yml b/governance/tests/fixtures/check-from-matrix/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/check-from-matrix/pr-title.yml +++ b/governance/tests/fixtures/check-from-matrix/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/check-types-skip-commits/ci.yml b/governance/tests/fixtures/check-types-skip-commits/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/check-types-skip-commits/ci.yml +++ b/governance/tests/fixtures/check-types-skip-commits/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/check-types-skip-commits/pr-title.yml b/governance/tests/fixtures/check-types-skip-commits/pr-title.yml index 6a81508..43aa190 100644 --- a/governance/tests/fixtures/check-types-skip-commits/pr-title.yml +++ b/governance/tests/fixtures/check-types-skip-commits/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited] jobs: diff --git a/governance/tests/fixtures/check-with-needs/ci.yml b/governance/tests/fixtures/check-with-needs/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/check-with-needs/ci.yml +++ b/governance/tests/fixtures/check-with-needs/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/check-with-needs/pr-title.yml b/governance/tests/fixtures/check-with-needs/pr-title.yml index 2690ac8..b48cb5e 100644 --- a/governance/tests/fixtures/check-with-needs/pr-title.yml +++ b/governance/tests/fixtures/check-with-needs/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/filtered-aggregate-duplicated/ci.yml b/governance/tests/fixtures/filtered-aggregate-duplicated/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/filtered-aggregate-duplicated/ci.yml +++ b/governance/tests/fixtures/filtered-aggregate-duplicated/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/filtered-aggregate-duplicated/pr-title.yml b/governance/tests/fixtures/filtered-aggregate-duplicated/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/filtered-aggregate-duplicated/pr-title.yml +++ b/governance/tests/fixtures/filtered-aggregate-duplicated/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/filtered-aggregate-duplicated/second.yml b/governance/tests/fixtures/filtered-aggregate-duplicated/second.yml index fd3b5b0..2e12a4b 100644 --- a/governance/tests/fixtures/filtered-aggregate-duplicated/second.yml +++ b/governance/tests/fixtures/filtered-aggregate-duplicated/second.yml @@ -1,5 +1,7 @@ name: Filtered duplicate on: + merge_group: + types: [checks_requested] pull_request: paths: [docs/**] jobs: diff --git a/governance/tests/fixtures/ignored-main/ci.yml b/governance/tests/fixtures/ignored-main/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/ignored-main/ci.yml +++ b/governance/tests/fixtures/ignored-main/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/ignored-main/pr-title.yml b/governance/tests/fixtures/ignored-main/pr-title.yml index 5b86d7f..6b7928c 100644 --- a/governance/tests/fixtures/ignored-main/pr-title.yml +++ b/governance/tests/fixtures/ignored-main/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: branches-ignore: [main] types: [opened, edited, reopened, synchronize] diff --git a/governance/tests/fixtures/main-only-branches/ci.yml b/governance/tests/fixtures/main-only-branches/ci.yml index 9080506..12c74c5 100644 --- a/governance/tests/fixtures/main-only-branches/ci.yml +++ b/governance/tests/fixtures/main-only-branches/ci.yml @@ -1,5 +1,8 @@ name: CI on: + merge_group: + branches: [main] + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/main-only-branches/pr-title.yml b/governance/tests/fixtures/main-only-branches/pr-title.yml index 18687f3..6341600 100644 --- a/governance/tests/fixtures/main-only-branches/pr-title.yml +++ b/governance/tests/fixtures/main-only-branches/pr-title.yml @@ -1,5 +1,8 @@ name: PR title on: + merge_group: + branches: [main] + types: [checks_requested] pull_request_target: branches: [main] types: [opened, edited, reopened, synchronize] diff --git a/governance/tests/fixtures/queue-filtered-paths/ci.yml b/governance/tests/fixtures/queue-filtered-paths/ci.yml new file mode 100644 index 0000000..b0887e5 --- /dev/null +++ b/governance/tests/fixtures/queue-filtered-paths/ci.yml @@ -0,0 +1,24 @@ +name: CI +on: + merge_group: + types: [checks_requested] + push: + branches: [main] + pull_request: +jobs: + quality: + name: Quality + runs-on: ubuntu-latest + steps: + - run: 'true' + security: + runs-on: ubuntu-latest + steps: + - run: 'true' + all-checks: + name: All checks + if: always() + needs: [quality, security] + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/queue-filtered-paths/pr-title.yml b/governance/tests/fixtures/queue-filtered-paths/pr-title.yml new file mode 100644 index 0000000..56918d9 --- /dev/null +++ b/governance/tests/fixtures/queue-filtered-paths/pr-title.yml @@ -0,0 +1,13 @@ +name: PR title +on: + merge_group: + paths: [src/**] + types: [checks_requested] + pull_request_target: + types: [opened, edited, reopened, synchronize] +jobs: + title: + name: Conventional Commit PR title + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/queue-title-missing/ci.yml b/governance/tests/fixtures/queue-title-missing/ci.yml new file mode 100644 index 0000000..b0887e5 --- /dev/null +++ b/governance/tests/fixtures/queue-title-missing/ci.yml @@ -0,0 +1,24 @@ +name: CI +on: + merge_group: + types: [checks_requested] + push: + branches: [main] + pull_request: +jobs: + quality: + name: Quality + runs-on: ubuntu-latest + steps: + - run: 'true' + security: + runs-on: ubuntu-latest + steps: + - run: 'true' + all-checks: + name: All checks + if: always() + needs: [quality, security] + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/queue-title-missing/pr-title.yml b/governance/tests/fixtures/queue-title-missing/pr-title.yml new file mode 100644 index 0000000..b4e2dbc --- /dev/null +++ b/governance/tests/fixtures/queue-title-missing/pr-title.yml @@ -0,0 +1,10 @@ +name: PR title +on: + pull_request_target: + types: [opened, edited, reopened, synchronize] +jobs: + title: + name: Conventional Commit PR title + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/queue-wrong-activity/ci.yml b/governance/tests/fixtures/queue-wrong-activity/ci.yml new file mode 100644 index 0000000..b0887e5 --- /dev/null +++ b/governance/tests/fixtures/queue-wrong-activity/ci.yml @@ -0,0 +1,24 @@ +name: CI +on: + merge_group: + types: [checks_requested] + push: + branches: [main] + pull_request: +jobs: + quality: + name: Quality + runs-on: ubuntu-latest + steps: + - run: 'true' + security: + runs-on: ubuntu-latest + steps: + - run: 'true' + all-checks: + name: All checks + if: always() + needs: [quality, security] + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/queue-wrong-activity/pr-title.yml b/governance/tests/fixtures/queue-wrong-activity/pr-title.yml new file mode 100644 index 0000000..3a8bbe9 --- /dev/null +++ b/governance/tests/fixtures/queue-wrong-activity/pr-title.yml @@ -0,0 +1,12 @@ +name: PR title +on: + merge_group: + types: [destroyed] + pull_request_target: + types: [opened, edited, reopened, synchronize] +jobs: + title: + name: Conventional Commit PR title + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/queue-wrong-branch/ci.yml b/governance/tests/fixtures/queue-wrong-branch/ci.yml new file mode 100644 index 0000000..b0887e5 --- /dev/null +++ b/governance/tests/fixtures/queue-wrong-branch/ci.yml @@ -0,0 +1,24 @@ +name: CI +on: + merge_group: + types: [checks_requested] + push: + branches: [main] + pull_request: +jobs: + quality: + name: Quality + runs-on: ubuntu-latest + steps: + - run: 'true' + security: + runs-on: ubuntu-latest + steps: + - run: 'true' + all-checks: + name: All checks + if: always() + needs: [quality, security] + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/queue-wrong-branch/pr-title.yml b/governance/tests/fixtures/queue-wrong-branch/pr-title.yml new file mode 100644 index 0000000..18d0047 --- /dev/null +++ b/governance/tests/fixtures/queue-wrong-branch/pr-title.yml @@ -0,0 +1,13 @@ +name: PR title +on: + merge_group: + branches: [release] + types: [checks_requested] + pull_request_target: + types: [opened, edited, reopened, synchronize] +jobs: + title: + name: Conventional Commit PR title + runs-on: ubuntu-latest + steps: + - run: 'true' diff --git a/governance/tests/fixtures/required-check-duplicated/ci.yml b/governance/tests/fixtures/required-check-duplicated/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/required-check-duplicated/ci.yml +++ b/governance/tests/fixtures/required-check-duplicated/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/required-check-duplicated/pr-title.yml b/governance/tests/fixtures/required-check-duplicated/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/required-check-duplicated/pr-title.yml +++ b/governance/tests/fixtures/required-check-duplicated/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/title-without-edited/ci.yml b/governance/tests/fixtures/title-without-edited/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/title-without-edited/ci.yml +++ b/governance/tests/fixtures/title-without-edited/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/title-without-edited/pr-title.yml b/governance/tests/fixtures/title-without-edited/pr-title.yml index 668b68c..2b7aacb 100644 --- a/governance/tests/fixtures/title-without-edited/pr-title.yml +++ b/governance/tests/fixtures/title-without-edited/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/trigger-forms/ci.yml b/governance/tests/fixtures/trigger-forms/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/trigger-forms/ci.yml +++ b/governance/tests/fixtures/trigger-forms/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/trigger-forms/listed.yml b/governance/tests/fixtures/trigger-forms/listed.yml index 7a1f07b..057ade9 100644 --- a/governance/tests/fixtures/trigger-forms/listed.yml +++ b/governance/tests/fixtures/trigger-forms/listed.yml @@ -1,5 +1,5 @@ name: Listed -on: [push, pull_request] +on: [push, pull_request, merge_group] jobs: check: name: Listed check diff --git a/governance/tests/fixtures/trigger-forms/pr-title.yml b/governance/tests/fixtures/trigger-forms/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/trigger-forms/pr-title.yml +++ b/governance/tests/fixtures/trigger-forms/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/valid/ci.yml b/governance/tests/fixtures/valid/ci.yml index 12b0970..b0887e5 100644 --- a/governance/tests/fixtures/valid/ci.yml +++ b/governance/tests/fixtures/valid/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/valid/pr-title.yml b/governance/tests/fixtures/valid/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/valid/pr-title.yml +++ b/governance/tests/fixtures/valid/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/fixtures/wrong-branch/ci.yml b/governance/tests/fixtures/wrong-branch/ci.yml index 13d9d4b..8ec2085 100644 --- a/governance/tests/fixtures/wrong-branch/ci.yml +++ b/governance/tests/fixtures/wrong-branch/ci.yml @@ -1,5 +1,7 @@ name: CI on: + merge_group: + types: [checks_requested] push: branches: [main] pull_request: diff --git a/governance/tests/fixtures/wrong-branch/pr-title.yml b/governance/tests/fixtures/wrong-branch/pr-title.yml index b4e2dbc..1877c06 100644 --- a/governance/tests/fixtures/wrong-branch/pr-title.yml +++ b/governance/tests/fixtures/wrong-branch/pr-title.yml @@ -1,5 +1,7 @@ name: PR title on: + merge_group: + types: [checks_requested] pull_request_target: types: [opened, edited, reopened, synchronize] jobs: diff --git a/governance/tests/policy.tftest.hcl b/governance/tests/policy.tftest.hcl index 7772604..d7aa3f8 100644 --- a/governance/tests/policy.tftest.hcl +++ b/governance/tests/policy.tftest.hcl @@ -213,6 +213,30 @@ run "spaced_always_expression_is_accepted" { variables { workflow_directory = "tests/fixtures/always-spaced" } } +run "queue_must_report_the_title_check_too" { + command = plan + variables { workflow_directory = "tests/fixtures/queue-title-missing" } + expect_failures = [output.required_status_checks] +} + +run "queue_must_request_checks" { + command = plan + variables { workflow_directory = "tests/fixtures/queue-wrong-activity" } + expect_failures = [output.required_status_checks] +} + +run "queue_cannot_filter_out_main" { + command = plan + variables { workflow_directory = "tests/fixtures/queue-wrong-branch" } + expect_failures = [output.required_status_checks] +} + +run "queue_cannot_omit_paths" { + command = plan + variables { workflow_directory = "tests/fixtures/queue-filtered-paths" } + expect_failures = [output.required_status_checks] +} + run "rulesets_can_be_disabled_in_an_emergency" { command = plan @@ -264,6 +288,19 @@ run "main_ruleset_requires_checks_not_reviews" { error_message = "Pull requests must need no approving review, dismiss stale approvals, require resolved conversations, and squash merge." } + assert { + condition = ( + github_repository_ruleset.main[0].rules[0].merge_queue[0].merge_method == "SQUASH" && + github_repository_ruleset.main[0].rules[0].merge_queue[0].grouping_strategy == "ALLGREEN" && + github_repository_ruleset.main[0].rules[0].merge_queue[0].max_entries_to_build == 1 && + github_repository_ruleset.main[0].rules[0].merge_queue[0].max_entries_to_merge == 1 && + github_repository_ruleset.main[0].rules[0].merge_queue[0].min_entries_to_merge == 1 && + github_repository_ruleset.main[0].rules[0].merge_queue[0].min_entries_to_merge_wait_minutes == 0 && + github_repository_ruleset.main[0].rules[0].merge_queue[0].check_response_timeout_minutes == 180 + ) + error_message = "The native queue must validate and squash one candidate at a time with room for the complete CI gate." + } + assert { condition = ( github_repository_ruleset.main[0].rules[0].required_status_checks[0].strict_required_status_checks_policy && diff --git a/governance/variables.tf b/governance/variables.tf index 6c32e69..8775023 100644 --- a/governance/variables.tf +++ b/governance/variables.tf @@ -16,7 +16,7 @@ variable "require_signed_commits" { } variable "required_status_checks" { - description = "Check runs every pull request into main must pass. Each must be a job name in a workflow that runs for every pull request." + description = "Check runs every pull request and merge group into main must pass. Each must be a job name in a workflow that runs for both events." type = list(string) default = ["All checks", "Conventional Commit PR title"] diff --git a/scripts/ci-workflow.test.mjs b/scripts/ci-workflow.test.mjs index 79e34bb..bdf171a 100644 --- a/scripts/ci-workflow.test.mjs +++ b/scripts/ci-workflow.test.mjs @@ -149,6 +149,22 @@ test('exact-source release validation is isolated and never cancels in progress' assert.notEqual(result.group, concurrency(values).group); }); +test('a new main arrival cannot replace validation of the native queue candidate', () => { + const queued = context({ event: 'merge_group', ref: 'refs/heads/gh-readonly-queue/main/pr-15' }); + queued.github.sha = 'a'.repeat(40); + const initial = concurrency(queued); + assert.equal(initial.group, `ci-queue-${queued.github.sha}`); + const main = context({ event: 'push', ref: 'refs/heads/main', run: 2 }); + main.github.sha = 'b'.repeat(40); + assert.notEqual(concurrency(main).group, initial.group); + // Native candidate replacement gets its own exact SHA; no PR branch update is dispatched. + const replacement = structuredClone(queued); + replacement.github.sha = 'c'.repeat(40); + assert.notEqual(concurrency(replacement).group, initial.group); + assert.deepEqual(parse(ci).on.merge_group, { types: ['checks_requested'] }); + assert.doesNotMatch(ci, /update-branch|gh pr merge/); +}); + test('the stable aggregate needs exactly every native validation job', () => { const jobs = [...ci.slice(ci.indexOf('jobs:\n')).matchAll(/^ {2}([a-z][a-z0-9-]+):$/gm)] .map((match) => match[1]) diff --git a/scripts/main-policy-audit.test.mjs b/scripts/main-policy-audit.test.mjs index ef8a0ce..6bbfd64 100644 --- a/scripts/main-policy-audit.test.mjs +++ b/scripts/main-policy-audit.test.mjs @@ -216,6 +216,50 @@ test('commit audit needs no approval; unavailable optional history is explicit a assert.notEqual(auditCommit(commit, repo, completeApi({ checks: [] })).failures.length, 0); }); +test('PR admission evidence stays bound to its head when main advances during validation', () => { + // A merge queue validates a separate integration candidate. This detective + // audit retains the PR admission checks; the native ruleset enforces the + // additional queue checks. This fixture does not simulate GitHub's queue. + const advancedMain = 'd'.repeat(40); + const landed = { ...commit, parents: [{ sha: advancedMain }] }; + const paths = []; + const original = completeApi(); + const api = { + ...original, + list(path, field) { + paths.push(path); + return original.list(path, field); + }, + }; + const result = auditCommit(landed, repo, api); + assert.deepEqual(result.failures, []); + assert.equal(result.head, head); + assert.deepEqual( + paths.filter((path) => path.endsWith('/check-suites')), + [`repos/${repo}/commits/${head}/check-suites`], + ); + // Green evidence from main or a queue candidate cannot replace a missing or + // failed check on the admitted PR head, nor can a later rerun cure it. + for (const replacement of [ + checks().map((run) => ({ ...run, head_sha: advancedMain })), + checks().map((run) => ({ ...run, head_sha: sha })), + [ + ...checks().map((run) => ({ ...run, conclusion: 'failure' })), + ...checks().map((run) => ({ + ...run, + id: run.id + 10, + started_at: late, + completed_at: late, + })), + ], + ]) { + assert.notEqual( + auditCommit(landed, repo, completeApi({ checks: replacement })).failures.length, + 0, + ); + } +}); + test('push audit rejects forced, direct and non-squash history without logging untrusted subjects', () => { assert.notEqual( auditPush({ repo, before, after: sha, forced: true }, completeApi()).failures.length, diff --git a/scripts/merge-queue-title.test.mjs b/scripts/merge-queue-title.test.mjs new file mode 100644 index 0000000..48e3e3a --- /dev/null +++ b/scripts/merge-queue-title.test.mjs @@ -0,0 +1,149 @@ +import assert from 'node:assert/strict'; +import { readFile } from 'node:fs/promises'; +import { test } from 'node:test'; +import { runInNewContext } from 'node:vm'; +import { parse } from 'yaml'; + +const title = parse( + await readFile(new URL('../.github/workflows/pr-title.yml', import.meta.url), 'utf8'), +); +const step = title.jobs.title.steps.find( + (item) => item.if === "github.event_name == 'merge_group'", +); +const source = step.run.match(/<<'JS'\n([\s\S]+)\nJS\n?$/)[1].replace(/^import .+;\n/gm, ''); +const repo = 'example/project'; +const head = 'a'.repeat(40); +const base = 'b'.repeat(40); +const event = () => ({ + action: 'checks_requested', + repository: { full_name: repo }, + merge_group: { base_ref: 'refs/heads/main', head_sha: head, base_sha: base }, +}); +const candidate = () => ({ + number: 15, + title: 'chore(main): release 2.2.1', + state: 'OPEN', + baseRefName: 'main', + headRefOid: 'c'.repeat(40), + repository: { nameWithOwner: repo }, + mergeQueueEntry: { + headCommit: { oid: head }, + baseCommit: { oid: base }, + }, +}); +const page = (nodes) => ({ data: { repository: { pullRequests: { nodes } } } }); + +function run({ + payload = event(), + pages = [page([candidate()])], + sha = head, + apiError = false, +} = {}) { + const calls = []; + runInNewContext(source, { + assert, + process: { env: { GH_REPO: repo, GITHUB_SHA: sha, GITHUB_EVENT_PATH: 'event.json' } }, + readFileSync: (path) => { + assert.equal(path, 'event.json'); + return JSON.stringify(payload); + }, + execFileSync: (command, args) => { + calls.push([command, ...args]); + if (apiError) throw new Error('API unavailable'); + return JSON.stringify(pages); + }, + }); + return calls; +} + +test('queue title check uses live candidate metadata without executing PR code or assuming a PR event', () => { + assert.deepEqual(title.on.merge_group, { types: ['checks_requested'] }); + assert.deepEqual(title.permissions, { 'pull-requests': 'read' }); + assert.doesNotMatch(JSON.stringify(title), /checkout@|:write|update-branch/); + assert.equal(title.jobs.title.steps[0].if, "github.event_name == 'pull_request_target'"); + const [call] = run(); + assert.equal(call[0], 'gh'); + assert.ok(call.includes('--paginate') && call.includes('--slurp')); + assert.ok(call.some((arg) => arg.includes('$endCursor') && arg.includes('after:$endCursor'))); + assert.ok(call.some((arg) => arg.includes('pageInfo { hasNextPage endCursor }'))); + assert.ok(call.some((arg) => arg.includes('pullRequests(states:OPEN,baseRefName:"main"'))); + assert.ok(call.some((arg) => arg.includes('mergeQueueEntry { headCommit { oid }'))); + assert.ok(call.every((arg) => !arg.includes('mergeQueue('))); +}); + +test('later main activity and unrelated queue entries do not substitute for the exact candidate', () => { + const unrelated = candidate(); + unrelated.mergeQueueEntry.headCommit.oid = 'd'.repeat(40); + unrelated.title = 'invalid unrelated title'; + const unqueued = { ...candidate(), mergeQueueEntry: null }; + assert.equal(run({ pages: [page([unrelated, unqueued]), page([candidate()])] }).length, 1); + assert.throws(() => run({ pages: [page([unrelated])] }), /current queue candidate/); +}); + +test('missing, duplicate, superseded, malformed and unavailable queue candidates fail closed', () => { + for (const pages of [ + [], + {}, + [page([])], + [page([candidate(), candidate()])], + [{ data: { repository: { pullRequests: null } } }], + [{ ...page([candidate()]), errors: [{ message: 'incomplete query' }] }], + ]) + assert.throws(() => run({ pages })); + assert.throws(() => run({ apiError: true }), /API unavailable/); + for (const modify of [ + (value) => { + value.mergeQueueEntry.baseCommit.oid = 'd'.repeat(40); + }, + (value) => { + value.mergeQueueEntry.headCommit = null; + }, + (value) => { + value.mergeQueueEntry = null; + }, + (value) => { + value.state = 'CLOSED'; + }, + (value) => { + value.baseRefName = 'other'; + }, + (value) => { + value.repository.nameWithOwner = 'other/project'; + }, + (value) => { + value.headRefOid = 'short'; + }, + (value) => { + value.title = 'not conventional'; + }, + (value) => { + value.title = 'fix: valid\nspoofed'; + }, + ]) { + const value = candidate(); + modify(value); + assert.throws(() => run({ pages: [page([value])] })); + } +}); + +test('event SHA and base remain bound even if main advances while CI runs', () => { + assert.throws(() => run({ sha: 'd'.repeat(40) })); + for (const modify of [ + (value) => { + value.action = 'destroyed'; + }, + (value) => { + value.repository.full_name = 'other/project'; + }, + (value) => { + value.merge_group.base_ref = 'refs/heads/other'; + }, + (value) => { + value.merge_group.base_sha = 'short'; + }, + ]) { + const payload = event(); + modify(payload); + assert.throws(() => run({ payload })); + } +});