File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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 }}
You can’t perform that action at this time.
0 commit comments