Skip to content

Add support for YAML references #63

Closed as not planned
Closed as not planned

Description

@ppkarwasz

When configuring exactly the same branch protection rules for multiple branches, it would be useful to use YAML anchor and references, for example:

# Enforce Review-then-Commit
protected_branches:
  2.x: &default_protection
    # All commits must be signed
    required_signatures: true
    # All reviews must be addressed before merging
    required_conversation_resolution: true
    # Require checks to pass before merging
    required_status_checks:
      checks:
        # The GitHub Actions app: 15368
        - app_id: 15368
          context: "build"
        - app_id: 15368
          context: "codeql-analysis"
    # At least one positive review must be present
    required_pull_request_reviews:
      required_approving_review_count: 1
  main: *default_protection

As far as I know strictyaml does not allow this feature for security reasons.
In this case an alternative might be allowing to specify the name of the branch that has an identical configuration:

# Enforce Review-then-Commit
protected_branches:
  2.x:
    # All commits must be signed
    required_signatures: true
    # All reviews must be addressed before merging
    required_conversation_resolution: true
    # Require checks to pass before merging
    required_status_checks:
      checks:
        # The GitHub Actions app: 15368
        - app_id: 15368
          context: "build"
        - app_id: 15368
          context: "codeql-analysis"
    # At least one positive review must be present
    required_pull_request_reviews:
      required_approving_review_count: 1
  main: "2.x"

Activity

  1. netomi commented on May 1, 2025

    @netomi
    Member

    The reason node anchors are not supported in strictyaml sounds more opinionated rather than being a security concern:

    https://hitchdev.com/strictyaml/why/node-anchors-and-references-removed/

    While the intent of the feature is obvious (it lets you deduplicate code), the effect is to make the markup more or less unreadable to non-programmers.

    I think this supporting node anchors would make strictyaml much more complex, but thats just a wild guess.

  2. netomi commented on May 1, 2025

    @netomi
    Member

    We could model it like that:

    # Enforce Review-then-Commit
    protected_branches:
      2.x:
        # All commits must be signed
        required_signatures: true
        # All reviews must be addressed before merging
        required_conversation_resolution: true
        # Require checks to pass before merging
        required_status_checks:
          checks:
            # The GitHub Actions app: 15368
            - app_id: 15368
              context: "build"
            - app_id: 15368
              context: "codeql-analysis"
        # At least one positive review must be present
        required_pull_request_reviews:
          required_approving_review_count: 1
      main:
        from: "2.x"
        with:
          required_pull_request_reviews:
            required_approving_review_count: 0
    

    where from defines the base configuration to use, and with allows to override specific values if needed.

    The schema could be adapted to allow the base branch protection settings via the existing MapPattern or the from use where the with would use the same MapPattern itself.

  3. ppkarwasz commented on May 6, 2025

    @ppkarwasz
    MemberAuthor

    Sounds good to me. You can assign me to the issue and I'll try to make a PR to implement it.

  4. ppkarwasz commented on Nov 12, 2025

    @ppkarwasz
    MemberAuthor

    Since Branch Rulesets #49 will remove the need for YAML references, by allowing the same ruleset to be applied to several branches, I am closing this issue.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions