-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add branch creation rules and update pipeline triggers #16384
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Vladimir Morozov (vmoroz)
merged 1 commit into
microsoft:main
from
vmoroz:PR/update-branch-rules
Aug 21, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| # Repository rules (rulesets) | ||
|
|
||
| Infrastructure-as-code for the GitHub **repository rulesets** applied to | ||
| `microsoft/react-native-windows`. Each `*.json` file in this folder is the exact | ||
| request body for GitHub's create/update ruleset REST API, so the live policy | ||
| always has a reviewable history in git. Edit the JSON, get it reviewed, then | ||
| apply it with the commands below. | ||
|
|
||
| ## Files | ||
|
|
||
| | File | Ruleset name | Purpose | | ||
| |------|--------------|---------| | ||
| | [`branch-namespace-ruleset.json`](./branch-namespace-ruleset.json) | Require namespaced branches | Stops new **top-level** branches. New branches must live under an approved namespace (personal work goes under `user/<alias>/…`). | | ||
|
|
||
| ## What `branch-namespace-ruleset.json` does | ||
|
|
||
| - Targets **all branches** (`~ALL`) *except* the approved patterns under | ||
| `conditions.ref_name.exclude`. | ||
| - Applies the **`creation`** rule ("Restrict creations"): a branch whose name is | ||
| not in the allow list cannot be created by anyone without bypass permission. | ||
| - **Creation only.** Existing branches and pushes to them are untouched — this | ||
| refuses only *new* non-conforming branch names. The ~90 legacy top-level | ||
| branches keep working; nobody can add more like them. | ||
| - `bypass_actors` is empty on purpose: **no one is exempt**, not even repo | ||
| admins. (An admin can still edit or delete the ruleset itself.) | ||
|
|
||
| ### Approved branch namespaces | ||
|
|
||
| | Branch pattern | Who / what uses it | | ||
| |----------------|--------------------| | ||
| | `user/<alias>/…` | Humans — the required home for personal and PR branches | | ||
| | `users/merlinbot/…` | 1ES PT auto-baselining bot | | ||
| | `dependabot/…` | Dependabot | | ||
| | `copilot/…` | Copilot coding agent | | ||
| | `chore/weekly-lock-refresh-*` | `compliance-yarn-lock.yml` weekly bot | | ||
| | `*-stable` | Release branches (e.g. `0.85-stable`) | | ||
| | `preview-*-test` | Preview test branches (e.g. `preview-0.84-test`) | | ||
| | `prepare-release/…` | Release preparation | | ||
| | `release/…`, `hotfix/…`, `archive/…` | Reserved by the [branch lifecycle policy](../../docs/branch-lifecycle-policy.md) (`archive/` is the documented way to preserve a branch) | | ||
| | `integrate/…` | React Native nightly integration (`integrate/nightly-*`) | | ||
| | `cherry-pick/…` | Cherry-pick branches | | ||
| | `revert-*` | GitHub "Revert" button on merged PRs | | ||
| | `gh-readonly-queue/…` | Merge queue (only if enabled) | | ||
| | `gh-pages` | Docs site publishing | | ||
|
|
||
| ### Pattern syntax & gotchas | ||
|
|
||
| GitHub matches ref patterns with Ruby's `File.fnmatch` under the | ||
| `File::FNM_PATHNAME` flag. It has sharp edges — each point below was verified | ||
| against that engine: | ||
|
|
||
| - **A single `*` never crosses `/`.** `foo/*` matches exactly one level | ||
| (`foo/bar`), never `foo/a/b`. Inside a single segment `*` is greedy, so | ||
| `*-stable` matches both `0.85-stable` and `0.58-vnext-stable`, and | ||
| `preview-*-test` requires the literal `-test` suffix (plain `preview-0.84` is | ||
| blocked). | ||
| - **A bare trailing `**` does *not* cross `/` either.** `foo/**` behaves like | ||
| `foo/*` and silently misses nested branches — never use it to mean "everything | ||
| under `foo/`". | ||
| - **Use `foo/**/*` for a whole namespace.** The `**/` piece matches *zero or | ||
| more* directories, so a single `foo/**/*` matches both single-level (`foo/bar`) | ||
| and deep (`foo/a/b/c`). That is why each folder namespace needs only this one | ||
| entry. | ||
| - **`~ALL` — not `refs/heads/**` — means "all branches".** The `include` uses the | ||
| special `~ALL` token; a trailing `**` cannot express it (see above). | ||
| - **Every `exclude` entry keeps the `refs/heads/` prefix**; patterns match the | ||
| full ref path, not the short branch name. | ||
| - **Reverts can contain slashes.** GitHub's "Revert" button creates | ||
| `revert-<PR#>-<original-branch>` and preserves slashes when the original was | ||
| namespaced (e.g. `revert-15633-user/WatsonFix/0.81`). That is why revert takes | ||
| two entries: `revert-*` (flat) and `revert-*/**/*` (nested). | ||
| - **Matching is case-sensitive.** `fix-*` does not match `Fix-lint`. | ||
| - **Unsupported syntax:** no negated character classes (`[^…]`), no brace/extglob | ||
| expansion (`{a,b}`, `File::FNM_EXTGLOB`), and backslash is not an escape | ||
| character. | ||
| - **Creation-only.** The rule blocks new non-conforming branch *names*; it never | ||
| touches existing branches or pushes to them. | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| 1. **Admin on the repo.** Rulesets are an admin-only setting. Elevate through | ||
| just-in-time (JIT) admin access to get the **Admin** role on | ||
| `microsoft/react-native-windows`, and drop it when you're done. | ||
| 2. **GitHub CLI**, authenticated as the elevated account: | ||
| ```powershell | ||
| gh --version | ||
| gh auth login # or set $env:GH_TOKEN | ||
| ``` | ||
|
|
||
| ## Apply (first time) | ||
|
|
||
| ```powershell | ||
| cd .ado/repo-rules | ||
| gh api --method POST repos/microsoft/react-native-windows/rulesets --input branch-namespace-ruleset.json | ||
| ``` | ||
|
|
||
| ## Update an existing ruleset | ||
|
|
||
| Look up the ruleset id, then `PUT` the edited file: | ||
|
|
||
| ```powershell | ||
| gh api repos/microsoft/react-native-windows/rulesets --jq '.[] | "\(.id): \(.name)"' | ||
| gh api --method PUT repos/microsoft/react-native-windows/rulesets/RULESET_ID --input branch-namespace-ruleset.json | ||
| ``` | ||
|
|
||
| ## Change the allowed patterns | ||
|
|
||
| Edit `conditions.ref_name.exclude` in the JSON, commit for review, then run the | ||
| **update** command above. Add a single `refs/heads/foo/**/*` entry per folder | ||
| namespace — it matches that namespace at any depth. Mind the | ||
| [pattern gotchas](#pattern-syntax--gotchas): keep the `refs/heads/` prefix and | ||
| never use a bare `foo/**` (it will not cross `/`). | ||
|
|
||
| ## Verify | ||
|
|
||
| ```powershell | ||
| # A non-namespaced name should be rejected: | ||
| git push upstream HEAD:policy-smoke-test | ||
|
|
||
| # A namespaced name should succeed, then clean it up: | ||
| git push upstream HEAD:user/<your-alias>/policy-smoke-test | ||
| git push upstream --delete user/<your-alias>/policy-smoke-test | ||
| ``` | ||
|
|
||
| Or inspect which rules would apply to a candidate branch name (it need not exist): | ||
|
|
||
| ```powershell | ||
| gh api repos/microsoft/react-native-windows/rules/branches/policy-smoke-test | ||
| ``` | ||
|
|
||
| ## Roll back | ||
|
|
||
| ```powershell | ||
| # Soft-disable: set "enforcement": "disabled" in the JSON and PUT it, or delete it: | ||
| gh api --method DELETE repos/microsoft/react-native-windows/rulesets/RULESET_ID | ||
| ``` | ||
|
|
||
| ## Notes | ||
|
|
||
| - To trial the policy without blocking anyone, set `"enforcement": "evaluate"` | ||
| first (violations are logged, not enforced), then switch to `"active"`. | ||
| - The allow list was derived from the repo's live branches plus the tooling that | ||
| creates them: Dependabot, Copilot, [`compliance-yarn-lock.yml`](../../.github/workflows/compliance-yarn-lock.yml), | ||
| [`integrate-rn`](../../packages/@rnw-scripts/integrate-rn), the release process, | ||
| and the protected prefixes in the [branch lifecycle policy](../../docs/branch-lifecycle-policy.md). | ||
| - If you later want an emergency bypass, add an entry to `bypass_actors` (for | ||
| example an `OrganizationAdmin` or a specific `Team`) rather than loosening the | ||
| patterns. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| { | ||
| "name": "Require namespaced branches", | ||
| "target": "branch", | ||
| "enforcement": "active", | ||
| "bypass_actors": [], | ||
| "conditions": { | ||
| "ref_name": { | ||
| "include": ["~ALL"], | ||
| "exclude": [ | ||
| "refs/heads/user/**/*", | ||
|
|
||
| "refs/heads/users/merlinbot/**/*", | ||
| "refs/heads/dependabot/**/*", | ||
| "refs/heads/copilot/**/*", | ||
| "refs/heads/chore/weekly-lock-refresh-*", | ||
|
|
||
| "refs/heads/*-stable", | ||
| "refs/heads/preview-*-test", | ||
| "refs/heads/prepare-release/**/*", | ||
| "refs/heads/release/**/*", | ||
| "refs/heads/hotfix/**/*", | ||
|
|
||
| "refs/heads/integrate/**/*", | ||
| "refs/heads/cherry-pick/**/*", | ||
| "refs/heads/archive/**/*", | ||
|
|
||
| "refs/heads/revert-*", | ||
| "refs/heads/revert-*/**/*", | ||
| "refs/heads/gh-readonly-queue/**/*", | ||
|
|
||
| "refs/heads/gh-pages" | ||
| ] | ||
| } | ||
| }, | ||
| "rules": [ | ||
| { "type": "creation" } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.