Skip to content

ci: manage repository rulesets as code and combine the main rulesets - #572

Merged
MushuEE merged 2 commits into
mainfrom
rulesets/1-as-code
Nov 12, 2026
Merged

MushuEE merged 2 commits into
mainfrom
rulesets/1-as-code

Conversation

@MushuEE

@MushuEE MushuEE commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

Moves AX's repository rulesets into the repo, and replaces the two overlapping rulesets on main with a single protect-main. This is the base of the rulesets stack for #546:

  1. This PR: rulesets as code + protect-main (Combine the main rulesets into a single protect-main ruleset #548, part of Manage rulesets as code and protect release tags and branches #547)
  2. Clear approvals on fresh commits (Clear approvals on fresh commits #570)
  3. Protect release tags and release branches (rest of Manage rulesets as code and protect release tags and branches #547)
  4. Merge queue on main (Set up a merge queue on main #571)

Changes

  • .github/rulesets/protect-main.json: exported from the two live rulesets (main and main: require PR review and CI) and merged into one. The only change in policy: allowed_merge_methods drops merge, which the repo settings already disable.
  • hack/apply-rulesets.sh: syncs the files with GitHub. Rulesets are matched by name, and the script never deletes a live ruleset.
    • no flag: create or update (repo admin)
    • --dry-run: print the diff
    • --check: diff, and exit 1 on drift
    • --export: write the live rulesets to the files
  • .github/workflows/rulesets.yml: on PRs that touch the rulesets, prints the --dry-run diff. Daily and on manual dispatch, runs --check, which fails on drift.
  • docs/rulesets.md: what is enforced, how to change a ruleset, and how drift is reported. Linked from CONTRIBUTING.md. AGENTS.md is updated to match.

Testing

Run locally against the live repo (read-only, as a non-admin):

$ RULESETS_DIR=/tmp/rs hack/apply-rulesets.sh --export && RULESETS_DIR=/tmp/rs hack/apply-rulesets.sh --check
=== main: up to date
=== main: require PR review and CI: up to date
$ hack/apply-rulesets.sh --dry-run
=== protect-main: not on GitHub; would create it from .github/rulesets/protect-main.json
=== main: require PR review and CI: on GitHub (id 25031200) but has no file; not deleting it
=== main: on GitHub (id 16615367) but has no file; not deleting it

After merge (repo admin)

  1. Run hack/apply-rulesets.sh --dry-run, then hack/apply-rulesets.sh. This creates protect-main. It is active, but it adds nothing stricter than the existing rulesets.
  2. Confirm that a PR still merges with squash and rebase. Then delete main and main: require PR review and CI in Settings → Rules → Rulesets.
  3. Check that bypass_actors: [] matches what you want. Non-admins can't see the current bypass list, so it couldn't be exported.

Until step 2 is done, the daily drift check fails, because the two old rulesets have no file.

Fixes #548. Part of #547.

Check the rulesets into .github/rulesets/ so changes to them are reviewed
as pull requests, and replace the two overlapping rulesets on main with a
single protect-main ruleset.

- .github/rulesets/protect-main.json: deletion, non-fast-forward, PR with
  1 approval, and the build-and-test check, exported from the live
  rulesets. Merge methods are limited to squash and rebase to match the
  repo settings; nothing else changes.
- hack/apply-rulesets.sh: applies the files (admin), with --dry-run,
  --check for CI, and --export. It matches rulesets by name and never
  deletes live rulesets.
- .github/workflows/rulesets.yml: prints the diff on PRs that touch the
  rulesets, and fails daily when the live rulesets drift from the files.
- docs/rulesets.md: what is enforced and how to change it.

Fixes #548. Part of #547.

@mayawang mayawang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, really glad to have the rulesets reviewable and drift-checked. Happy to run the apply script after merge

@MushuEE
MushuEE merged commit 3941680 into main Nov 12, 2026
11 checks passed
@MushuEE

MushuEE commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator Author

@mayawang these should be ready to apply as you like!

@mayawang

Copy link
Copy Markdown
Collaborator

Ran the dry-run, looks right. One thing for step 3: the live "main: require PR review and CI" lets repo admins bypass via PR (RepositoryRole 5, pull_request mode), which you couldn't see. Could you add that to protect-main.json so we keep it? I'll apply once that's in

Lukeluds pushed a commit to Lukeluds/ax-images that referenced this pull request Nov 18, 2026
Keep the repository rulesets in .github/rulesets/ so a change to branch or
tag protection is proposed and reviewed like any other change.

- Export the two live rulesets, "Protect main" and "protect-tags", as they
  are today. Nothing about what is enforced changes.
- Add scripts/apply-rulesets.sh to apply the files (matched by name), show
  differences (--dry-run), check for drift (--check) and export (--export).
- Add the rulesets workflow: a dry run on pull requests that touch the
  rulesets, and a daily drift check.
- Document the rulesets and how to change them in docs/rulesets.md.

Ported from google/ax (hack/apply-rulesets.sh, google/ax#572).

Part of agentexecutor#14.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Combine the main rulesets into a single protect-main ruleset

2 participants