Skip to content

Commit e6c6b9a

Browse files
committed
ADD: add pipeline to delete new branches after merge
1 parent 2590e9e commit e6c6b9a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Automatically delete merged branches on PR merge
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
8+
permissions:
9+
contents: write
10+
pull-requests: write
11+
12+
jobs:
13+
delete-merged-branches:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Delete Branch after merge (Except main)
21+
run: |
22+
BRANCH_NAME=${{ github.event.pull_request.head.ref }}
23+
24+
# Prevent deletion of the main branch
25+
if [ "${{ github.event.pull_request.merged }}" == "true" ] && [ "$BRANCH_NAME" != "main" ]; then
26+
echo "Deleting merged branch: $BRANCH_NAME"
27+
git push origin --delete $BRANCH_NAME
28+
else
29+
echo "Branch not deleted. Either it was not merged or it was 'main'."
30+
env:
31+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)