Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/auto-delete-pr-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# .github/workflows/auto-delete-pr-branches.yml
name: auto-delete-pr-branches
on:
pull_request:
types: [closed]
permissions:
contents: write
jobs:
delete:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Delete head branch when PR is merged (skip main branches)
uses: actions/github-script@v7
with:
script: |
const allowlist = new Set(['main','staging','dev']);
const headRef = context.payload.pull_request.head.ref;
const headRepo = context.payload.pull_request.head.repo.full_name;
const baseRepo = context.payload.pull_request.base.repo.full_name;
if (headRepo !== baseRepo) {
core.info(`PR from fork (${headRepo}) — nothing to delete here.`);
return;
}
if (allowlist.has(headRef)) {
core.info(`'${headRef}' is in allowlist; not deleting.`);
return;
}
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${headRef}`
});
core.notice(`Deleted branch '${headRef}'.`);
} catch (e) {
core.warning(`Could not delete heads/${headRef}: ${e.message}`);
}
46 changes: 46 additions & 0 deletions .github/workflows/nightly-prune-merged-branches.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# .github/workflows/nightly-prune-merged-branches.yml
name: nightly-prune-merged-branches
on:
schedule:
- cron: "17 3 * * *" # daily 03:17 UTC
workflow_dispatch:
permissions:
contents: write
jobs:
prune:
runs-on: ubuntu-latest
steps:
- name: Prune merged non-main branches
uses: actions/github-script@v7
with:
script: |
const allowlist = new Set(['main','staging','dev']);
const owner = context.repo.owner;
const repo = context.repo.repo;

// Get last 200 merged PRs
const prs = await github.paginate(github.rest.pulls.list, {
owner, repo, state: 'closed', per_page: 100
});
const merged = prs.filter(pr => pr.merged_at);

for (const pr of merged) {
const headRef = pr.head.ref;
const headRepo = pr.head.repo && pr.head.repo.full_name;
if (!headRepo || headRepo !== `${owner}/${repo}`) continue;
if (allowlist.has(headRef)) continue;

// Check branch existence
try {
await github.rest.repos.getBranch({ owner, repo, branch: headRef });
} catch {
continue; // already gone
}

try {
await github.rest.git.deleteRef({ owner, repo, ref: `heads/${headRef}` });
core.notice(`Deleted '${headRef}' from merged PR #${pr.number}`);
} catch (e) {
core.warning(`Could not delete '${headRef}' (PR #${pr.number}): ${e.message}`);
}
}
26 changes: 0 additions & 26 deletions .github/workflows/release.yml

This file was deleted.

Loading