Skip to content

ci: auto-update queued PR branches when main advances - #1801

Merged
LucasSantana-Dev merged 2 commits into
mainfrom
ci/auto-update-pr-branches
Jul 12, 2026
Merged

LucasSantana-Dev merged 2 commits into
mainfrom
ci/auto-update-pr-branches

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Jul 12, 2026 •

Copy link
Copy Markdown
Owner

Problem

Branch protection requires branches be up to date, but GitHub auto-merge does not auto-update-branch. So every merge re-stales the sibling queued PRs, forcing a manual gh pr update-branch on each — I ran it ~10× in one session working through the backlog (the merge-train thrash).

Fix

A workflow on push: main that update-branches every open PR which already has auto-merge enabled (the opt-in signal) and is BEHIND. As each queued PR lands, the rest are automatically re-based and re-run CI, so the train drains itself.

Notes

  • Scope is narrow on purpose: only auto-merge-enabled, non-draft PRs — other contributors' branches are never touched.
  • Uses RELEASE_PLEASE_TOKEN (PAT), not GITHUB_TOKEN: a branch update made with GITHUB_TOKEN doesn't re-trigger the PR's workflows, which would leave required checks pending forever and auto-merge never firing. The repo already uses this PAT for the same reason in release-please.
  • Conflicting PRs 422 on update-branch → logged as a warning and skipped (they need a manual resolve, as they should).
  • workflow_dispatch included for manual runs.

Alternative considered: the repo-level "Automatically update branches" setting does the same thing with zero YAML — flip that instead and this workflow is redundant. This PR is the in-repo, reviewable version.


Summary by cubic

Automatically updates queued PR branches when main advances to keep auto-merge trains moving without manual updates. Only touches non-draft PRs with auto-merge enabled.

  • New Features
    • Workflow updates branches for open PRs behind main with auto-merge enabled.
    • Uses RELEASE_PLEASE_TOKEN instead of GITHUB_TOKEN so required checks re-run and auto-merge can finish.
    • Skips drafts and conflicting PRs (logs a warning), serializes runs, and supports workflow_dispatch.

Written for commit 010b3f0. Summary will update on new commits.

Review in cubic

@coderabbitai

coderabbitai Bot commented Jul 12, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 19 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f0e96178-3578-4555-916c-7039b03983bf

📥 Commits

Reviewing files that changed from the base of the PR and between 68fd0be and 010b3f0.

📒 Files selected for processing (1)
  • .github/workflows/auto-update-pr-branches.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ci/auto-update-pr-branches

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@LucasSantana-Dev
LucasSantana-Dev enabled auto-merge (squash) July 12, 2026 01:54

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

Auto-approved: Adds a CI workflow to auto-update branches of queued PRs when main advances. Low-risk configuration addition using existing PAT.

Re-trigger cubic

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit 36d14fc into main Jul 12, 2026
39 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the ci/auto-update-pr-branches branch July 12, 2026 15:44
LucasSantana-Dev added a commit that referenced this pull request Jul 12, 2026
## Bug (observed live)
After #1801 merged, its `auto-update-pr-branches` workflow ran green but
updated **0** PRs — all 7 queued auto-merge PRs stayed BEHIND and the
queue **deadlocked** (no further main-advance to re-fire the workflow;
had to manually `update-branch` all 7).

## Root cause
`on: push: [main]` fires the instant main advances, but GitHub hasn't
recomputed the *other* PRs' `mergeStateStatus` to `BEHIND` yet — it
reads `UNKNOWN` — so the `== "BEHIND"` filter matches none.

## Fix
- **45s settle** on push events before listing (lets mergeStateStatus
recompute).
- **`*/15` cron backstop** — catches any stranded PR within ~15 min
regardless of the race. Cheap (a `gh pr list` job, seconds).

Makes the merge-train self-heal instead of stranding on the first-merge
race — the automation `ship-all-prs` depends on.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Fixes a race in the auto-update workflow after merges to main that
sometimes updated zero PRs and stalled the queue. We now wait briefly on
push runs and add a 15‑minute cron backstop to keep the merge train
moving.

- **Bug Fixes**
- On push events, wait 45s before listing PRs so GitHub sets
mergeStateStatus to BEHIND.
- Add a */15 cron schedule to catch and update any stranded PRs within
~15 minutes.

<sup>Written for commit 73e3ae6.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/LucasSantana-Dev/Lucky/pull/1811?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant