Skip to content

push-to-pull-request-branch blocked on every branch when an org ruleset such as required_signatures applies (regression in v1.2.1) #77191

Closed

Description

@mason-tim

Summary

Since v1.2.1, push_to_pull_request_branch fails on every non-default branch in repositories covered by an organisation ruleset, including a purely required_signatures ("Signed Commits") ruleset. check-branch-protection is now effectively "block if any ruleset applies", so orgs that enforce signed commits can only use push-to-pull-request-branch by disabling the protection check entirely. That also drops the guard for default-branch-style protection (required reviews, status checks, etc.), which we want to keep.

Observed failure (gh-aw v1.2.2)

safe_outputs job log:

Check branch protection: true
Push signed commits: true
##[error]Cannot push to branch "fix/some-feature-branch": this branch has protection rules. Agents must not push directly to protected branches.

The push is never attempted. signed-commits was enabled, so a signed commit would have satisfied the rule.

Root cause

checkBranchPushable in actions/setup/js/pr_helpers.cjs, changed in #74946 (commit 3636e00e6, first released in v1.2.1; absent in v1.2.0):

-      await githubClient.rest.repos.getBranchProtection({ owner, repo, branch: branchName });
-      // Successful response means branch protection rules exist
-      isBranchProtected = true;
+      const { data: branchData } = await githubClient.rest.repos.getBranch({ owner, repo, branch: branchName });
+      isBranchProtected = branchData.protected;
  • Up to v1.2.0 the guard used getBranchProtection, which returns 404 unless classic branch protection exists. Rulesets were ignored.
  • From v1.2.1 it reads branch.protected, which is also true when any ruleset applies to the branch.
  • Fix PR branch rejection for Copilot-review-only rulesets #75230 added hasOnlyCopilotReviewRules so branches whose only rules are copilot_code_review are not treated as protected. No other rule type is exempt.

Reproduction

Repo with an org-level ruleset: required_signatures, target ~ALL, enforcement active, no classic branch protection.

$ gh api repos/OWNER/REPO/branches/some-feature-branch --jq '{protected,protection}'
{"protected":true,"protection":{"enabled":false,"required_status_checks":{"checks":[],"contexts":[],"enforcement_level":"off"}}}

$ gh api repos/OWNER/REPO/rules/branches/some-feature-branch --jq '.[].type'
required_signatures
branch_name_pattern
file_extension_restriction

Any workflow using safe-outputs.push-to-pull-request-branch with default check-branch-protection then fails on any PR branch. We confirmed an unrelated feature branch in the same repo also reports protected: true.

Impact

  • Organisations that enforce signed commits (a common baseline) cannot use push-to-pull-request-branch with the default guard on any PR branch since v1.2.1.
  • The only workaround is check-branch-protection: false, which removes the protection guard wholesale, including for branches with real protection (required reviews or checks, lock branch, etc.). We would rather keep the guard and only exempt rules a signed append-only push satisfies.
  • The failure surfaces only in the post-agent safe_outputs job, after the agent has finished work. Agents report the push as "requested", so it is easy to miss.

Proposed fix

Make the guard distinguish rules that block an agent push from rules that an append-only (optionally signed) push to a PR branch satisfies. In checkBranchPushable, when branchData.protected is true and branchData.protection?.enabled === false, extend hasOnlyCopilotReviewRules (it already reads repos.getBranchRules) to an allowlist of non-blocking rule types:

  • copilot_code_review (existing)
  • required_signatures, but only when the safe output is configured with signed commits, as the push then satisfies the rule
  • naming, content and metadata rules that a normal push satisfies: branch_name_pattern, commit_message_pattern, commit_author_email_pattern, committer_email_pattern, file_path_restriction, file_extension_restriction, max_file_path_length, max_file_size

Keep blocking, as today, on rules that mean the branch is genuinely protected: update, deletion, non_fast_forward, pull_request, required_status_checks, required_deployments, merge_queue, required_linear_history, workflows, etc. Keep the existing classic-protection confirmation (refUpdateRule).

Optionally expose the allowlist in frontmatter for overrides, for example push-to-pull-request-branch.allowed-rule-types: [...], instead of an all-or-nothing check-branch-protection: false.

Implementation plan

  1. actions/setup/js/pr_helpers.cjs: replace hasOnlyCopilotReviewRules with hasOnlyNonBlockingRules(githubClient, owner, repo, branch, { signedCommits }) using the allowlist above. Keep paging and fail-closed behaviour.
  2. Plumb signed-commits into checkBranchPushable's options. Check the call sites in the push_to_pull_request_branch handler.
  3. Tests in the existing pr_helpers test file:
    • only required_signatures + signedCommits: true → pushable
    • only required_signatures + signedCommits: false → blocked
    • required_signatures + pull_request → blocked
    • required_signatures + branch_name_pattern → pushable
    • classic protection enabled → blocked
  4. Update the check-branch-protection docs for push-to-pull-request-branch to state which rule types are treated as non-blocking.

Acceptance criteria

A repo whose only branch rules are org-level required_signatures (plus naming/content rules) can use push-to-pull-request-branch with signed-commits enabled and the default check-branch-protection, while branches with required reviews, status checks or classic protection are still blocked.

Environment

  • gh-aw v1.2.2 (also v1.2.1); v1.2.0 and earlier behave correctly
  • Engine: copilot
  • Repo covered by org rulesets (required_signatures, branch_name_pattern, file_extension_restriction), classic branch protection off

Related

#74946, #75230, #76264 (earlier changes to the same check)

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions