Skip to content

use rulesets in the rust repo#2327

Open
marcoieni wants to merge 1 commit intomainfrom
use-rulesets-in-the-rust-repo
Open

use rulesets in the rust repo#2327
marcoieni wants to merge 1 commit intomainfrom
use-rulesets-in-the-rust-repo

Conversation

@marcoieni
Copy link
Copy Markdown
Member

@marcoieni marcoieni commented Mar 16, 2026

Is there a preferred moment when we want to merge this?

  • record the git SHA of each branch before the switch

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 16, 2026

Dry-run check results

[WARN  rust_team::sync] sync-team is running in dry mode, no changes will be applied.
[INFO  rust_team::sync] synchronizing crates-io
[INFO  rust_team::sync] synchronizing github
[INFO  rust_team::sync] 💻 Repo Diffs:
    📝 Editing repo 'rust-lang/rust':
      Permission Changes:
        Giving team 'rust-timer' write permission
      Rulesets:
          Creating 'main'
            Include Branches: ["refs/heads/main"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'main - force-push'
            Include Branches: ["refs/heads/main"]
            Require pull requests: false
          Creating 'stable'
            Include Branches: ["refs/heads/stable"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }, RulesetBypassActor { actor_id: 217112, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'stable - force-push'
            Include Branches: ["refs/heads/stable"]
            Bypass Actors: [RulesetBypassActor { actor_id: 217112, actor_type: Integration, bypass_mode: Always }]
            Require pull requests: false
          Creating 'stable - misc'
            Include Branches: ["refs/heads/stable"]
            Forbid force pushes: false
            Require pull requests: false
          Creating 'beta'
            Include Branches: ["refs/heads/beta"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }, RulesetBypassActor { actor_id: 217112, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'beta - force-push'
            Include Branches: ["refs/heads/beta"]
            Bypass Actors: [RulesetBypassActor { actor_id: 217112, actor_type: Integration, bypass_mode: Always }]
            Require pull requests: false
          Creating 'beta - misc'
            Include Branches: ["refs/heads/beta"]
            Forbid force pushes: false
            Require pull requests: false
          Creating '*'
            Include Branches: ["refs/heads/*"]
            Bypass Actors: [RulesetBypassActor { actor_id: 217112, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating '*/**/*'
            Include Branches: ["refs/heads/*/**/*"]
            Require pull requests: false
            Restrict updates: true
          Creating 'cargo_update'
            Include Branches: ["refs/heads/cargo_update"]
            Forbid force pushes: false
            Require pull requests: false
            Restrict deletions: false
          Creating 'automation/bors/try'
            Include Branches: ["refs/heads/automation/bors/try"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'automation/bors/try-merge'
            Include Branches: ["refs/heads/automation/bors/try-merge"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'automation/bors/auto'
            Include Branches: ["refs/heads/automation/bors/auto"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'automation/bors/auto-merge'
            Include Branches: ["refs/heads/automation/bors/auto-merge"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'try-perf'
            Include Branches: ["refs/heads/try-perf"]
            Bypass Actors: [RulesetBypassActor { actor_id: 16787004, actor_type: Team, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true
          Creating 'perf-tmp'
            Include Branches: ["refs/heads/perf-tmp"]
            Bypass Actors: [RulesetBypassActor { actor_id: 16787004, actor_type: Team, bypass_mode: Always }]
            Required approvals: 1
            Restrict updates: true

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 2 times, most recently from 11472fe to ccd8f31 Compare March 19, 2026 12:09
@marcoieni
Copy link
Copy Markdown
Member Author

Backup (taken automatically with https://github.com/marcoieni/multicheese in case you are curious!)

001-github-com-rust-lang-rust-settings-branch-protection-rules-2097960 002-github-com-rust-lang-rust-settings-branch-protection-rules-2626273 003-github-com-rust-lang-rust-settings-branch-protection-rules-29679214 004-github-com-rust-lang-rust-settings-branch-protection-rules-31895354 005-github-com-rust-lang-rust-settings-branch-protection-rules-38663771 006-github-com-rust-lang-rust-settings-branch-protection-rules-42228944 007-github-com-rust-lang-rust-settings-branch-protection-rules-42230325 008-github-com-rust-lang-rust-settings-branch-protection-rules-63047047 009-github-com-rust-lang-rust-settings-branch-protection-rules-63047048 010-github-com-rust-lang-rust-settings-branch-protection-rules-69583533 011-github-com-rust-lang-rust-settings-branch-protection-rules-71071517

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 2 times, most recently from a4540e6 to 83f09a2 Compare March 19, 2026 22:31
protection.pattern,
);
}

Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Mar 19, 2026

Choose a reason for hiding this comment

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

From https://docs.github.com/en/enterprise-cloud@latest/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/about-rulesets#about-rulesets-and-protected-branches:

Unlike protection rules, multiple rulesets can apply at the same time, so you can be confident that every rule targeting a branch in your repository will be evaluated when someone interacts with that branch

I removed this because we need multiple rules to interact with the same branch (different bypass list for normal push and force push).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In that case we should make the name required when there are multiple identical patterns, because we used the pattern as an identifier.

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 4 times, most recently from 6f35480 to c3d0cbd Compare March 20, 2026 09:32
@marcoieni
Copy link
Copy Markdown
Member Author

Here's how I tested the "stable" and "stable - force-pushes" rules.

image github com_marco-test-org_ruleset-test_settings_rules_14250638 github com_marco-test-org_ruleset-test_settings_rules_14250638 (1)

The user in the test-team was able to push to the repository but not to force-push. See marco-test-org/ruleset-test#1

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 2 times, most recently from 6e4c63c to c67ec1b Compare March 23, 2026 22:54
@marcoieni
Copy link
Copy Markdown
Member Author

There's one issue:
In the try-perf branch, the user rust-timer is allowed to push.
In rulesets, only teams and github apps can be allowed to push.
Should we create a team for rust-timer?
Another approach would be converting rust-timer to a github app but I'm not sure how difficult it is.

@marcoieni marcoieni mentioned this pull request Mar 24, 2026
1 task
@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 4 times, most recently from 0dee3f1 to f614447 Compare March 24, 2026 06:23
@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented Mar 24, 2026

We are relatively close to making the unrolled PRs by bors, instead of rustc-perf. If this can wait a few weeks, rust-timer will no longer need that access.

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch from f614447 to dbe30bf Compare March 24, 2026 06:25
@marcoieni
Copy link
Copy Markdown
Member Author

We are relatively close to making the unrolled PRs by bors, instead of rustc-perf. If this can wait a few weeks, rust-timer will no longer need that access.

#2343 is a small change that can be reverted easily. Since this is the only blocker to have rulesets in the rust I'm in favor of creating the team. What do you think? 🤔

@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented Mar 24, 2026

Sure, go ahead, it's a small change 👍

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 3 times, most recently from 1b14c6d to c62adff Compare March 24, 2026 17:25
let bypass_actors = self.bypass_actors(expected_repo, branch_protection).await?;

Ok(construct_ruleset(branch_protection, bypass_actors))
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this function is only two lines but I left it like this to minimize the git diff of the PR.
We could inline the construct_ruleset free function later

bypass_mode: RulesetBypassMode::Always,
})
})
.collect();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this piece of code was moved up

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch from c62adff to 8c81777 Compare March 24, 2026 17:48
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch from eafb1f6 to 2146114 Compare March 30, 2026 10:48
ubiratansoares
ubiratansoares previously approved these changes Mar 30, 2026
Copy link
Copy Markdown
Contributor

@ubiratansoares ubiratansoares left a comment

Choose a reason for hiding this comment

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

I've checked all screenshots and compared side-by-side with the new config. Looks Ok to me. Perhaps @Kobzol wants to confirm whether we are good to go from his side as well.

I think it'd be nice spreading the word about this PR on T-infra/annoucements.

name = "main"
pattern = "main"
allowed-merge-apps = ["bors"]
prevent-update = true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I realized that to mirror the previous behavior of branch protections, having a non-empty list of allowed-merge-apps should probably imply prevent-update = true. But that's non-blocking, we can do that later.

pattern = "stable"
allowed-merge-apps = ["promote-release"]
# `stable` already requires users to open PRs.
# This allows bors to push without opening a PR.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
# This allows bors to push without opening a PR.
# This allows promote-release to push without opening a PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

no, I meant bors!
The stable - force-push branch protection is there to restrict the behavior of bors.
promote-release doesn't have any restrictions because it is in all the allowed lists, so it could even delete the branch.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 3 times, most recently from b563c85 to f1b0898 Compare April 7, 2026 16:54
@rustbot

This comment has been minimized.

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 2 times, most recently from 21063a4 to d9ec7fa Compare April 7, 2026 17:14
) -> api::Ruleset {
use api::*;

let branch_protection_mode = get_branch_protection_mode(branch_protection);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As noted by Kobzol:

we shouldn't turn off requiring PRs when bors is enabled, because that will turn off required PRs for everyone

pattern = "try-perf"
allowed-merge-apps = ["rust-timer"]
allowed-merge-teams = ["rust-timer"]
pr-required = false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
pr-required = false

Shouldn't be needed, as rust-timer bypasses this ruleset anyway (same below).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

removed!

prevent-force-push = false

[[branch-protections]]
pattern = "*"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have to check whether this still protects tags (like 1.94.1).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

it doesn't. Let's do a followup PR

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 2 times, most recently from 95f7537 to af4704b Compare April 9, 2026 09:56
@rustbot

This comment has been minimized.

[[branch-protections]]
pattern = "*"
allowed-merge-apps = ["promote-release"]
prevent-update = true
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the classic branch protection allows deletion, while this doesn't.
Jakub here says he prefers to prevent deletion for this and "*/**/*"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, I didn't realize deletion was allowed before. I don't think it's super important, but I guess we can try to be more strict and see if preventing deletion breaks anything.

@rustbot

This comment has been minimized.

@rustbot
Copy link
Copy Markdown

rustbot commented Apr 9, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch from a1caee4 to 37806ed Compare April 9, 2026 13:17
@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch from 37806ed to ab71fb6 Compare April 9, 2026 13:23
@jieyouxu jieyouxu added the needs-infra-admin-review This change requires one of the `infra-admins` to review. label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-infra-admin-review This change requires one of the `infra-admins` to review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants