Skip to content

fix(ci): use unique branch name for update-managed-tools PR - #64

Merged
SilverKnightKMA merged 1 commit into
mainfrom
fix/unique-branch-managed-tools
Jul 20, 2026
Merged

SilverKnightKMA merged 1 commit into
mainfrom
fix/unique-branch-managed-tools

Conversation

@SilverKnightKMA

Copy link
Copy Markdown
Owner

Xin đính chính PR #63

Sau khi nhận feedback, tôi đã kiểm chứng lại và phát hiện chẩn đoán trong PR #63 là sai. Đây là bản sửa đúng.

Chẩn đoán sai (PR #63)

delete_branch_on_merge setting không hoạt động với auto-merge qua GraphQL.

Chẩn đoán đúng (PR này)

Setting delete_branch_on_merge: true hoạt động hoàn hảo với auto-merge. Bằng chứng từ chính repo:

PR Author Branch có bị auto-delete sau merge?
#58, #59, #60 app/dependabot ✅ Có (DeleteEvent vài giây sau merge)
#62 app/silverknightkma-s-app ❌ Không (phải xóa thủ công)

Cả hai cùng auto-merge, cùng setting. Sự khác biệt: tên branch.

  • Dependabot dùng branch name duy nhất theo version (dependabot/npm_and_yarn/typescript-7.0.2, dependabot/docker/debian-020c0d2).
  • Workflow update-managed-tools.yml dùng branch name cố định automated/update-managed-tools qua mọi lần cron.

Khi PR merge và branch bị auto-delete, lần cron kế tiếp create-pull-request push commit lên cùng tên branch, tạo lại branch đã xóa → trông như branch ". mặc nhiên".

Fix

  1. Đổi branch: automated/update-managed-tools thành automated/update-managed-tools-${{ github.run_id }} → mỗi PR dùng branch một lần, giống Dependabot.
  2. Xóa workflow delete-branch-on-close.yml (thêm ở PR ci: auto-delete head branch after merging automation PRs #63) — không cần nữa vì đã sửa đúng nguyên nhân.

Verification

The root cause of lingering branches was NOT that delete_branch_on_merge
fails with auto-merge (that was my earlier, incorrect diagnosis). The
repo setting works fine for Dependabot PRs, which use unique branch
names per version bump.

The real issue: update-managed-tools.yml reused a fixed branch name
'automated/update-managed-tools' across every weekly cron run. When that
PR was merged and auto-deleted, the next cron push recreated the same
branch, so it always appeared to linger.

Switch to a run-id-suffixed branch name so each PR maps to a one-shot
branch that GitHub's delete_branch_on_merge removes cleanly, matching
the Dependabot pattern.

Also drop the redundant delete-branch-on-close.yml workflow added in
#63 - it is no longer needed now that the actual root cause is fixed.
Copilot AI review requested due to automatic review settings July 20, 2026 11:02

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@SilverKnightKMA
SilverKnightKMA merged commit 165e9f9 into main Jul 20, 2026
6 checks passed
@SilverKnightKMA
SilverKnightKMA deleted the fix/unique-branch-managed-tools branch July 20, 2026 11:02
SilverKnightKMA added a commit that referenced this pull request Jul 20, 2026
)

PR #64 misdiagnosed the lingering branch as a side effect of reusing a
fixed branch name. The real cause is a long-standing GitHub platform
bug (orgs/community#63409): when a PR is merged via a bot/App token
(actor: github-actions[bot]), the repo setting delete_branch_on_merge
is silently ignored. User-merged PRs on the same repo delete fine.

Evidence from this repo's timeline:
- PRs #44, #45, #47, #55, #62 (merged_by=github-actions[bot]): no
  auto-delete; branches lingered until manually removed.
- PRs #58, #59, #60 (merged_by=SilverKnightKMA): auto-deleted within
  1 second of merge.

Renaming the branch per run (PR #64) only stops branch reuse; it does
not delete the merged branch. Without this workflow, merged branches
would accumulate indefinitely one per week.

This workflow explicitly deletes the head branch on PR close (merged),
scoped to same-repo automation branches (automated/*, dependabot/*,
deps/*, chore/*) or trusted bot authors. Fork branches are skipped and
deletion is idempotent.
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.

2 participants