Skip to content

prepare for moving cargo from branch protections to rulesets#2333

Open
marcoieni wants to merge 1 commit intomainfrom
add-cargo-to-rulesets
Open

prepare for moving cargo from branch protections to rulesets#2333
marcoieni wants to merge 1 commit intomainfrom
add-cargo-to-rulesets

Conversation

@marcoieni
Copy link
Member

@marcoieni marcoieni commented Mar 18, 2026

I ran a script to detect existing rulesets in our orgs. rust-lang/cargo is the only repository that has a ruleset not tracked in this repo.

This PR:

  • Adds this ruleset ("Only allow the release process to publish tags") to the team repository. You can verify that the dry run doesn't mention this repo, so we are just writing down without editing the ruleset in github
  • Migrate cargo from classic branch protections to rulesets
  • Improve the logging of rulesets, so that only relevant fields are showed in the dry run (default values are omitted)

In the following, I post the screenshots of the resources this PR touches:

  • as a backup in case something goes wrong

  • to better review the dry run

  • For triagebot retrocompatibility we should first merge the code changes, update triagebot and then edit cargo.toml. After this PR is approved, I will comment the changes to cargo.toml before merging this.

Existing branch protections

Master

github com_rust-lang_cargo_settings_branch_protection_rules_593520

rust-1.*

(download to see the full picture)

github com_rust-lang_cargo_settings_branch_protection_rules_593520 (2)

Existing ruleset

github com_rust-lang_cargo_settings_rules_1162109

@github-actions
Copy link

github-actions bot commented Mar 18, 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

@marcoieni marcoieni force-pushed the add-cargo-to-rulesets branch 2 times, most recently from 2758c92 to 3473afa Compare March 18, 2026 10:43
[[branch-protections]]
pattern = "master"
ci-checks = ["conclusion"]
merge-queue = true
Copy link
Member Author

Choose a reason for hiding this comment

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

merge queues in branch protections were enabled from the UI because the API only support merge queues in rulesets.

pr-required = false
allowed-merge-apps = ["promote-release"]
prevent-update = true

Copy link
Member Author

Choose a reason for hiding this comment

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

this is the ruleset that already existed. I just imported the settings here.

pub allowed_merge_apps: Vec<MergeBot>,
pub merge_queue: bool,
#[serde(default = "default_true")]
#[serde(default = "branch_protection_default_prevent_creation")]
Copy link
Member Author

Choose a reason for hiding this comment

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

the fact that prevent_creation "was true by default" was encoded in too many places in the codebase. So I created functions to be reused across the codebase.
Similar with the other fields.

Copy link
Member

Choose a reason for hiding this comment

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

Wait, this is the v1 API, not GitHub API models, why do we need a default at all? Once triagebot has been updated, the field should always be present, right?

default = "branch_protection_default_prevent_update",
skip_serializing_if = "is_false"
)]
pub prevent_update: bool,
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to add this field because cargo needs it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I edited this file to encode the default of various fields, so that we know when to skip logging a rule

pub struct BranchProtection {
pub pattern: String,
#[serde(default, skip_serializing_if = "is_branch_target")]
pub target: ProtectionTarget,
Copy link
Member Author

Choose a reason for hiding this comment

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

I had to add this field because the existing cargo ruleset targets a tag

@marcoieni marcoieni force-pushed the add-cargo-to-rulesets branch from f1ca0f1 to 7b72488 Compare March 18, 2026 11:39
r#"repo '{}' uses multiple branch protections with the pattern `{}`"#,
r#"repo '{}' uses multiple {:?} protections with the pattern `{}`"#,
repo.name,
protection.target,
Copy link
Member Author

Choose a reason for hiding this comment

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

A repo can have the same pattern for branch and tag

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could create some BranchProtectionId to encode what is the unique identifier of the protection (target + pattern, maybe plus name?). But if it's only used here, it's fine.

@marcoieni marcoieni force-pushed the add-cargo-to-rulesets branch 5 times, most recently from e82a97d to d8e7dba Compare March 18, 2026 12:37
@marcoieni marcoieni marked this pull request as ready for review March 18, 2026 12:56
src/schema.rs Outdated
#[serde(default)]
pub merge_queue: bool,
#[serde(default = "default_true")]
#[serde(default = "rust_team_data::v1::branch_protection_default_prevent_creation")]
Copy link
Member

Choose a reason for hiding this comment

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

The defaults should be chosen here, not in the v1 API.

Copy link
Member Author

Choose a reason for hiding this comment

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

the issue is that the rust_team_data crate doesn't import this crate. So it can't use the default.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, I saw your other comment.

r#"repo '{}' uses multiple branch protections with the pattern `{}`"#,
r#"repo '{}' uses multiple {:?} protections with the pattern `{}`"#,
repo.name,
protection.target,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could create some BranchProtectionId to encode what is the unique identifier of the protection (target + pattern, maybe plus name?). But if it's only used here, it's fine.

@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@marcoieni marcoieni force-pushed the add-cargo-to-rulesets branch 2 times, most recently from 4e2357c to 83c18a9 Compare March 18, 2026 16:41
@marcoieni marcoieni requested a review from Kobzol March 18, 2026 16:56
RustTimer,
Bors,
WorkflowsCratesIo,
PromoteRelease,
Copy link
Member

Choose a reason for hiding this comment

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

We don't have deny unknown fields on the branch protection, so adding the new fields there should be fine for downstream. But this enum variant will brick triagebot, because it won't know it. So we will again have to first land just the infra change, then update triagebot, and then land the cargo repo config change itself.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, this is what I wrote in the PR body, right?

@rustbot

This comment has been minimized.

@rustbot
Copy link

rustbot commented Mar 19, 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 add-cargo-to-rulesets branch from b009059 to a6ed73b Compare March 19, 2026 08:53
@marcoieni marcoieni changed the title add cargo to rulesets prepare for moving cargo from branch protections to rulesets Mar 19, 2026
@marcoieni marcoieni force-pushed the add-cargo-to-rulesets branch from a6ed73b to 4a5dc0b Compare March 19, 2026 08:58
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