Skip to content

ci: restore delete-branch-on-close workflow (actual root-cause fix) - #65

Merged
SilverKnightKMA merged 1 commit into
mainfrom
fix/restore-branch-cleanup
Jul 20, 2026
Merged

SilverKnightKMA merged 1 commit into
mainfrom
fix/restore-branch-cleanup

Conversation

@SilverKnightKMA

Copy link
Copy Markdown
Owner

Đính chính PR #64

Sau khi đào sâu thêm với dữ liệu timeline thực tế, tôi nhận ra PR #64 đã chẩn đoán sai nguyên nhân. Đây là bản sửa đúng.

Nguyên nhân thực sự (đã chứng minh bằng dữ liệu)

Đây là bug lâu năm của GitHub: orgs/community#63409 — "PR branches merged by app installation tokens do not get deleted".

Khi PR merge bằng bot/App installation token, GitHub bỏ qua setting delete_branch_on_merge. Khi merge bằng session người dùng thật, setting hoạt động bình thường.

Bằng chứng từ repo này

PR merged_by Branch auto-delete?
#44, #45, #47, #55, #62 github-actions[bot] ❌ Không
#58, #59, #60 SilverKnightKMA ✅ Có (1s sau merge)

Cùng setting, cùng auto-merge, khác actor merge → khác kết quả.

PR #64 sai ở đâu

Đổi branch: automated/update-managed-tools-${{ github.run_id }} chỉ ngăn việc ghi đè branch tên giống nhau giữa các tuần. Nó không sửa việc branch không bị xóa sau merge — bug áp dụng cho mọi branch khi merge bằng bot token. Kết quả: mỗi tuần vẫn sẽ tích lũy thêm 1 branch "mới" không bị xóa.

Fix đúng

Khôi phục workflow delete-branch-on-close.yml (đã thêm ở #63, đã xóa ở #64) — nó explicit xóa head branch khi PR close as merged, bypass bug của GitHub.

Scope an toàn:

  • Chỉ xóa branch cùng repo (fork skip).
  • Chỉ xóa branch có prefix automated/*, dependabot/*, deps/*, chore/* hoặc tác giả là bot đáng tin.
  • Idempotent (nếu branch đã xóa thì no-op).

Kết luận

Hai layer phòng thủ:

  1. PR fix(ci): use unique branch name for update-managed-tools PR #64 (đã merge): branch name duy nhất per run → tránh collision tên.
  2. PR ci: restore delete-branch-on-close workflow (actual root-cause fix) #65 (this): explicit cleanup → giải quyết bug GitHub không xóa branch khi merge bằng bot.

Cảm ơn bạn đã không chấp nhận chẩn đoán vội — nó buộc tôi phải đào đến tận cùng nguyên nhân.

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.
Copilot AI review requested due to automatic review settings July 20, 2026 11:11

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 f58e475 into main Jul 20, 2026
6 checks passed
@SilverKnightKMA
SilverKnightKMA deleted the fix/restore-branch-cleanup branch July 20, 2026 11:11
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