Skip to content

DOC-343: Add stale-branch cleanup script and workflow - #935

Open
quetzalliwrites wants to merge 1 commit into
mainfrom
doc-343-docs-delete-stale-head-branches-in-github-docs-repo
Open

DOC-343: Add stale-branch cleanup script and workflow#935
quetzalliwrites wants to merge 1 commit into
mainfrom
doc-343-docs-delete-stale-head-branches-in-github-docs-repo

Conversation

@quetzalliwrites

@quetzalliwrites quetzalliwrites commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Delete-on-merge is already enabled for this repo, so the remaining problem is the existing backlog of stale head branches from before that setting existed (plus ongoing cleanup of closed-but-unmerged PRs).

  • scripts/delete-stale-branches.sh: fetches every branch via the GitHub GraphQL API along with its last commit date and most recently updated associated PR, then classifies it:
    • Skipped (never touched): the default branch, and any branch that is the head of an open PR.
    • Eligible for deletion: head of a merged PR (any age), or head of a closed-unmerged PR older than --days (default 90).
    • Reported only, never auto-deleted: no associated PR at all and older than --days — this may be someone's unpushed personal work rather than an abandoned PR branch, so it's flagged for manual review instead.
    • Defaults to a dry run. Actually deleting requires --execute, plus either a typed delete confirmation or --yes for non-interactive/CI use.
  • .github/workflows/cleanup-stale-branches.yml: runs the script as a weekly dry-run report (schedule), and lets a maintainer trigger a real cleanup via workflow_dispatch with the execute input checked.

Verified against the live repo in dry-run mode: 310 branches fetched, 273 eligible (mostly merged PRs from before delete-on-merge was enabled), 8 flagged for manual review, and confirmed none of the branches behind currently open PRs were touched.

Linear ticket

https://linear.app/localstack/issue/DOC-343/docs-delete-stale-head-branches-in-github-docs-repo

Test plan

  • bash -n scripts/delete-stale-branches.sh (syntax check)
  • Ran the script in dry-run mode against localstack/localstack-docs and reviewed the full output
  • Confirmed branches behind open PRs are correctly excluded from both lists
  • npx astro build still completes successfully (these files aren't part of the content collection)

Note

Haven't run --execute yet, want a maintainer to skim the dry-run output (or re-run it) before we actually delete 273 branches.

Delete-on-merge is already enabled, so this targets the backlog of
already-merged branches from before that setting existed, plus
ongoing cleanup for closed-but-unmerged PRs.

scripts/delete-stale-branches.sh classifies every non-default branch:
- Skipped: the default branch and any branch that is the head of an
  open PR.
- Eligible for deletion: head of a merged PR (any age), or head of a
  closed-unmerged PR older than --days (default 90).
- Reported only, never auto-deleted: no associated PR at all and
  older than --days, since this may be unpushed personal work rather
  than an abandoned PR branch.

Defaults to a dry run; --execute (with a typed confirmation, or --yes
for non-interactive/CI use) is required to actually delete anything.

.github/workflows/cleanup-stale-branches.yml runs it as a weekly
dry-run report (workflow_dispatch or schedule), and lets a maintainer
trigger an actual cleanup by checking "execute" on a manual run.

Verified against the live repo in dry-run mode: 310 branches fetched,
273 eligible (mostly merged), 8 flagged for manual review, and none
of the branches behind currently open PRs were touched.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying localstack-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 944ffde
Status: ✅  Deploy successful!
Preview URL: https://6a36ba7e.localstack-docs.pages.dev
Branch Preview URL: https://doc-343-docs-delete-stale-he.localstack-docs.pages.dev

View logs

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.

1 participant