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?

@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 }]
            Restrict updates: true
          Creating 'main - force-push'
            Include Branches: ["refs/heads/main"]
          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 }]
            Restrict updates: true
          Creating 'stable - force-push'
            Include Branches: ["refs/heads/stable"]
            Bypass Actors: [RulesetBypassActor { actor_id: 217112, actor_type: Integration, bypass_mode: Always }]
          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 }]
            Restrict updates: true
          Creating 'beta - force-push'
            Include Branches: ["refs/heads/beta"]
            Bypass Actors: [RulesetBypassActor { actor_id: 217112, actor_type: Integration, bypass_mode: Always }]
          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/*/**/*"]
            Restrict updates: true
          Creating 'cargo_update'
            Include Branches: ["refs/heads/cargo_update"]
          Creating 'automation/bors/try'
            Include Branches: ["refs/heads/automation/bors/try"]
            Bypass Actors: [RulesetBypassActor { actor_id: 278306, actor_type: Integration, bypass_mode: Always }]
            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 }]
            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 }]
            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 }]
            Restrict updates: true
          Creating 'try-perf'
            Include Branches: ["refs/heads/try-perf"]
            Bypass Actors: [RulesetBypassActor { actor_id: 16787004, actor_type: Team, bypass_mode: Always }]
            Restrict updates: true
          Creating 'perf-tmp'
            Include Branches: ["refs/heads/perf-tmp"]
            Bypass Actors: [RulesetBypassActor { actor_id: 16787004, actor_type: Team, bypass_mode: Always }]
            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
@marcoieni marcoieni marked this pull request as ready for review March 24, 2026 17:56
@marcoieni marcoieni requested a review from Kobzol March 24, 2026 17:57
rust-timer = "write"

# Only `bors` can push to `main`
[[branch-protections]]
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 don't understand why we need two separate branch protections to prevent force pushes. Force pushes should be disabled for everyone, even for bors.

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.

Force pushes should be disabled for everyone, even for bors.

That's what the main - force-push rule does. It prevents everyone (including bors) to force push.
Bors is in the main rule, so that rule doesn't apply to bors. To restrict bors, we need another rule where bors isn't in the bypass list.

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.

Ah, I see, I forgot about the other branch protection. That's quite stupid that rulesets work like this, tbh 😆 It would be better if we could bypass only specific properties.. but I understand that would make the options more complicated.

It's quite non-obvious though, and it seems hard to ensure that the other branch protection don't enable something that we don't want, hmm.

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's quite non-obvious though, and it seems hard to ensure that the other branch protection don't enable something that we don't want, hmm.

Yeah, it requires a different mindset than before a bit.

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.

Wait, but if the force push ruleset requires a PR by default, doesn't that mean that it will require a PR also for bors?

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.

yes, you are right, in my test I didn't have "requires a PR" in the settings.
Probably we should add a third rule related to main 😅

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.

Not a third rule, just disable requiring PRs here.

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.

With "here" you mean in the "main - force push"?
I think you are right!
Because "main" already prevent everyone from opening PRs.
I'll do it.

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.

I did the same for stable and beta as well.

pattern = "perf-tmp"
allowed-merge-apps = ["rust-timer"]
allowed-merge-teams = ["rust-timer"]
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.

What does prevent-update actually do? Any why isn't it the default?

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.

From https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets#restrict-updates:

If selected, only users with bypass permissions can push to branches or tags whose name matches the pattern you specify.

At the moment it's not enabled by default. I will raise a PR to make it the default.

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, it seems that the mental model of branch protections and rulesets quite diverges here. I guess that prevent-update = true should be automatically set by pr-required = true?

Copy link
Copy Markdown
Member Author

@marcoieni marcoieni Mar 25, 2026

Choose a reason for hiding this comment

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

Yeah the fact that you both have "restrict updates" and "require a pull request before merging" as possible rules is weird. I think it makes sense for tags, but still..
I will raise 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.

I think we can resolve this after #2346 and #2348

@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 761602e to a6907b3 Compare March 27, 2026 17:37
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch 2 times, most recently from 04c04e1 to 846355b Compare March 29, 2026 10:01
@marcoieni
Copy link
Copy Markdown
Member Author

We added "allow force push" to the cargo_update branch. See #t-infra > cargo_update branch protection broken
image

@marcoieni marcoieni force-pushed the use-rulesets-in-the-rust-repo branch from 846355b to 6e05527 Compare March 29, 2026 17:32
@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 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
Copy link
Copy Markdown

rustbot commented Mar 30, 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.

@rustbot
Copy link
Copy Markdown

rustbot commented Mar 31, 2026

☔ The latest upstream changes (possibly #2355) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants