Skip to content

feat(ci): add workflow to auto-delete merged branches #1

feat(ci): add workflow to auto-delete merged branches

feat(ci): add workflow to auto-delete merged branches #1

Workflow file for this run

name: Branch Cleanup
on:
pull_request:
types: [closed]
branches:
- main
jobs:
delete-branch:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && github.event.pull_request.head.ref != 'develop'
steps:
- name: Delete head branch
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch = context.payload.pull_request.head.ref;
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.name,
ref: `heads/${branch}`
});
console.log(`Deleted branch ${branch}`);
} catch (error) {
console.error(`Error deleting branch ${branch}:`, error);
}