Skip to content

Manage rulesets as code and protect release tags and branches #547

Open

Description

@MushuEE

Summary

Check AX's repository rulesets into the repo, and use that to add the protection that main already has to release tags and release branches, and to enforce branch and tag naming. Ruleset changes are then proposed, reviewed and audited as PRs instead of being edited only in the GitHub UI.

This issue combines four items from the epic (#546): rulesets as code, protecting release tags, protecting release branches, and branching and tagging rules. They are one unit of work: each protection lands as a JSON file in .github/rulesets/ and is applied with the same script.

Current state (checked 2026-11-12)

  • Two rulesets exist, both on ~DEFAULT_BRANCH: main and main: require PR review and CI (merged into one by Combine the main rulesets into a single protect-main ruleset #548).
  • No ruleset targets tags or release-* branches. Anyone with write access can create, move or delete a v* tag.
  • Tags v0.1.0 … v0.3.1 were created by hand. All of them follow vX.Y.Z; there are no stray tags.
  • There are 62 branches on upstream. Most (32) were last updated in July 2026. Common prefixes: readme-*, fix-*, antigravity-*, agy-*. Because PRs are squash-merged, git branch --merged finds only 1 of them, so cleanup has to check PR state instead.
  • delete_branch_on_merge is false.
  • There is no .github/rulesets/ directory and no release-* branch yet.

Proposal

1. Rulesets as code

  1. Export each active ruleset to .github/rulesets/<name>.json with gh api repos/google/ax/rulesets/<id>. Remove server-managed fields such as id, node_id, _links, created_at, updated_at and source*, so the files contain only the policy: name, target, enforcement, conditions, rules, bypass_actors.
  2. Apply with hack/apply-rulesets.sh, which a repo admin runs:
    • Match local files to live rulesets by name.
    • PUT /repos/google/ax/rulesets/<id> for existing rulesets, and POST /repos/google/ax/rulesets for new ones.
    • Support --dry-run, which shows the differences without changing anything.
    • Never delete live rulesets that have no file. List them instead.
  3. Detect drift with a scheduled workflow, or a step in an existing one, that compares .github/rulesets/*.json with the live rulesets and fails or opens an issue when they differ.
    • Reading bypass_actors needs admin. Decide whether this check uses a GitHub App or token with admin read, or compares everything except bypass_actors.
  4. Document the flow in CONTRIBUTING.md or docs/dev/rulesets.md: open a PR that edits the JSON, get it reviewed, and after merge an admin runs hack/apply-rulesets.sh.

2. Protect release tags (protect-tags.json)

  • Target tags matching refs/tags/v*.
  • Rules: block creation, update, deletion and non-fast-forward, and require names to match ^v\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$.
  • Bypass list: release managers only, or the release workflow's identity once the tag-driven release workflow (Epic 5) lands.
  • This must be in place before releases publish images from tags, following Substrate's docs/dev/releasing.md.

3. Protect release branches (protect-release-branches.json)

  • Target refs/heads/release-*.
  • Rules: block deletion and force-push, require a PR, and require the same status checks as main.
  • Open: how many approvals release-branch PRs need. Substrate uses 0 because its cherry-picks are bot-driven.
  • Open: whether release branches also use the merge queue. Substrate's don't.

4. Branching and tagging rules

  • Branches: only main and release-X.Y are long-lived on upstream. The format for any other upstream branch depends on the fork RFC in Epic: Establish rulesets for branching, tagging, and merging #546 (require forks, allow only prefixes such as user/<ldap>/… or bot/…, or keep the current setup). If that RFC adds a branch-name ruleset, it lands here too.
  • Tags: semantic-version vX.Y.Z[-pre] only, with no ad-hoc tags on upstream. Enforced by protect-tags.
  • Cleanup: turn on delete_branch_on_merge. For the 62 existing branches, delete those whose PR is merged or closed, and contact the owners of the rest.
  • Write the rules down in CONTRIBUTING.md (with the Epic 3 docs update).

Acceptance criteria

  • Every active ruleset on google/ax has a matching file in .github/rulesets/
  • hack/apply-rulesets.sh --dry-run reports no differences against the live configuration right after export
  • hack/apply-rulesets.sh creates or updates rulesets from the files, matched by name
  • Drift between the files and the live rulesets is reported automatically
  • A user who isn't a release manager can't create, move or delete a v* tag, and tags that don't match the semver pattern are rejected
  • A release-X.Y branch can only change through PRs that pass CI, and can't be deleted or force-pushed
  • delete_branch_on_merge is on, and stale upstream branches are cleaned up
  • The ruleset change process and the branch and tag naming rules are documented

Rollout

New rulesets start in evaluate mode. Once the rule insights show they wouldn't block legitimate work, they switch to active. Suggested order: rulesets as code first, then protect-tags, then protect-release-branches, then branch cleanup.

Open questions

  • Who are the admins who can run the apply script, and who are the release managers on the tag bypass list?
  • Should applying stay a manual admin step, or eventually run automatically after merge using a GitHub App with admin rights on rulesets?
  • How many approvals do release-branch PRs need, and do release branches use the merge queue?

Notes

Activity

  1. added
    devx
    on Nov 1, 2026
  2. added and removed
    devx
    on Nov 2, 2026
  3. changed the title [-]Manage repository rulesets as code[/-] [+]Manage rulesets as code and protect release tags and branches[/+] on Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions