Skip to content

Commit f0c9dfc

Browse files
committed
✨Feat: 브랜치 자동 삭제 Github Action
1 parent 6f802ee commit f0c9dfc

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

.github/workflows/delete_branch.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Delete Merged Branches
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * *' # 매일 자정에 실행
6+
workflow_dispatch: # 수동 실행 가능
7+
8+
jobs:
9+
delete-merged-branches:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Delete old merged branches
18+
run: |
19+
# 시작 로그
20+
echo "Starting branch cleanup process..."
21+
22+
git config --global user.name 'github-actions'
23+
git config --global user.email '[email protected]'
24+
25+
# develop 브랜치로 전환
26+
echo "Switching to develop branch..."
27+
git checkout develop
28+
29+
# 현재 시간 기록
30+
echo "Current time: $(date)"
31+
32+
# 병합된 브랜치 검사 및 삭제
33+
echo "Checking for merged branches older than 7 days..."
34+
git branch -r --merged develop | \
35+
grep -v 'main\|develop' | \
36+
grep "origin/" | \
37+
cut -d "/" -f 2- | \
38+
while read branch; do
39+
echo "Checking branch: $branch"
40+
last_commit_date=$(git log -1 --format=%cd origin/$branch)
41+
echo "Last commit date: $last_commit_date"
42+
43+
if [[ $(git log -1 --since='7 days ago' origin/$branch) == "" ]]; then
44+
echo "Branch '$branch' is older than 7 days and will be deleted"
45+
git push origin --delete $branch
46+
echo "Successfully deleted branch: $branch"
47+
else
48+
echo "Branch '$branch' is still active (less than 7 days old)"
49+
fi
50+
done
51+
52+
# 완료 로그
53+
echo "Branch cleanup process completed"
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)